akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 100005;

int n;
int a[MAX_N];

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int prev = 0, res = 0;
	for (int i = 0; i < n; i++)
	{
		//if (i + 1 < n && a[i] == a[i + 1])
		//	continue;
		//cout << "! " << a[i] << " " << prev << " " << (n - i) << endl;
		if ((a[i] - prev) % 2 != 0)
			res ^= (n - i);
		prev = a[i];
	}
	//cout << res << endl;
	cout << (res == 0 ? "second" : "first") << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll kzyou(ll a,ll k){//aのk乗を返す
    ll zyou = 1;
    for(ll i = 1;i<=k;i++){
        zyou *= a;
    }
    return zyou;
}
/*Aをmod2の配列Bに変換 Bのうち1と0の個数をカウント
*/


int main() {
 ll N,P;
 cin >> N >>P;
 vector<int> A(N);
 rep(i,N){
     cin >> A[i];
 }

 vector<int> B(N);
 rep(i,N){
     B[i] = A[i]%2;
 }

 int c0 = 0;
 int c1 = 0;
 rep(i,N){
     if(B[i] == 0) c0++;
     if(B[i] == 1) c1++; 
 }
 ll ans = 0;
if(c1 == 0){
    if(P == 0)ans = kzyou(2,N);
    else if(P == 1) ans = 0;
}
//Aに奇数が含まれている場合
else ans = kzyou(2,N-1);

cout << ans << endl;
 }

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

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

	vector<int> ab(3);
	vector<vector<int> > x(n,ab);

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

	vector<int> temp(3);
	vector<vector<int > > dp(n,ab);

	dp[0][0]=x[0][0];
	dp[0][1]=x[0][1];
	dp[0][2]=x[0][2];

	for(int i=1;i<n;i++)
	{
		dp[i][0]=x[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=x[i][1]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=x[i][2]+max(dp[i-1][1],dp[i-1][0]);
			
		
		

	}

	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

	return 0;
}

Measured memory_bytes: 11136
#include <cstdio>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <tuple>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long int ll;
using namespace std;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main()
{
    string a = "CODEFESTIVAL2016";
    int res = 0;
    string s;
    cin >> s;
    REP(i,16)
    {
        if(s[i] != a[i]){res++;}
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		using P = pair<LL, LL>;
		vector<P> ba(n);
		REP(i, n) cin >> ba[i].S >> ba[i].F;
		sort(ALL(ba));
		LL sum = 0;
		string ans = "Yes";
		REP(i, n) {
			sum += ba[i].S;
			if(sum > ba[i].F) {
				ans = "No";
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    cout << s[0] << s.size() - 2 << s[(int)s.size() - 1] << endl;
}

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

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e6 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};

ll chk[1000006], ar[200006];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll n, i, cnt = 0, j, div;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> ar[i];
        chk[ar[i]]++;
        //cout << chk[ar[i]] << " " << ar[i] << " " << i  << endl;
    }
    //sort(ar, ar+n);
    for(i = 0; i < n; i++){
        int f = 0;
        //cout << i << endl;
        if(chk[ar[i]] > 1) continue;
        if(ar[i] == 2 || ar[i] == 3){
            if(chk[1]){
                continue;
            }
        }
        else if(ar[i] == 1){
            cout << 1 << endl;
            return 0;
        }
        for(j = 2; j <= sqrt(ar[i]); j++){
            if(ar[i]%j == 0){
                div = ar[i]/j;
                if(chk[div] || chk[j]){
                    f = 1;
                    //cout << ar[i] << " " << j << endl;
                    break;
                }
            }
        }
        if(!f && !chk[1]) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 12860
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)10e9+7;
const int INF = 0x3f3f3f3f;
int a[100001];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int nn, t;
    int mi = INT_MAX, ma = -1, range=0, n=0;
    cin >> nn >> t;
    for(int i=0; i<nn; i++)
    {
        cin >> a[i];
        if(a[i]<mi)
        {
            mi=a[i];
            ma=mi;
        }
        else if(a[i]>ma)
        {
            ma=a[i];
            if(ma-mi>range)
            {
                range = ma-mi;
                n=1;
            }
            else if(ma-mi==range)
            {
                n++;
            }
        }
    }
    cout << n;
}

//TODO: 47


Measured memory_bytes: 640
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;

#define MAX_N 100000000

int par[MAX_N];
int ran[MAX_N];
long long siz[MAX_N];

void init_uft(int n){
  for(int i=0;i<n;i++){
    par[i] = i;
    ran[i] = 0;
    siz[i] = 1;
  }
}

int find_uft(int x){
  if(par[x] == x){
    return x;
  }
  else{
    return par[x] = find_uft(par[x]);
  }
}

int unite_uft(int x,int y){
  x = find_uft(x);
  y = find_uft(y);
  if(x == y) return 0;
  long long s1,s2;
  s1 = siz[x];
  s2 = siz[y];
  if(ran[x] < ran[y]){
    par[x] = y;
    siz[y] += siz[x];
  }
  else{
    par[y] = x;
    siz[x] += siz[y];
    if(ran[x] == ran[y]) ran[x]++;
  }
  return s1*s2;
}

int main(){
  long long n,m;
  cin >> n >> m;
  pair<int,int> e[m];
  for(int i=0;i<m;i++){
    cin >> e[i].first >> e[i].second;
  }
  long long ans[m];
  ans[m-1] = n*(n-1)/2;
  init_uft(n);
  for(int i=0;i<m-1;i++){
    ans[m-2-i] = ans[m-1-i] - unite_uft(e[m-1-i].first-1,e[m-1-i].second-1);
  }

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



  return 0;
}

Measured memory_bytes: 7808
#include <stdio.h>

int main(void)
{
    int i,j,n,tmp,A[1000];
   scanf("%d",&n);
   for(i=0;i<n;i++){
    scanf("%d",&A[i]);
   }

        
        for(j=0;j<n;++j){
   
            for(i=j; i!=0 && A[i]<A[i-1] ;--i){
             
                tmp=A[i-1];
                A[i-1]=A[i];
                A[i]=tmp;
            }
              for(i=0;i<n;++i){
                if(i>0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
        }
    return 0;
}


Measured memory_bytes: 2140
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

//#include<boost/circular_buffer.hpp>
using namespace std;

//cout << fixed << setprecision(10);
typedef long long ll;
#define PI 3.141592653589793
#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";
#define rep(i,n) for(int i=0;i<n;i++)

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}
	long long int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

long long int lcm(long long int a, long long int b) {
	long long int L;
	L = a / gcd(a, b);
	L *= b;
	return L;
}

vector<long long  int> Prime;
void Eratosthenes(long long int n) {
	vector<bool> is_prime(n, true);
	for (int i = 2; i * i <= n; i++) {
		;
		if (is_prime.at(i)) {
			for (int j = i * i; j <= n; j += i) {
				is_prime.at(j) = false;
			}
		}
		Prime.emplace_back(i);
	}
}

/*
map<int, int> prime;
void Prime_number(long long int n) {
	for (int i = 2; i <= n; i++) {
		int count = 0;
		while (n % i == 0) {
			count++;
			n /= i;
		}
		if (count != 0) {
			prime.insert(make_pair(i, count));
		}
	}
}
*/
//std::cout.fill('0');

int keta(long long int N) {
	int k = 0;
	while (N > 0) {
		N /= 10;
		k++;
	}
	return k;
}



int Combination(int n, int m) {
	long long int s = 1, t = 1;
	int tmp = n;
	while (n - m != tmp) {
		s *= tmp;
		tmp--;
	}
	tmp = m;
	while (tmp != 1) {
		t *= tmp;
		tmp--;
	}
	return s / t;
}


int main() {
	long long int n, a, b;
	string s, t;

	cin >> a >> b;
	n = lcm(a, b);
	cout << n << endl;
}


/*
int main() {
	int n; cin >> n;
	vector<int> f(n);
	vector<int> t(n,1);
	int x[15][15], y[15][15];
	int p[15][15], q[15][15];
	vector<int> a(n);
	int count = 0, ans = 0;

	for (int i = 0; i < n; i++) {
		cin >> f.at(i);
		for (int j = 0; j < f.at(i); j++) {
			cin >> p[i][j] >> q[i][j];
		}
	}
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			a.at(i) = f.at(i);
			for (int j = 0; j < a.at(i); j++) {
				x[i][j] = p[i][j]; y[i][j] = q[i][j];
			}
		}

		for (int i = 0 ; i < n; i++) {
			if (t.at((i+k)%n) == 0) {
				for (int j = 0; j < a.at((i + k) % n); j++) {
					if (y[(i + k) % n][j] == 1)
						y[(i + k) % n][j] = 0;
					else
						y[(i + k) % n][j] = 1;
				}
			}
			for (int j = 0; j < a.at(i); j++) {
				a.at(x[(i + k) % n][j] - 1) *= y[(i + k) % n][j];
			}
		}
		count = 0;
		for (int i = 0; i < n; i++) {
			if (a.at(i) == 1)
				count++;
		}
		ans = max(ans, count);
	}
	cout << ans << endl;
}
*/

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

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

  string M = S;
  set<char> Set;
  int cnt = 0;
  for (int i = 0; i < M.size() - 1; i++) {
    if (M.at(i) == M.at(i + 1)) {
      cnt++;
      M.at(i + 1) = 'C';
      Set.insert(M.at(i));
    }
  }

  string L = S + S;
  int cnt2 = 0;
  for (int i = 0; i < L.size() - 1; i++) {
    if (L.at(i) == L.at(i + 1)) {
      cnt2++;
      L.at(i + 1) = 'C';
    }
  }

  if (Set.size() == 1 || S.size() == 1) {
    cout << S.size() * K / 2 << endl;
    return 0;
  }

  if (S.at(0) != S.at(S.size() - 1))
    cout << cnt * K << endl;
  else
    cout << cnt + (K - 1) * (cnt2 - cnt) << endl;
}


Measured memory_bytes: 256
from math import factorial

N = int(input())
K = int(input())


def ncr(n, r):
    if n < r:
        return 0
    return factorial(n) // factorial(r) // factorial(n - r)


def k1(n):
    s = str(n)
    return (len(s) - 1) * 9 + int(s[0])


def k2(n):
    if n < 10:
        return 0
    s = str(n)
    res = ncr(len(s)-1, 2) * 9 * 9
    res += (int(s[0]) - 1) * k1(10 ** (len(s) - 1) - 1) + k1(int(s[1:]))
    return res


def k3(n):
    s = str(n)
    res = ncr(len(s)-1, 3)*9*9*9
    res += (int(s[0]) - 1) * k2(10 ** (len(s) - 1) - 1) + k2(int(s[1:]))
    return res


kf = [k1, k2, k3]
print(kf[K-1](N))


Measured memory_bytes: 38256
n=int(input())
a=list(map(int,input().split()))
c=0
is_zero=False

for aa in a:
    if aa<0:c+=1
    if aa==0:is_zero=True

a=[abs(aa) for aa in a]
if c%2==0 or is_zero==True:
    print(sum(a))
else:
    print(sum(a)-2*min(a))


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

int main() {
  int N;
  cin >> N;
  vector<long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (0 < i) A[i] += A[i-1];
  }
  long ans = abs(A[0] - (A[N-1] - A[0]));
  for (int i = 1; i < N-1; i++) {
    long x = A[i], y = A[N-1] - A[i];
    ans = min(ans, abs(x - y));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
B, A = map(int, input().split())

h, w = 100, 100
grid = [['.'] * 100 for _ in range(50)] + [['#'] * 100 for _ in range(50)]

for i in range(A - 1):
    A1, A2 = divmod(i, 50)
    grid[2 * A1][2 * A2] = '#'

for j in range(B - 1):
    B1, B2 = divmod(j, 50)
    grid[2 * B1 + 51][2 * B2] = '.'

print(h, w)
for i in range(100):
    print(''.join(grid[i]))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll,ll> P;
typedef long double ld;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, x;
	cin >> n >> x;
	if (x == 1 || x == 2 * n - 1) {
		cout << "No\n";
	} else {
		cout << "Yes\n";
		if (x == n) {
			rep (i, 2 * n - 1) {
				cout << i + 1 << "\n";
			}
		} else if (x < n) {
			int y = 2 * n - x, nn = 2 * n - 1;
			repp (i, y + 1 - n, y + 1) cout << nn - i << "\n";
			rep (i, y + 1 - n) cout << nn - i << "\n";
			repp (i, y + 1, 2 * n - 1) cout << nn - i << "\n";
		} else {
			repp (i, x + 1 - n, x + 1) cout << i + 1 << "\n";
			rep (i, x + 1 - n) cout << i + 1 << "\n";
			repp (i, x + 1, 2 * n - 1) cout << i + 1 << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <assert.h>
using namespace std;

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

    vector<int64_t> x(N), y(N), h(N);

    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> h[i];
    }

    for (int cx = 0; cx <= 100; cx++) {
        for (int cy = 0; cy <= 100; cy++) {
            int64_t lb_h = 1, ub_h = (1LL << 50);

            for (int i = 0; i < N; i++) {
                if (h[i] == 0) ub_h = min(ub_h, abs(x[i] - cx) + abs(y[i] - cy));
                else {
                    int64_t tmp_h = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
                    lb_h = max(lb_h, tmp_h);
                    ub_h = min(ub_h, tmp_h);
                }
            }

            if (lb_h == ub_h) {
                cout << cx << " " << cy << " " << lb_h << endl;
                return 0;
            }
        }
    }
    assert(false);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  rep(i, N) cin >> H[i];

  vector<int> diff(N - 1);
  rep(i, N - 1) { diff[i] = H[i + 1] - H[i]; }

  int minus_one = false;
  rep(i, N - 1) {
    if (diff[i] >= 1) {
      minus_one = false;
    } else if (diff[i] <= -2) {
      cout << "No" << endl;
      return 0;
    } else if (diff[i] == -1) {
      if (minus_one) {
        cout << "No" << endl;
        return 0;
      } else {
        minus_one = true;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define p 1000000007

struct activity{
    int a;
    int b;
    int c;
};

int solve(int n,vector<activity> &v)
{
    int dp[n+1][3];
    dp[1][0]=v[1].a;
    dp[1][1]=v[1].b;
    dp[1][2]=v[1].c;
    
    for(int i=2;i<=n;i++)
    {
        dp[i][0]=v[i].a+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=v[i].b+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=v[i].c+max(dp[i-1][0],dp[i-1][1]);
    }
    
    return max(max(dp[n][0],dp[n][1]),dp[n][2]);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin>>n;
    
    vector<activity> v(n+1);
    
    for(int i=1;i<=n;i++)
    {
        cin>>v[i].a>>v[i].b>>v[i].c;
    }
    cout<<solve(n,v);
    return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n;cin >> n;
	vll a(n);
	rep(i, n) cin >> a[i];

	cpp_int ans = 1;
	sort(all(a));
	if(a[0] == 0){ cout << 0 << endl; return 0; }
	else {
		for(cpp_int t : a){
			ans *= t;
			if(ans > INFLL){
				cout << -1 << endl;
				return 0;
			}
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4040
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
   int A, B, C;
   cin >> A >> B >> C;
   if (A + B >= C) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();
		sc.close();
		int s = 0;
		for(int i=0; i<K; i++) {
			if(A>0) {
				A--;
				s++;
			}else if(B>0) {
				B--;
			}else if(C>0) {
				C--;
				s--;
			}
		}
		System.out.println(s);
	}

}

Measured memory_bytes: 36160
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
const int N = 1e7 + 5;
string a[N], b[N];

int main(){
	string a, b;
	while(cin >> a >> b){
		int len1 = a.length();
		int len2 = b.length();
		if(len1 > len2)
			cout << "GREATER" << endl;
		else if(len1 < len2)
			cout << "LESS" << endl;
		else{
			int x, y;
			for(int i = 0; i < len1; i++){
				if(a[i] > b[i]){
					x = 1;
					break;
				}
				else if(a[i] < b[i]){
					x = 0;
					break;
				}
				else{
					x = 2;
				}
			}
			if(x == 1)
				cout << "GREATER" << endl;
			else if(x == 0)
				cout << "LESS" << endl;
			else
				cout << "EQUAL" << endl;
		}
	}
}

Measured memory_bytes: 156544
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long  N;
    cin >> N;

    long long sum = 0,result;

    long long l,A[N+1] = {};
    for (int i = 1; i< N ;i++){
        cin >> l;
        A[l]++;
    }

    for (int i=1 ; i<=N ; i++) {
      cout << A[i]  << endl;
    }

    return 0;
}
 


Measured memory_bytes: 5144
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B_ROTN solver = new B_ROTN();
        solver.solve(1, in, out);
        out.close();
    }

    static class B_ROTN {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            String s = in.next();

            for (char c : s.toCharArray())
                System.out.print((char) (((c + n) - 'A') % 26 + 'A'));

        }

    }
}



Measured memory_bytes: 25812
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 900000000
signed main(){
    int m,d;cin>>m>>d;
    int ans=0;
    for(int i=1;i<=m;i++){
        for(int j=22;j<=d;j++){
            if(j%10>=2){
                if(j/10*(j%10)==i)ans++;
            }
        }
    }
    cout<<ans<<endl;
}
        

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
using namespace std;
signed main(){
    int n;
    cin >> n;
    vector<int>v(n);
    for(auto & e : v) cin >> e;
    int sum = accumulate(all(v),0LL);
    int idx = 0;
    long double temp = INF;
    int ans = 0;
    for(auto e : v){
        if(temp > abs(e*n - sum)){
            ans = idx;
            temp = abs(e*n-sum);
        }
        idx++;
    }
    cout << ans << endl;
    
}



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

using namespace std;

int conv(string s)
{
    int res = 0;
    for (int i = 0; i < (int)s.length(); i++)
    {
        res *= 10;
        res += (s[i] - '0');
    }
    return res;
}

int solve(string s)
{
    string s2 = s;
    int res = 0;
    int val = conv(s);
    set<int> st;
    while (val >= 10)
    {
        int ma = -1;
        for (int i = 1; i < (int)s2.length(); i++)
        {
            string a = s2.substr(0, i), b = s2.substr(i);
            int v1 = conv(a), v2 = conv(b);
            ma = max(ma, v1 * v2);
        }
        //cout<<ma<<endl;
        if (st.find(ma) != st.end())
        {
            res = -1;
            break;
        }
        st.insert(ma);
        val = ma;
        s2 = to_string(ma);
        res++;
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        string n;
        cin >> n;
        cout << solve(n) << endl;
    }
    return 0;
}


Measured memory_bytes: 3292
/*input
5
WWRRR
*/
 
 
 
#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#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(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
#define F first
#define S second  
#define pb push_back  
#define INF 3e18
#ifdef gaviria
#define TRACE
#endif
#ifdef TRACE
#define trace(...) _f(#VA_ARGS, __VA_ARGS_)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< ll, ll > ii;
typedef unordered_set<int> usi;
 
 
 
ll n,i,j,k,m,c;

void solve()
{

    cin>>n;
    string a;
    cin>>a;
    int pre[n+1];
    int post[n+1];
c=0;
pre[0]=0;
    for(i=0;i<n;i++)
    {
        if(a[i]=='W')
            c++;
        if(a[i]=='R')
            pre[i+1]=0;
        else pre[i+1]=1;

      pre[i+1]+= pre[i];
 
    }

    int ans=min(c,n-c);
    int temp=0;

    for(i=0;i<n;i++)
    {
        temp= (n-i)-(c-pre[i]);
          // cout<<temp<<" "<<pre[i];

        if(pre[i]>temp)
        {
            ans=min(ans,pre[i]);
        }
        else 
        {
             ans=min(ans,temp);
        }


    }

    cout<<ans;

}
 
 
 
 
 
signed main()
{// inputFile;


    fast;
    int T = 1;
    // cin >> T;
    ll h=T;
    while(T--){
 
        solve();
        cout<<endl;
 
     
        
        
 
    }
    
    
    return 0;
 
}

Measured memory_bytes: 5252
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int gcd(int a, int b)
{
    if (a < b) swap(a, b);
    while (true)
    {
        if (b == 0) break;
        int r = a % b;
        a = b;
        b = r;
    }
    return a;
}

const int num_match[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int main()
{
    int N, M;
    cin >> N >> M;
    int A[M];
    REP(i, M) cin >> A[i];
    sort(A, A + M, greater<int>());
    int dp[N + 1];
    REP(i, N + 1) dp[i] = -2147483648;
    dp[0] = 0;
    REP(n, N + 1)
    {
        REP(j, M)
        {
            int m = n - num_match[A[j]];
            if (m >= 0)
            {
                dp[n] = max(dp[n], dp[m] + 1);
            }
        }
    }

    int n = N;
    while (n > 0)
    {
        REP(i, M)
        {
            int m = n - num_match[A[i]];
            if (m >= 0)
            {
                if (dp[n] == dp[m] + 1)
                {
                    n = m;
                    cout << A[i];
                    break;
                }
            }
        }
    }
    cout << endl;

    return 0;
}


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

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



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

	ll sum = 0;
	for (auto x : N) {
		sum += x - '0';
	}

	cout << (sum % 9 == 0 ? "Yes" : "No") << endl;

	return 0;
}

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

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> using iodef_rng_t = typename enable_if<decltype(declval<C>().begin(), true_type{})::value && !is_same<C, string>::value>::type;
template<class C, class = iodef_rng_t<C>> istream& operator>>(istream& in, C& c) { for (auto& v : c) { in >> v; } return in; }
template<class C, class = iodef_rng_t<C>> ostream& operator<<(ostream& out, const C& c) { int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector a(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        cin >> a[i];
    }
    int min_sum_c = numeric_limits<int>::max();
    for (int b = 0; b < (1 << n); b++) {
        int sum_c = 0;
        vector<int> sum(m);
        for (int i = 0; i < n; i++) {
            if (b >> i & 1) {
                sum_c += c[i];
                for (int j = 0; j < m; j++) {
                    sum[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for (int j = 0; j < m; j++) {
            if (sum[j] < x) {
                ok = false;
                break;
            }
        }
        if (ok) {
            min_sum_c = min(min_sum_c, sum_c);
        }
    }
    if (min_sum_c == numeric_limits<int>::max()) {
        cout << -1 << '\n';
    } else {
        cout << min_sum_c << '\n';
    }
}


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

int n;
int a[50];
bool b[50];

bool pourAll(int p);

bool pour(int p, int q, int rest) {
  if (!rest) {
    return pourAll(p+1);
  }
  if (q == n) {
    return false;
  }
  if (!b[q] && a[q] <= rest) {
    b[q] = true;
    if (pour(p, q+1, rest-a[q])) {
      return true;
    }
    b[q] = false;
  }
  return pour(p, q+1, rest);
}

bool pourAll(int p) {
  if (p == n) {
    return true;
  }
  if (!b[p]) {
    return false;
  }
  if (pour(p, p+1, a[p])) {
    return true;
  }
  return pourAll(p+1);
}

bool solve() {
  sort(a, a+n, greater<int>());
  b[0] = true;
  for (int i=1; i<n; i++) {
    b[i] = false;
  }

  return pourAll(0);
}

int main() {
  bool ans;
  while (1) {
    cin >> n;
    if (!n) {
      break;
    }
    for (int i=0; i<n; i++) {
      cin >> a[i];
    }
    ans = solve();
    cout << (ans ? "YES" : "NO") << endl;
  }
  return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
using lint = long long int;

int main() {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;

    vector<lint> p(A), q(B), r(C);
    for_(i,0,A) cin >> p[i];
    for_(i,0,B) cin >> q[i];
    for_(i,0,C) cin >> r[i];
    
    using PLI = pair<lint, int>;
    priority_queue<PLI> que;
    for_(i,0,A) que.push(PLI(p[i], 0));
    for_(i,0,B) que.push(PLI(q[i], 1));
    for_(i,0,C) que.push(PLI(r[i], -1));

    lint ans = 0, cnt = 0, MAX_CNT = X + Y;
    while (cnt < MAX_CNT) {
        PLI p = que.top(); que.pop();

        if (p.second == 0 and X > 0) {
            ans += p.first;
            --X;
            ++cnt;
        }

        if (p.second == 1 and Y > 0) {
            ans += p.first;
            --Y;
            ++cnt;
        }

        if (p.second == -1) {
            ans += p.first;
            ++cnt;
        }
    }
    cout << ans << endl;
}

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

int main(){
  int n;
  while(cin >> n && n != -1){
    vector<int> res;
    int b = 4;
    if(n==0) {
      cout << 0 << endl;
      continue;
    }
    while(n > 0){
      res.push_back(n%4);
      n /= 4;
    }
    for(int i = 0; i < (int)res.size(); i++){
      cout << res[res.size() - 1 - i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)


//template functions
/////////////////////////
long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}
long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}
long GCM(long A,long B){
            long W,r;
    if(A<B){

        W=B;
        B=A;
        A=W;
    }
    while(A%B!=0){
        r=A%B;
        A=B;
        B=r;
    }
    return B;
}
long LCM(long A,long B){
    return (A*B)/GCM(A,B);
}

long upDiv(long a,long b){
  return (a+b-1)/b;
}

/////////////////////////


//Answer


int main() {

long N,count=0;
cin>>N;
vector<long> L(N);
for(long i=0;i<N;i++){
cin>>L.at(i);
}
for(long i=0;i<N;i++){
    for(long j=i+1;j<N;j++){
        for(long k=j+1;k<N;k++){
            if(L.at(i)!=L.at(j)&&L.at(i)!=L.at(k)&&L.at(k)!=L.at(j)&&L.at(i)+L.at(j)>L.at(k)&&L.at(i)+L.at(k)>L.at(j)&&L.at(k)+L.at(j)>L.at(i)){
                count++;
            }
        }
    }
}

cout<<count<<endl;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>



const int mod = 1000000007;

int main() {
	int N;
	scanf("%d", &N);
	if (N % 2 == 0) {
		printf("%d\n", N*(N - 2) / 2);
		for (int i = 1; i <= N; i++) {
			for (int j = i + 1; j <= N; j++) {
				if (j != N - i + 1) {
					printf("%d %d\n", i, j);
				}
			}
		}
	}
	else {
		printf("%d\n", (N - 1)*(N - 3) / 2 + (N - 1));
		for (int i = 1; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				if (j != N - i) {
					printf("%d %d\n", i, j);
				}
			}
			printf("%d %d\n", i, N);
		}
	}
}





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

int main() {
    int N;
    cin >> N;
    vector<int>A(N);
    for (int i = 0; i < N; ++i) {
      cin >> A[i];
    }
    int first = 0;
    int second = 1;
    if(A[first] < A[second]){
        first = 1;
        second = 0;
    }
    for (int i = 2; i < N; ++i) {
        if(A[i] >= A[first]){
            second = first;
            first = i;
        } else if(A[i] > A[second]){
            second = i;
        }
    }
    for (int i = 0; i < N; ++i) {
        if(i != first){
            cout << A[first] << "\n";
        }else{
            cout << A[second] << "\n";
        }
    }
    return 0;
}

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

int main() {
    int A, B, C, K, i, sum;
    cin >> A >> B >> C >> K;
  
    if ( K > A + B ) {
      sum = A * 1 + ( K - A - B ) * ( -1 );  
    } else if ( A > K ){
      sum = K * 1;
    } else {
      sum = A * 1;
    }
    cout << sum << endl;
    return 0;
}

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

using namespace std;
using ll = long long ;

#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)

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

    if((int)N.find("7") >= 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, const char * argv[])
{
    int h[10];
    int i,j,temp;
    char buf[10];
    
    for(i = 0; i < 10; i++){
        fgets(buf,10,stdin);
        buf[strlen(buf)-1] = '\0';
        h[i] = atoi(buf);
        //printf("%d\n",h[i]);
    }
    
    for(i = 0;i < sizeof(h) / sizeof(h[0]) - 1; i++){
        for(j = sizeof(h) / sizeof(h[0]) - 1; j > i; j--){
            if(h[j-1]> h[j]){
                temp = h[j];
                h[j] = h[j-1];
                h[j-1] = temp;
            }
        }
    }
    
//    for(i = 0; i < 10; i++){
//        printf("%d\n",h[i]);
//    }
    
    for(i = 0; i < 3 ;i++){
        printf("%d\n",h[sizeof(h) / sizeof(h[0]) -1 -i]);
    }
    return 0;
}

Measured memory_bytes: 528
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) c.begin(), c.end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

ll f(ll b, ll n){
    if (n < b) return n;
    return f(b, n/b) + n % b;
}

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

    for (ll b = 2; b * b <= n; b++){
        if (f(b, n) == s){
            cout << b << endl;
            return 0;
        }
    }

    ll ans = 1e18;
    for (ll x = 1; x * x <= n - s; x++){
        if ((n-s) % x != 0) continue;
        ll b = (n-s) / x + 1;
        if (x >= b) continue;
        ll y = s - x;
        if (y < 0 || y >= b) continue;
        ans = min(ans, b);
    }

    if (ans != 1e18){
        cout << ans << endl;
        return 0;
    }

    if (n == s) cout << n+1 << endl;
    else cout << -1 << endl;
    return 0;
}

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


int N;
int M;
std::vector<std::vector<int> > light;
std::vector<int> p;


bool check(int bit) {
    for (int i = 0; i < M; ++i) {
        int num = 0;
        for (auto l: light[i]) if ((bit & (1 << (l-1)))) ++num;

        if (num % 2 != p[i]) return false;
    }
    return true;
}


int count_num(int bit) {
    int num = 0;
    for (int i = 0; i < N; ++i) if (bit & (1 << i)) ++num;
    return num;
}


int main(){
    std::cin >> N >> M;
    light.resize(M);
    p.resize(M);
    for(int i = 0; i < M; ++i){
        int kosu;
        std::cin >> kosu;
        light[i].resize(kosu);
        for (int j = 0; j < kosu; ++j) std::cin >> light[i][j];
    }
    for (int i = 0; i < M; ++i) std::cin >> p[i];

    int hikaru = 0;
    for (int bit = 0; bit < (1 << N); ++bit) {
        if (check(bit)) ++hikaru;
    }

    std::cout << hikaru << std::endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def solve(A,B,C,D,E=3**30):
    # 大きさEの穴まで考慮
    if not E:
        return abs(A-C) + abs(B-D)
    a = A//E
    b = B//E
    c = C//E
    d = D//E
    if a != c and b != d:
        return abs(A-C) + abs(B-D)
    if a == c and b == d:
        return solve(A,B,C,D,E//3)
    if b == d and a != c:
        A,B = B,A
        a,b = b,a
        C,D = D,C
        c,d = d,c
    if a == c and b != d:
        if a % 3 != 1:
            return solve(A,B,C,D,E//3)
        if abs(b-d) == 1:
            return solve(A,B,C,D,E//3)
        if B > D:
            A,B,C,D = C,D,A,B
            a,b,c,d = c,d,a,b
        x1 = E * a - 1
        y1 = E * (b+1) - 1
        y2 = E * d
        dist1 = abs(x1-A) + abs(y1-B) + abs(y1-y2) + abs(x1-C) + abs(y2-D)
        x1 = E * (a+1)
        y1 = E * (b+1) - 1
        y2 = E * d
        dist2 = abs(x1-A) + abs(y1-B) + abs(y1-y2) + abs(x1-C) + abs(y2-D)
        return min(dist1, dist2)
 
solve(2,1,3,1)
 
N = int(readline())
m = map(int,read().split())
for A,B,C,D in zip(m,m,m,m):
    print(solve(A-1,B-1,C-1,D-1,3**30))

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

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> PP;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
//------------------------------------------------------------------------------------------------------------------------------


int main(void) {
    string S, T;
    cin >> S >> T;
    int sz = T.size();
    map<char, char> mp,mp2;
    for (int i = 0; i < sz; i++) {
        auto itr = mp.find(T[i]);
        if (itr == mp.end()) {
            mp[T[i]] = S[i];
        } 
        else if(mp[T[i]] != S[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = 0; i < sz; i++) {
        auto itr = mp2.find(S[i]);
        if (itr == mp2.end()) {
            mp2[S[i]] = T[i];
        } 
        else if(mp2[S[i]] != T[i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}

struct Acc {
  vector<lli> sum;
  Acc(vector<lli> v) {
    sum.push_back(0);
    each (i, v) {
      sum.push_back(sum.back() + i);
    }
  }
  lli query(lli begin, lli end) {
    return sum[end] - sum[begin];
  }
};

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m, q;
  while (cin >> n >> m >> q) {
    vector<lli> g[n];
    fill(g, g + n, vector<lli>(n));

    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      ++g[a][b];
    }

    vector<Acc> v;
    for (int i = 0; i < n; ++i) {
      v.push_back(Acc(g[i]));
    }

    while (q--) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      lli sum = 0;
      for (int i = a; i <= b; ++i) {
        sum += v[i].query(a, b + 1);
      }
      cout << sum << endl;
    }
  }
  
  return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

const ll mod = 998244353;
ll N, A, B, K;

long long ret, res, fact[333333], inv[333333], factinv[333333];
long long ncr(int n, int r) { return (n - r >= 0 && r >= 0) ? 1LL * fact[n] * factinv[r] % mod * factinv[n - r] % mod : 0; }

void init() {
	fact[0] = 1; for (int i = 1; i < 333333; i++) fact[i] = 1LL * fact[i - 1] * i % mod;
	inv[1] = 1; for (int i = 2; i < 333333; i++) inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
	factinv[0] = 1; for (int i = 1; i < 333333; i++) factinv[i] = 1LL * factinv[i - 1] * inv[i] % mod;
}

int main() {
   cin >> N >> A >> B >> K;
   init();

   ll ans = 0;
   for (int x = 0; x <= N; x++) {
      if ((K - A*x) % B != 0) continue;
      int y = (K - A*x) / B;
      if (y < 0 || y > N) continue;
      // if (x + y > N) continue;

      // debug2(x, y)
      ans += ((ncr(N, x)%mod) * (ncr(N, y)%mod))%mod;
      ans %= mod;
      // ans += ncr(N, y);
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 8192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            if('A'<= s[0] && s[0] <= 'Z') Console.Write("A");
            else if('a' <= s[0] && s[0] <= 'z') Console.Write("a");
        }
    }
}

Measured memory_bytes: 25612