akhauriyash/Code-Regression huggingface dataset:
#define FASTIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//#define BZ
//#define PBDS
//#define POINT

#ifndef BZ
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("no-stack-protector")
//#pragma GCC target ("tune=native")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize ("conserve-stack")
//#pragma GCC optimize ("no-stack-limit")
#endif

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
//using xll = __int128_t;
using str = string;
using pll = pair<ll, ll>;

#ifdef POINT
using point = complex<ll>;
#define x real
#define y imag
#endif

#ifdef PBDS
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//using namespace __gnu_pbds::detail;
template <class T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif

#define INF 0x7fffffffffffffffLL
#define BASE 1000000007LL // 3 * 10**9 + 19 // 998244353 - rev == pow(n + m, BASE - 2)
#define MAX(type) std::numeric_limits<type>::max()
#define MIN(type) std::numeric_limits<type>::min()

#define LOG(v) cout << #v << " " << v << "\n";

#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define forEach(c) for (auto &it : c)
#define loop while (true)
#define mp make_pair
#define mt make_tuple

template <class T>
void chMax(T &a, T b) {
	if (a < b) a = b;
}

template <class T>
void chMin(T &a, T b) {
	if (b < a) a = b;
}

inline ll divUp(ll a, ll b) {
	return (a + b - 1)/b;
}

bool bit(ll m, ll v) {
	return (m >> v) & 1;
}

ull mmul(ll a, ll b) {
	assert(__builtin_popcountll(a) == 1);
	ll ans = 0;
	while (a) {
		if (a == 1) ans += b;
		b = b * 2;
		if (b >= BASE) b %= BASE;
		a /= 2;
	}
	return ans;
}

void solve() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	forEach(a) cin >> it;
	ll maxI = 0;
	{
		ll m = *max_element(a.begin(), a.end());
		while ((1LL << maxI) <= m) maxI++;
	}
	ull s = 0;
	ull cnt[2][maxI];
	memset(cnt, 0, sizeof(cnt));
	forEach(a) {
		for (ll i = 0; i < maxI; i++) {
			//if (it < (1LL << i)) break;
			if (bit(it, i)) {
				s = (s + (mmul(1LL << i, cnt[0][i]))) % BASE;
				cnt[1][i]++;
				//if (cnt[1][i] >= BASE) cnt[1][i] -= BASE;
			} else {
				s = (s + (mmul(1LL << i, cnt[1][i]))) % BASE;
				cnt[0][i]++;
				//if (cnt[0][i] >= BASE) cnt[0][i] -= BASE;
			}
		}
	}
	cout << s << "\n";
}

//#define LOCAL

int main() {
	FASTIO
#ifdef LOCAL
	freopen("D.in", "r", stdin);
	auto start = std::chrono::system_clock::now();
#endif
	solve();
#ifdef LOCAL
	auto end = std::chrono::system_clock::now();
	std::chrono::duration<ld> elapsed_seconds = end - start;
	cout << "\ntime: " << elapsed_seconds.count() << " s\n";
#endif
	return 0;
}


Measured memory_bytes: 2560
from math import gcd
k = int(input())
gcdl = [[0 for i in range(k + 1)] for i in range(k + 1)]
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcdl[i][j] = gcd(i, j)
s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            s += gcdl[i][gcdl[j][l]]

print(s)


Measured memory_bytes: 9416
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

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

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


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

    ll ans = 0;
    rep(i, n) {
        ll lft = min(a[i], b[i]);
        ans += lft;
        a[i] -= lft;
        b[i] -= lft;

        ll rht = min(a[i + 1], b[i]);
        ans += rht;
        a[i + 1] -= rht;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int a = 0;
        int mina = 1000;
        int maxa = 0;

        for (int i = 0; i < n; i++) {
            a = scanner.nextInt();
            if (mina > a){
                mina = a;
            }
            if (maxa < a){
                maxa = a;
            }
        }
        System.out.println(maxa-mina);
    }
}


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

using namespace std;

int main()
{
	string S;
	int answer;
	cin >> S;
	if (S == "SUN")
	{
		answer = 7;
	}
	else if (S == "MON")
	{
		answer = 6;
	}
	else if (S == "TUE")
	{
		answer = 5;
	}
	else if (S == "WED")
	{
		answer = 4;
	}
	else if (S == "THU")
	{
		answer = 3;
	}
	else if (S == "FRI")
	{
		answer = 2;
	}
	else if (S == "SAT")
	{
		answer = 1;
	}
	cout << answer << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

int main(void){
	int N, M, dif;
	int x, y, nx, ny;
	char c;

	while(1){
		int d[21][21] = {0};
		cin >> N;
		if(!N) break;
		for(int i=0; i<N; ++i){
			cin >> x >> y;
			d[x][y] = 1;
		}

		cin >> M;
		nx = ny = 10;
		d[nx][ny] = 0;
		for(int i=0; i<M; ++i){
			cin >> c >> dif;
			for(int j=0; j<dif; ++j){
				if(c == 'N'){
					ny++;
				}
				if(c == 'S'){
					ny--;
				}
				if(c == 'E'){
					nx++;
				}
				if(c == 'W'){
					nx--;
				}
				d[nx][ny] = 0;
			}
		}
	
		int check = 0;

		for(int i=0; i<21; ++i){
			for(int j=0; j<21; ++j){
				if(d[i][j] == 1) check = 1;
			}
		}

		if(check) cout << "No" << endl;
		else cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=100050;
int mod;
int add(int x, int y){ x+=y;return x>=mod?x-mod:x;}
int sub(int x, int y){ x-=y;return x<0?x+mod:x;}
int mul(int x, int y){ return (ll)x*y%mod;}
int dp[N],ans[N],up[N];
vector<int> E[N];
void DFS(int u, int p)
{
	dp[u]=1;
	for(int v:E[u]) if(v!=p) DFS(v,u),dp[u]=mul(dp[u],add(dp[v],1));
}
void Solve(int u, int p)
{
	if(!p) up[u]=1;
	ans[u]=mul(up[u],dp[u]);
	vector<int> l,r;
	l.pb(1);r.pb(1);
	for(int v:E[u]) if(v!=p)
	{
		l.pb(add(dp[v],1));
		r.pb(l.back());
	}
	l.pb(1);r.pb(1);
	for(int i=1;i<l.size();i++) l[i]=mul(l[i],l[i-1]);
	for(int i=(int)r.size()-2;i>=0;i--) r[i]=mul(r[i],r[i+1]);
	int c=0;
	for(int v:E[u]) if(v!=p)
	{
		c++;
		up[v]=add(mul(up[u],mul(l[c-1],r[c+1])),1);
		Solve(v,u);
	}
}
int main()
{
	int n,u,v;
	scanf("%i %i",&n,&mod);
	for(int i=1;i<n;i++) scanf("%i %i",&u,&v),E[u].pb(v),E[v].pb(u);
	DFS(1,0);
	Solve(1,0);
	for(int i=1;i<=n;i++) printf("%i\n",ans[i]);
	return 0;
}

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

int data[30][6];

bool judge(int);

main(){
  string in;
  int n;
  while(1){
    cin >> n;
    if(n==0) break;
    int count=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<6;j++){
	cin >> in;
	if(in=="Red") data[i][j]=1;
	if(in=="Yellow") data[i][j]=2;
	if(in=="Blue") data[i][j]=3;
	if(in=="Magenta") data[i][j]=4;
	if(in=="Green") data[i][j]=5;
	if(in=="Cyan") data[i][j]=6;
      }
      if(judge(i)) count++;
    }
    int ans=n-count;
    if(ans<0) ans=0;
    cout << ans << endl;
  }
  return 0;
}

bool judge(int n){
  if(n==0) return true;
  int tmp[6];
  for(int i=0;i<6;i++){
    tmp[i]=data[n][i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
	for(int a=0;a<4;a++){
	  if(tmp[0]==data[i][0] && tmp[1]==data[i][1] && tmp[2]==data[i][2] && tmp[3]==data[i][3] && tmp[4]==data[i][4] && tmp[5]==data[i][5]) return false;
	  int ttt[6];
	  for(int b=0;b<6;b++){
	    ttt[b]=tmp[b];
	  }
	  ttt[0]=tmp[0];
	  ttt[1]=tmp[2];
	  ttt[2]=tmp[4];
	  ttt[3]=tmp[1];
	  ttt[4]=tmp[3];
	  ttt[5]=tmp[5];
	  for(int b=0;b<6;b++){
	    tmp[b]=ttt[b];
	  }
	}
	int tt[6];
	for(int l=0;l<6;l++){
	  tt[l]=tmp[l];
	}
	tt[0]=tmp[1];
	tt[1]=tmp[5];
	tt[2]=tmp[2];
	tt[3]=tmp[3];
	tt[4]=tmp[0];
	tt[5]=tmp[4];
	for(int l=0;l<6;l++){
	  tmp[l]=tt[l];
	}
      }
      int t[6];
      for(int k=0;k<6;k++){
	t[k]=tmp[k];
      }
      t[0]=tmp[3];
      t[1]=tmp[1];
      t[2]=tmp[0];
      t[3]=tmp[5];
      t[4]=tmp[4];
      t[5]=tmp[2];
      for(int k=0;k<6;k++){
	tmp[k]=t[k];
      }
    }
  }
  return true;
}

Measured memory_bytes: 0
X, N = map(int, input().split())

if N == 0:
  print(X)
else:
  ps = set(list(map(int, input().split())))

  i = 0
  while True:
    if X-i not in ps:
      print(X-i)
      break
    elif X+i not in ps:
      print(X+i)
      break
    i += 1

Measured memory_bytes: 9184
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Scan()
	S := sc.Text()

	if S == "ABC" {
		fmt.Println("ARC")
	} else {
		fmt.Println("ABC")
	}

}


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

#define int long long

typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int N;
string S;
int cnt[26];
signed main(){
    cin>>N>>S;
    rep(i,N)if(isalpha(S[i]))cnt[S[i]-'a']++;

    bool f=false;
    int ans=0;

    reps(i,1,10){
        int hoge=count(cnt,cnt+26,i);
        if(hoge==0)continue;
        if(f)ans++;
        else f=true;
        ans+=2*hoge-1;
        if(i!=1){
            if(hoge==1)ans+=2;
            else ans+=4;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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


#define MOD 1000000007
using ll = long long;

bool operator<(const pair<int, int>& a, const pair<int, int>& b) {
	if (a.first == b.first) {
		return a.second < b.second;
	}
	return a.first < b.first;
}


const int sqrtN = 512;

struct SqrtDecomposition {
	int N, K;
	vector<int> data;
	vector<int> bucketMin;
	SqrtDecomposition(int n) : N(n) {
		K = (N + sqrtN - 1) / sqrtN;
		data.assign(K*sqrtN, INT_MAX);
		bucketMin.assign(K, INT_MAX);
	}

	void update(int x, int y) {
		int k = x / sqrtN;
		data[x] = y;
		int minV = INT_MAX;
		for (int i = k * sqrtN; i < (k + 1)*sqrtN; ++i) {
			minV = min(minV, data[i]);
		}
		bucketMin[k] = minV;
	}

	//[x, y)
	int find(int x, int y) {
		int minV = INT_MAX;
		for (int k = 0; k < K; ++k) {
			int l = k * sqrtN, r = (k + 1) * sqrtN;
			if (r <= x || y <= l) continue;
			if (x <= l && r <= y) {
				minV = min(minV, bucketMin[k]);
			}
			else {
				for (int i = max(x, l); i < min(y, r); ++i) {
					minV = min(minV, data[i]);
				}
			}
		}
		return minV;
	}
};
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, q; cin >> n >> q;
	SqrtDecomposition sd(n);

	for (int i = 0; i < q; ++i) {
		int com, x, y; cin >> com >> x >> y;
		if (com == 0) {
			sd.update(x, y);
		}
		else {
			cout << sd.find(x, y + 1) << endl;
		}
	}
	int a; cin >> a;
	return 0;
}


Measured memory_bytes: 3360
#include<stdio.h>
int main(void)
{
  int n,x;
  int don[101];

  scanf("%d%d",&n,&x);
  for(int i=1;i<=n;i++)
  {
    scanf("%d",&don[i]);
  }

  int sum=0;
  for(int i=1;i<=n;i++)
  {
    sum+=don[i];
  }

  int min=don[1];
  for(int i=2;i<=n;i++)
  {
    if (min>don[i]) min=don[i];
  }

  int nokori=x-sum;
  int donuts=nokori/min;

  int amo=donuts+n;

  printf("%d",amo);

  return 0;
}

Measured memory_bytes: 128
n,k = map(int,input().split())
a_list = list(map(int,input().split()))
a = 0
t = 1
d = 0
hoge_list = []
hoge_set = set()
while a < k:
  hoge_list.append(t)
  hoge_set.add(t)
  t = a_list[t-1]
  a += 1
  if t in hoge_set:
    b = hoge_list.index(t)
    d += 1
    break
if d == 0:
  print(t)
else:
  e = (k-b)%(a-b)
  print(hoge_list[b+e])


Measured memory_bytes: 32376
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
	int x, y;
	cin >> x >> y;

    cout << x+(y/2) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

   int a=0,b=0;

   scanf("%d %d",&a, &b);
   
   if(a>b){
      printf("a > b\n");
   }
   else if(a<b){
      printf("a < b\n");
   }
   else{
      printf("a == b\n");
   }

   return 0;

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  int k;
  scanf("%d", &k);
  if (k == 1) {
    puts("1");
    puts("1");
    return 0;
  }
  int n = (k + 3) / 4 * 2;
  printf("%d\n", n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      int color = (i + j) % n;
      if ((i & 1) && color + n < k) {
        color += n;
      }
      printf("%d%c", color + 1, j == n - 1 ? '\n' : ' ');
    }
  }
  return 0;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <ratio>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;
template<class T> using v = vector<T>;
template<class T, class U> using p = pair<T, U>;

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

template<class T> T read() { T x{}; cin >> x; return x; }
template<class T> v<T> read(int N){ v<T> x(N); REP(i, N) cin >> x[i]; return x; }

template<class T>
void write(const T &x){ cout << x << endl; }
void write(double x){ printf("%.15f\n", x); }

const ull MOD = 1000'000'007;

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

    if((A+B)%2 == 0){ write(abs(A-B)/2); }
    else{ 
        ll ans = max(A,B) - 1;
        ans = min(ans, N - min(A, B));
        ll ans3 = (abs(A - B) - 1)/2 + min(min(A, B), min(N-A, N-B)+1);
        ans = min(ans, ans3);
        write(ans);
    }
}



Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int k = Integer.parseInt(sc.next());
        int num = 7;
        int res = 1;
        if(k % 2 == 0 || k % 5 == 0){
            System.out.println("-1");
        }else if(k == 1 || k == 7){
            System.out.println("1");
        }else{
            while(num != 0){
                num = (num * 10 + 7) % k;
                res++;
            }
            System.out.println(res);
        }
    }
}

Measured memory_bytes: 35612
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<bitset>
#include<tuple>
#include<time.h>
#include<list>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

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




void solve(){
	int n, a[1010];
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n; i++){
		for(int j = i-1; j >= 0; j--){
			if(a[j+1] < a[j]) swap(a[j+1],a[j]);
			else break;
		}
		for(int j = 0; j < n; j++){
			cout << a[j];
			if(j != n-1) cout << " ";
		}
		cout << endl;
	}
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
 
int main (){
  int D,S,T;
  cin>>D>>T>>S;
  if(D<=T*S) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<int>> odd;
    vector<vector<int>> temodd;
    vector<int> tem;
    int p;
    rep(i,h){
        rep(j,w){
            cin >> p;
            if(p%2 == 1){
                tem = {i+1,j+1};
                temodd.push_back(tem);
            }
        }
        if(i%2==0){
            rep(j,temodd.size()){
                odd.push_back(temodd[j]);
            }
        }
        else{
            rep(j,temodd.size()){
                odd.push_back(temodd[temodd.size()-1-j]);
            }
        }
        temodd = {};
    }
    //rep(i,odd.size()){
        //cout << odd[i][0] << " " << odd[i][1] << endl;
    //}
    long long cnt = 1;
    vector<int> now;
    int fw;
    vector<vector<int>> ans;
    if(h%2 == 0){
        fw = 1;
    }
    else{
        fw = w;
    }
    int n = odd.size();
    if(n != 0){
        now = odd[0];
    }
    else{
        now = {h,fw};
    }
    vector<int> next;
    while(now[0] != h || now[1] != fw){
        if(now[0]%2 == 0){
            if(now[1] == 1){
                next = {now[0]+1,now[1]};
            }
            else{
                next = {now[0],now[1]-1};
            }
        }
        else{
            if(now[1] == w){
                next = {now[0]+1,now[1]};
            }
            else{
                next = {now[0],now[1]+1};
            }
        }
        tem = {now[0],now[1],next[0],next[1]};
        ans.push_back(tem);
        if(next[0] == odd[cnt][0] && next[1] == odd[cnt][1]){
            if(cnt == n-1 || cnt == n-2){
                break;
            }
            else{
                now = odd[cnt+1];
                cnt+=2;
            }
        }
        else{
            now = next;
        }
    }
    cout << ans.size() << endl;
    rep(i,ans.size()){
        cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " " << ans[i][3] << endl;
    } 
}

Measured memory_bytes: 22700
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
 
int main() {
    
    int N;
    cin >> N;
    
    vector<string> s(N);
    for (int i = 0; i < N; i++)
    {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
 
    sort(s.begin(), s.end());
 
    long long ans = 0;
    int count = 0;
    for (int i = 1; i < N; i++)
    {
        if (s[i] == s[i-1]) {
            count++;
            ans += count;
        }
        else {
            count = 0;
        }
    }
 
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


class UnionFind {
public:
    UnionFind(int n) : par(n, -1), ran(n, -1) {};

    void unite(int x, int y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return;

        if (ran[x] < ran[y]) {
            par[find_root(y)] += par[find_root(x)];
            par[x] = y;
        }
        else {
            par[find_root(x)] += par[find_root(y)];
            par[y] = x;
            if (ran[x] == ran[y]) ran[x]++;
        }
    }

    int size(int x) {
        return -par[find_root(x)];
    }

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

    int find_root(int x) {
        if (par[x] < 0) {
            return x;
        }
        else {
            return par[x] = find_root(par[x]);
        }
    }

private:
    std::vector<int> par, ran;
};


int main() {
    int n; std::cin >> n;
    std::vector<int> x(n), y(n);
    std::vector<int> prev(1e5, -1);
    UnionFind uf(1e5);
    for (int i = 0; i < n; i++) {
        std::cin >> x[i] >> y[i];
        x[i]--; y[i]--;
        if (prev[y[i]] != -1) {
            uf.unite(x[i], prev[y[i]]);
        }
        prev[y[i]] = x[i];
    }
    std::map<int, std::set<int>> s;
    for (int i = 0; i < n; i++) {
        s[uf.find_root(x[i])].insert(y[i]);
    }
    long long ans = -n;
    for (const auto &p : s) {
        ans += uf.size(p.first) * p.second.size();
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 4608
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n,m;cin>>n>>m;
  rep(i,m){
    ll a;cin>>a;
    n-=a;
  }
  if(n<0)cout<<-1<<endl;
  else cout<<n<<endl;
}
  

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

bool a[26];

int main()
{
	string S;
	cin >> S;

	int sz = S.size();
	for( int i = 0; i < sz; i++ ) {
		int c = S[i] - 'a';
		a[c] = true;
	}
	int i;
	for( i = 0; i < 26; i++ ) {
		if( a[i] != true ) {
			break;
		}
	}
	if( i >= 26 ) {
		cout << "None" << endl;
	}
	else {
		cout << (char)('a' + i) << endl;
	}

	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n, u, v, m;
	cin >> n >> u >> v >> m;
	map<int, pair<int, int>> bingo_u;
	map<int, pair<int, int>> bingo_v;
	REP(i,n)
		REP(j, n){
		int num;
		cin >> num;
		bingo_u[num] = pair<int, int>(i,j);
	}
	REP(i, n)
		REP(j, n){
		int num;
		cin >> num;
		bingo_v[num] = pair<int, int>(i, j);
	}
	queue<int> tyusen;
	REP(i, m){
		int num;
		cin >> num;
		tyusen.push(num);
	}
	vector<int> usa_h(n,0);
	vector<int> usa_v(n,0);
	int usa_naname[2] = {0};
	vector<int> nek_h(n,0);
	vector<int> nek_v(n,0);
	int nek_naname[2] = {0};

	while (!tyusen.empty()){
		int q = tyusen.front(); tyusen.pop();
		if (bingo_u.find(q) != bingo_u.end()){
			if (n == 1)
				u--;
			else{
				usa_h[bingo_u[q].first]++;
				if (usa_h[bingo_u[q].first] == n)
					u--;
				usa_v[bingo_u[q].second]++;
				if (usa_v[bingo_u[q].second] == n)
					u--;
				if (bingo_u[q].first == bingo_u[q].second){
					usa_naname[0]++;
					if (usa_naname[0] == n)
						u--;
				}
				if (bingo_u[q].first + bingo_u[q].second == n - 1){
					usa_naname[1]++;
					if (usa_naname[1] == n)
						u--;
				}
			}
		}
		if (bingo_v.find(q) != bingo_v.end()){
			if (n == 1)
				v--;
			else{
				nek_h[bingo_v[q].first]++;
				if (nek_h[bingo_v[q].first] == n)
					v--;
				nek_v[bingo_v[q].second]++;
				if (nek_v[bingo_v[q].second] == n)
					v--;
				if (bingo_v[q].first == bingo_v[q].second){
					nek_naname[0]++;
					if (nek_naname[0] == n)
						v--;
				}
				if (bingo_v[q].first + bingo_v[q].second == n - 1){
					nek_naname[1]++;
					if (nek_naname[1] == n)
						v--;
				}
			}
		}
		if (u <= 0 && v <= 0){
			cout << "DRAW" << endl;
			return 0;
		}
		else if (u <= 0){
			cout << "USAGI" << endl;
			return 0;
		}
		else if (v<=0){
			cout << "NEKO" << endl;
			return 0;
		}
	}
	cout << "DRAW" << endl;
}

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

int main(){
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  int x=x2;
  int y=y2;
  int dx=x2-x1;
  int dy=y2-y1;
  rep(i,2){
    swap(dx,dy);
    dx=-dx;
    x+=dx;
    y+=dy;
    cout<<x<<' '<<y<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
*/
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
using ll=long long; using dd=double;
using pii=pair<int,int>; using pll=pair<ll,ll>;
typedef vector<int> vi;
const ll INFLL=(ll)2e18, MOD=1'000'000'007;
const int INF=0x3f3fffff;
/////////////////// DEBUG MODE ///////////////////////////////////
#define D(x) cerr<<"DEBUG: "<<#x<<" is: "<<x<<'\n';
#define DD(x,y) cerr<<"DEBUG:("<<#x<<","<<#y<<") are: "<<x<<" "<<y<<'\n';
/////////////////// GLOBAL VARIABLES ////////////////////////////
vector<vector<int>> adj; vector<bool> vis;
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
/////////////////// FUNCTIONS ////////////////////////////////////
inline ll mexp(ll x,ll n,ll m){ll res=1;while(n){if(n&1)res=(res*x)%m;n>>=1;x=((x%m)*(x%m))%m;}return res;}
bool ispow2(ll x){ return x && (!(x&(x-1)));}
ll gcd(ll x, ll y){ pll p{x,y}; while(p.ss) p={p.ss,p.ff%p.ss}; return p.ff;}

/////////////////// MAIN STARTS //////////////////////////////////
int main(){
  ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
  cout<<fixed;cerr<<fixed; cout<<setprecision(8); cerr<<setprecision(3);
  srand(time(NULL)); rand();

#ifdef DEBUG
  clock_t tStart = clock(); //freopen("op.txt","w",stdout);
#endif

  int n,k,l=0,r=0; cin>>n>>k;
  for (int i=0;i<n;i++){
    int t; cin>>t;
    if(t!=1) ++l; else break;
  }
  r=n-l-1;
  if (k==n) {
    cout<<1<<'\n';
  }
  else{
    cout<<1+(int)ceil(((dd)n-k)/(k-1))<<'\n';
  }

#ifdef DEBUG
	cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1e3<<"ms.\n";
#endif
  return 0;
}


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

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int m;
    cin >> m;
    int ans = 0;
    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            for (int k = 1; k <= m; k++)
            {
                int cur1 = __gcd(i, j);
                int cur = __gcd(cur1, k);
                ans += cur;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3652
import copy
N = int(input())
X = list(map(int,input().split(" ")))
Y = copy.deepcopy(X)
Y.sort()
B = (Y[N//2]+Y[N//2-1])/2

for i in range(N):
    if X[i] <= B:
        print(Y[N//2])
    else:
        print(Y[N//2-1])


Measured memory_bytes: 26068
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 100000000
#define MOD 100000007
#define SIZE 100005
#define pi 	3.14159265358979323846

int main(){
	string s;
	while(1){
		cin >> s;
		if(s[0]=='0'){
			break;
		}
		ll sum = 0;
		REP(i,s.size()){
			char c[2];
			c[0] = s[i];
			sum += atoi(c);
		}
		cout << sum << endl;
	}
	return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(false);
	int N;
	bool ans = true;

	cin >> N;
	int bt = 0, bx=0, by=0;
	rep(i,N){
		int t, x, y;
		cin >> t >> x >> y;
		int len = abs(x-bx) + abs(y-by);
		int time = t - bt;
		if( len > time || (time - len)%2 == 1 ) ans = false;
		bt = t;
		bx = x;
		by = y;
	}

	cout << (ans?"Yes":"No") << endl;

	return 0;
}


Measured memory_bytes: 256
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

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

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int a,b,c;
signed main(){

    cin >> a >> b >> c;
    cout << b + min(a+b+1,c) << endl;
}

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

using namespace std;

typedef long long ll;

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

	int counts['z' + 1];
	fill(counts, counts + ('z' + 1), 0);

	for (int i = 0; i < w.length(); i++) {
		counts[(int) w[i]]++;
	}

	for (int i = 0; i < 'z' + 1; i++) {
		if (counts[i] % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define fs first
#define se second
#define M 998244353
#define pii pair<long long,long long>
 
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
unordered_map<char,pii>dir;
ll D=1e9;
 
bool check(int x,int y,int n,int m)
{
	return x>0 && y>0 && x<=n && y<=m;
}
int fun()
{
	static int num = 16;
	return num--;
}
ll exp(ll a,ll p,ll m)
{
	if(p==0)
		return 1LL;
	if(p==1)
		return a;
	ll h=exp(a,p/2,m);
	h=(h*h)%m;
	if(p&1)
		h=(h*a)%m;
	return h;
}
int find_parent(ll a,vector<ll>&dsu)
{
	while(a!=dsu[a])
	{
		a=dsu[dsu[a]];
	}
	return a;
}
void join(ll a,ll b,vector<ll>&dsu,vector<ll>&si)
{
	ll pa=find_parent(a,dsu);
	ll pb=find_parent(b,dsu);
	if(pa!=pb)
	{
		if(si[pa]>si[pb])
		{
			dsu[pb]=pa;
			si[pa]+=si[pb];
		}
		else
		{
			dsu[pa]=pb;
			si[pb]+=si[pa];
		}
	}
}
ll cal(ll h)
{
	ll mn=LLONG_MAX,mx=LLONG_MIN;
	while(h)
		{
			ll r=h%10;
			mn=min(r,mn);
			mx=max(r,mx);
			h/=10;
		}
	return mn*mx;

}

void anon_sort(ll u,string &ans,vector<ll>&mark,int arr[][26])
{
	mark[u]=1;
	for(ll i=0;i<26;i++)
	{
		if(arr[u][i] && mark[i]==0)
			anon_sort(i,ans,mark,arr);
	}
	ans.pb(u+'A');
}



int main()
{
	ios_base::sync_with_stdio(false);
	
	ll k;
	cin>>k;
	string s;
	cin>>s;
	if(s.size()<=k)
		cout<<s<<endl;
	else
	{
		for(ll i=0;i<k;i++)
			cout<<s[i];
		cout<<"...\n";
	}
}

Measured memory_bytes: 3604
N = int(input())
A = list(map(int, input().split()))
B = [ 0 for _ in range(N+1) ]
ans = []
for i in range(1, N+1)[::-1]:
  c = 0
  for j in range(i, N+1, i):
    if B[j]:
      c += 1
  if c % 2 == A[i-1]:
    B[i] = 0
  else:
    B[i] = 1
    ans.append(i)
ans.sort()
print(len(ans))
print(" ".join([ str(x) for x in ans]))



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

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define rep(i,a) for(i = 0 ; i < a ; i++)
#define repr(i,a) for(i = a ; i >= 0 ; i--)
#define REP(i,a,b) for(i = a ; i <= b ; i++)
#define REPR(i,a,b) for(i = a ; i >= b ; i--)

#define scan(N) scanf("%lld",&N)
#define print(N) printf("%lld",N)
#define scan2(N1,N2) scanf("%lld %lld",&N1,&N2)
#define print2(N1,N2) printf("%lld %lld",N1,N2)
#define scan3(N1,N2,N3) scanf("%lld %lld %lld",&N1,&N2,&N3)
#define print3(N1,N2,N3) printf("%lld %lld %lld",N1,N2,N3)

#define mem(a,b)memset(a,b,sizeof(a))
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl

#define endl '\n'

const long long INF = 2000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

template<class T> bool is_prime(T n)
{
	if((n%2 == 0 and n > 2) or n < 2 )
		return false;
	for(T i = 3; i*i <= n ; i += 2)
	{
		if( n % i == 0)
			return false;
	}
	return true;
}
lli power(lli a,lli b)
{
    lli value;
    if(!b)
    	return 1;
    else if(b%2==0) {
        value = power(a,b/2)%MOD;
        return (value * value)%MOD;
    }
    else {
        value = power(a,b/2)%MOD;
        return ((a*value)%MOD*(value))%MOD;
    }
}

int main()
{
	opt;
	lli n;
    cin >> n;
    if(n < 3)
        cout << 0 << endl;
    else
        cout << n/3 << endl;
	return 0;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define ll long long 
#define N 200005
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define piii pair<int, pii>
#define print(x) cout << #x << "=" << x << "\t";
#define endl "\n"
#define newline cout << endl;

int n;
int k;
int a[N][3];
ll dp[N][3];

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); 
    cin >> n;
    for(int i=1;i<=n;i++)
        for(int j=0;j<3;j++)
            cin >> a[i][j];
    for(int i = 1; i <= n; i++)
        for(int j = 0; j < 3; j++)
            dp[i][j] = a[i][j] + max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]);
    cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
    return 0;
}


Measured memory_bytes: 6400
#include<stdio.h>

int  main()
{
    int i,j=0;
    char a[50],b[50];

    scanf("%s%s",a,b);

    for(i=0;i<3;i++)
    {
        if(a[i]==b[i])
        {
            j++;
        }
    }
    printf("%d\n",j);

    return  0;
}

Measured memory_bytes: 128
import sys
import numpy as np
INF = 10**18+5
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a = np.sort(a)
    ap = a[a > 0]
    an = a[a < 0]
    zc = n * (n - ap.size - an.size)

    l = -INF
    r = INF
    while(l+1 < r):
        x = (l+r)//2

        total = (n-np.searchsorted(a, -(-x // an), side='left')).sum()
        if x >= 0:
            total += zc
        total += np.searchsorted(a, x // ap, side='right').sum()
        total -= a[a*a <= x].size
        total //= 2
        if total < k:
            l = x
        else:
            r = x

    print(r)


main()


Measured memory_bytes: 32320
def ncr(n, r):
    if n < r: return 0
    r = min(r, n - r)
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + i + 1 for i in range(r)]
    denominator = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= numerator[k]
    return int(result)


n, p = map(int, input().split())
a = list(map(int, input().split()))
# ans = 0
# for maskN in range(1 << n):
#     # print(maskN)
#     tmp = 0
#     for i in range(n):
#         if (maskN >> i & 1 == 1):
#             tmp += a[i]
#     if tmp % 2 == p:
#         ans += 1

# print(ans)

dic = {'odd': 0, 'even': 0}

for i in a:
    if i % 2 == 0:
        dic['even'] += 1
    else:
        dic['odd'] += 1

even = 0
odd = 0
# 偶数個の組み合わせ総数
for i in range(dic['even'] + 1):
    even += ncr(dic['even'], i)

if p == 0:
    for i in range(0, dic['odd'] + 1, 2):
        odd += ncr(dic['odd'], i)

else:
    for i in range(1, dic['odd'] + 1, 2):
        odd += ncr(dic['odd'], i)

print(odd * even)


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
int par(int i){
  return i / 2;
}
int lef(int i){
  return i * 2;
}
int rig(int i){
  return 2 * i + 1;
}

void max_Heap(vll &A, int i){
  int h = SZ(A)-1;
  int l = lef(i);
  int r = rig(i);
  int large = i;
  if(l <= h && A[l] > A[i]) large = l;
  if(r <= h && A[r] > A[large]) large = r;

  if(large != i){
    swap(A[i],A[large]);
    max_Heap(A,large);
  }
}
void tr(vll &A){
  int h = SZ(A)-1;
  for(int i=h/2;i>=1;i--){
    max_Heap(A, i);
  }
}
//-----------------------------------------

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

  int n;
  cin >> n;
  vll a(n+1);
  REP(i,n) cin >> a[i+1];
  tr(a);
  REP(i,n) cout << " " << a[i+1];
  cout <<endl;





  return 0;
}



Measured memory_bytes: 6764
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i < n; i++)
#define repv(i,n) for(int i = n-1; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;

char BUF[3500000];
inline void I(int&a){scanf("%d",&a);}
inline void I(int&a,int&b){scanf("%d%d",&a,&b);}
inline void I(int&a,int&b,int&c){scanf("%d%d%d",&a,&b,&c);}
inline void I(int&a,int&b,int&c,int&d){scanf("%d%d%d%d",&a,&b,&c,&d);}
inline void L(ll&a){scanf("%lld",&a);}
inline void L(ll&a,ll&b){scanf("%lld%lld",&a,&b);}
inline void L(ll&a,ll&b,ll&c){scanf("%lld%lld%lld",&a,&b,&c);}
inline void L(ll&a,ll&b,ll&c,ll&d){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);}
inline void S(string&str){str.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)str.pb(BUF[i]);}
inline void SV(vector<int>&v){v.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)if('a'<=BUF[i]&&BUF[i]<='z')v.pb(BUF[i]-'a');else v.pb(BUF[i]-'A');}

const auto EPS = 1e-10;
const auto INF = 100000000;
const auto MOD = 1000000007;
typedef pair<ll,ll> P;

int n, k;
int a[5000];
bool dp[5001];

bool check(){
    bool ret = true;
    rep(i,n){
        if(a[i] < k) return false;
    }
    return ret;
}

int main(){
    I(n,k);
    rep(i,n) I(a[i]);
    if(check()){
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    sort(a,a+n);
    /*
    rep(i,n){
        if(a[i] >= k){
            n = i;
            break;
        }
    }
    */
    int ss = -1, ee = n, mid;
    while(ee-ss > 1){
        mid = (ss+ee)/2;
        memset(dp,0,sizeof(dp));
        dp[0] = true;
        for(int i = 0; i < n; i++){
            if(i == mid) continue;
            for(int j = k-1-a[i]; j >= 0; j--){
                if(dp[j]){
                    dp[j+a[i]] = true;
                }
            }
        }
        int x = a[mid];
        bool ok = true;
        for(int i = max(0,k-x); i < k; i++){
            if(dp[i]) ok = false;
        }
        if(ok) ss = mid;
        else ee = mid;
    }
    cout << ss+1 << endl;
}
































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

int main() {
    // input
    int ABCD;
    cin >> ABCD;

    // solve & output
    int A = ABCD / 1000; ABCD = ABCD - A * 1000;
    int B = ABCD / 100; ABCD = ABCD - B * 100;
    int C = ABCD / 10; ABCD = ABCD - C * 10;
    int D = ABCD;

    if      ((A + B + C + D) == 7) cout << A << "+" << B << "+" << C << "+" << D;
    else if ((A + B + C - D) == 7) cout << A << "+" << B << "+" << C << "-" << D;
    else if ((A + B - C + D) == 7) cout << A << "+" << B << "-" << C << "+" << D;
    else if ((A + B - C - D) == 7) cout << A << "+" << B << "-" << C << "-" << D;
    else if ((A - B + C + D) == 7) cout << A << "-" << B << "+" << C << "+" << D;
    else if ((A - B + C - D) == 7) cout << A << "-" << B << "+" << C << "-" << D;
    else if ((A - B - C + D) == 7) cout << A << "-" << B << "-" << C << "+" << D;
    else if ((A - B - C - D) == 7) cout << A << "-" << B << "-" << C << "-" << D;
    cout << "=7" << endl;

    return 0;
}


Measured memory_bytes: 256
wall = "#"*20

table = [[[0]*10 for r in range(3)] for i in range(4)]

N = int(input())

for i in range(N):
    b,f,r,v = map(int,input().split())
    table[b-1][f-1][r-1] += v

    

for i in range(4):
    if i != 0:
        print(wall)
        
    for r in range(3):
        for v in range(10):
            print(" %d"%table[i][r][v],end = "")
        print("")


Measured memory_bytes: 5620
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

const double PI=acos(-1.0);

int N; vector<pair<int,int>> red,blue;
void input()
{
    cin >> N;
    red.resize(N);
    for (int i = 0; i < N; ++i) cin >> red[i].first >> red[i].second;
    blue.resize(N);
    for (int i = 0; i < N; ++i) cin >> blue[i].first >> blue[i].second;
}

void solve()
{
    sort(red.begin(),red.end());
    sort(blue.begin(),blue.end());   
    vector<int> is_checked(N,0);

    int ans = 0;
    for (int i = 0; i < N; ++i){
        int max_y_value = -1, max_y_num = -1;
        for (int j = 0; j < N; ++j){
            if (red[j].first >= blue[i].first) break;
            if (red[j].second >= blue[i].second || is_checked[j] == 1) continue;
            if (max_y_value <= red[j].second){
                max_y_value = red[j].second;
                max_y_num = j;
            }
        }
        if (max_y_num == -1) continue;
        is_checked[max_y_num] = 1;
        ++ans;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 3620