akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	int ans = 0;
	cin >> s;
	if (s[0] == '1') ans++;
	if (s[1] == '1') ans++;
	if (s[2] == '1') ans++;
	cout << ans << "\n";

	return 0;
}



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

int main()
{
	int N, count = 0;
	string color[100];

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> color[i];
		if (color[i] == "Y") {
			cout << "Four" << endl;
			count++;
			break;
		}
	}
	if (count != 1) {
		cout << "Three" << endl;
	}
}

Measured memory_bytes: 256
from collections import deque
K = int(input())
que = deque()
que.extend([i for i in range(1,10)])

for k in range(K-1):
    out = que.popleft()
    div = out%10
    if div==0:
        que.extend([out*10,out*10+1])
    elif out%10==9:
        que.extend([out*10+8,out*10+9])
    else:
        que.extend([out*10-1+div,out*10+div,out*10+1+div])
print(que.popleft())

Measured memory_bytes: 70916
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int MOD;

template <class T>
vector<vector<T> > matrixProduct(const vector<vector<T> >& x, const vector<vector<T> >& y)
{
    int a = x.size();
    int b = x[0].size();
    int c = y[0].size();
    vector<vector<T> > z(a, vector<T>(c, 0));
    for(int i=0; i<a; ++i){
        for(int j=0; j<c; ++j){
            for(int k=0; k<b; ++k){
                z[i][j] += x[i][k] * y[k][j];
                z[i][j] %= MOD;
            }
        }
    }
    return z;
}

template <class T>
vector<vector<T> > matrixPower(const vector<vector<T> >& x, int k)
{
    int n = x.size();
    vector<vector<T> > y(n, vector<T>(n, 0));
    for(int i=0; i<n; ++i)
        y[i][i] = 1;

    vector<vector<T> > z = x;
    while(k > 0){
        if(k & 1)
            y = matrixProduct(y, z);
        z = matrixProduct(z, z);
        k >>= 1;
    }
    return y;
}

int main()
{
    for(;;){
        int n, a, b, c, t;
        cin >> n >> MOD >> a >> b >> c >> t;
        if(n == 0)
            return 0;

        vector<vector<int> > s(n, vector<int>(1));
        for(int i=0; i<n; ++i)
            cin >> s[i][0];

        vector<vector<int> > mat(n, vector<int>(n, 0));
        for(int i=0; i<n; ++i){
            mat[i][i] = b;
            if(i-1 >= 0)
                mat[i][i-1] = a;
            if(i+1 < n)
                mat[i][i+1] = c;
        }
        mat = matrixPower(mat, t);

        vector<vector<int> > ret = matrixProduct(mat, s);
        cout << ret[0][0];
        for(int i=1; i<n; ++i)
            cout << ' ' << ret[i][0];
        cout << endl;
    }
}

Measured memory_bytes: 1284
//
// Created by MengHaitao on 2019/11/27 0027.
//
//反向波兰语表示法
#include <iostream>
#include <string>
#include <stack>
#include <cstdlib>
#include <cstdio>
using namespace std;
stack<int> t;
int solve(string str) {
    int b = t.top();
    t.pop();
    int a = t.top();
    t.pop();
    if (str == "+")return a + b;
    else if (str == "-")return a - b;
    else if (str == "*")return a * b;
    else if (str == "/")return a / b;
}

int main() {
    string str;
    while (cin >> str) {
        if (str == "+" || str == "-" || str == "*" || str == "/")
            t.push(solve(str));
        else t.push(atoi(str.c_str()));
        if (getchar() == '\n') {
            cout << t.top() << endl;
            return 0;
        }
    }
}



Measured memory_bytes: 3160
#include <iostream>

using namespace std;

int main()
{
    int n;
    double amount, total = 0.0;
    cin >> n;
    string type;
    while (n--)
    {
        cin >> amount >> type;
        if (type == "BTC")
        {
            amount = (double)(amount * 380000.0);
        }
        total += double(amount);
    }
    cout << total;
    return 0;
}

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


int n; 
int x[10], y[10];

double dist(int i, int j) {
  double dx = x[i] - x[j];
  double dy = y[i] - y[j];
  return pow(dx*dx+dy*dy, 0.5);
}

int main() {
  cin >> n;
  rep(i,n) cin >> x[i] >> y[i];
  double sum = 0.0;
  vector<int>v(n);
  rep(i,n) v[i] = i;
  
  do {
  	rep(i,n-1) sum += dist(v[i], v[i+1]);
  }while(next_permutation(v.begin(), v.end()));
         
  int factorial = 1;       
  for(int i=1; i<=n; ++i) factorial *= i;
         
  cout << fixed << setprecision(10) << sum/factorial << endl;
         
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.reverse

sum_until_here = 0
ans_sum = 0
for i in range(n):
    ans_sum += a[i] * sum_until_here
    sum_until_here += a[i]
print(ans_sum % (1000000000 + 7))

Measured memory_bytes: 31448
import scala.io.StdIn

object Main extends App {

  val Array(n, k) = StdIn.readLine.split(" ").map(_.toInt)
  val seq = StdIn.readLine.split(" ").map(_.toInt)
    .groupBy(m => m).map(_._2.size).toArray.sorted
  val g = math.max(seq.size - k, 0)
  val ans = seq.take(g).sum
  
  println(ans)
}

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

int main() {
	int n,sw=0;
	cin >> n;
	int *arr = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	for (int i = 0; i < n-1; i++) {
		int minv = i;
		for (int j = i + 1; j < n; j++) {
			if (arr[j] < arr[minv]) {
				minv = j;
			}
		}
		if (minv != i) {
			swap(arr[minv], arr[i]);
			++sw;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << arr[i];
		if (i != n - 1)
			cout << ' ';
	}
	cout << endl << sw << endl;
	delete[] arr;
	return 0;
}


Measured memory_bytes: 3068
a=list(map(int,input().split()))

l=[]
l.append(abs(a[0]-a[1])+abs(a[1]-a[2]))
l.append(abs(a[1]-a[2])+abs(a[2]-a[0]))
l.append(abs(a[2]-a[0])+abs(a[0]-a[1]))
print(min(l))


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

int main(){
  int n,k;
  cin>>n>>k;
  
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  
  sort(a,a+n,greater<int>());
  int length=0;
  for(int i=0;i<k;i++){
    length+=a[i];
  }
  cout<<length<<endl;
}


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

int main()
{
   int a,b,c;
   cin>>a>>b>>c;
   if(a==b && a!=c)
   {
       cout<<c<<endl;
   }
   else if(a==c && a!=b)
   {
       cout<<b<<endl;
   }
   else if(b==c && b!=a)
   {
       cout<<a<<endl;
   }

     return 0;
}

Measured memory_bytes: 3464
n,a,b = map(int,input().split())

if a > b:
    print(0)
elif a == b:
    print(1)
elif a < b and n == 1:
    print(0)
elif a < b and n == 2:
    print(1)
elif (a < b) and n >= 3:
    print((b-a)*(n-2)+1)

Measured memory_bytes: 3060
import math

a,b,h,m = map(int,input().split())
zisin = (360/12)*h
zisin += 0.5*m
if zisin == 0:
    zisin = 360
hunsin = (360/60)*m
if hunsin == 0:
    hunsin = 360

if zisin == hunsin:
    print(abs(a-b))
    exit()
elif zisin > hunsin:
    cosa = zisin-hunsin
else:
    cosa = hunsin-zisin
# print(cosa)
ans = (a**2)+(b**2)-2*a*b*math.cos(math.radians(cosa))
# print(math.cos(cosa),math.radians(cosa),math.cos(math.radians(cosa)),ans)
ans = math.sqrt(ans)
print(ans)


Measured memory_bytes: 9524
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	double d,t,s;cin>>d>>t>>s;
	if (d / s <= t)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3744
n,m=gets.chomp.split(" ").map(&:to_i)
ab=[]
0.upto(n-1) do |i|
  ab.push(gets.chomp.split(" ").map(&:to_i))
end
ab.sort_by!(&:first)
count=0
while m>0
  kazu=ab[0][1]<m ? ab[0][1] : m
  count+=ab[0][0]*kazu
  ab.shift
  m-=kazu
end
puts count

Measured memory_bytes: 12664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define vi vector<int>
#define MAX_N 200005
#define i197 1000000007

using namespace std;


typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,P1> P2;
const int inf=1000000000;
P1 xy[MAX_N]={};

int main() {
	int n;
	ll x1,y1;
	cin>>n;
	rep(i,n){
		cin>>x1>>y1;
		if(x1>y1)swap(x1,y1);
		xy[i]=P1(x1,y1);
	}
	ll Rmax=0,Rmin=i197,Bmax=0,Bmin=i197;
	rep(i,n){
		if(xy[i].second>Rmax){
			Rmax=xy[i].second;
			Bmax=xy[i].first;
		}
		if(xy[i].first<Bmin){
			Bmin=xy[i].first;
			Rmin=xy[i].second;
		}
	}

	rep(i,n){
		if(xy[i].first>Bmax)Bmax=xy[i].first;
		if(xy[i].second<Rmin)Rmin=xy[i].second;
	}
	ll t=(Rmax-Rmin)*(Bmax-Bmin);

//	cout<<t<<endl;
	Rmax=0,Rmin=i197,Bmax=0,Bmin=i197;
	//RMax Rmin
	rep(i,n){
		if(xy[i].second>Rmax){
			Rmax=xy[i].second;
		}
		if(xy[i].first<Rmin){
			Rmin=xy[i].first;
		}
	}
	sort(xy,xy+n);
	Bmax=xy[n-1].first,Bmin=xy[0].first;
	ll Bmin2=Bmax,Bmax2=Bmax;
	ll Bmm=Bmax-Bmin;
//	cout<<Bmax<<" "<<Bmin<<endl;
	rep(i,n-1){
		ll k=xy[i].second;
		Bmin2=min(Bmin2,k);
		Bmax2=max(Bmax2,k);
		Bmm=min(Bmm,max(Bmax2,Bmax)-min(Bmin2,xy[i+1].first));
//		cout<<Bmm<<endl;
	}
	Bmm=min(Bmm,max(Bmax2,xy[n-1].second)-min(Bmin2,xy[n-1].second));

//	cout<<Bmax<<" "<<Bmin<<endl;

	t=min(t,(Rmax-Rmin)*Bmm);


	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 3328
using System;

namespace abc164_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int s,w;
            string[] token = Console.ReadLine().Split();
            s = Convert.ToInt32(token[0]);
            w = Convert.ToInt32(token[1]);
            if (w >= s)
            {
                Console.WriteLine("unsafe");
            }
            else
            {
                Console.WriteLine("safe");
            }
        }
    }
}


Measured memory_bytes: 17964
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
//partition sort
vector<int> a,b;

int partition(int p,int r){
    int x = a[r];
    int i = p-1;
    for(int j=p;j<=r-1;j++){
        if(a[j]<=x){
            i++;
            swap(a[i],a[j]);
        }
    }
    swap(a[i+1],a[r]);
    b = a;
    return i+1;
}

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

    a.resize(n+1);
    rep(i,n) cin >> a[i+1];
    int q = partition(1,n);
    rep(i,n-1){
        if(i+1!=q) cout << a[i+1] << " ";
        else cout << "[" << a[i+1] << "]" << " ";
    }

    cout << a[n] << endl;
    return 0;
}



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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, a, b, c, d, e, k);
  if (e - a > k) {
    out(":(");
  } else {
    out("Yay!");
  }
}


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

int main() {
	int N;
	cin >> N;
	vector<vector<int>>MAXs(N, vector<int>(3));
	cin >> MAXs[0][0] >> MAXs[0][1] >> MAXs[0][2];
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			int a;
			cin >> a;
			MAXs[i][j] = max(MAXs[i - 1][(j + 1) % 3], MAXs[i - 1][(j + 2) % 3]) + a;
		}
	}
	cout << max({ MAXs[N - 1][0],MAXs[N - 1][1] ,MAXs[N - 1][2] }) << endl;
}


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

int main(){

    int n;
    cin>> n;

    ll ans=1;
    ll mo=1e+9+7;

    for(int i=1;i<=n;i++){
        ans*=i;
        ans%=mo;
    }

    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
// #define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

int solve(){
	int n;
	cin>>n;
	int ans = 0;
	vi v[n],g[n];
	for (int i = 0; i < n; ++i)
	{
		int k,l,r;
		cin>>k>>l>>r;
		k--;
		if(l >= r){
			ans += r;
			v[k].emplace_back(l-r);
		}
		else{
			ans += l;
			if(n-k-2 >= 0) g[n-k-2].emplace_back(r-l);
		}
	}
	multiset<int>s;
	for (int i = 0; i < n; ++i)
	{
		for(const auto it:v[i]){
			s.insert(it);
		}
		while(s.size() > (i+1)){
			s.erase(s.begin());
		}
	}
	for(auto it:s) ans += it;
	// show(ans);
	s.clear();
	for (int i = 0; i < n; ++i)
	{
		for(const auto it:g[i]){
			s.insert(it);
		}
		while(s.size() > (i+1)){
			s.erase(s.begin());
		}
	}
	for(auto it:s) ans += it;
	return ans;
}

int32_t main(){
    fast_io;
    int t;
    cin>>t;
    while(t--){
    	show(solve());
    }
    return 0;
}

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

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

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;



int main() {
  int a,b,c;
  cin >>a>>b>>c;
  if(a==b) cout <<c<<endl;
  if(b==c) cout <<a<<endl;
  if(a==c) cout <<b<<endl;
  
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<int,int> pi;
typedef pair<int,pi> pii;
typedef vector<pi> vpi;
typedef set<int> si;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define f first
#define s second
ll INF = 1e15;
ll MOD = 1e9;
#define lb lower_bound
#define ub upper_bound
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),x.end()

int N,M,a,b;
string S;
vi aList[200100];
int R[200100][2];
vi V;
int cnt;
stack<int> stk;

int main(){
  // freopen("input.txt","r",stdin);
  cin>>N>>M;
  cin >> S;
  for (auto i : S){
    if (i == 'A')V.pb(0);
    else V.pb(1);
  }
  for (int i=0;i<M;++i){
    cin>>a>>b;
    --a;--b;
    aList[a].pb(b);
    aList[b].pb(a);
    R[a][V[b]]++;
    R[b][V[a]]++;
  }
  for (int i=0;i<N;++i){
    if (R[i][0] == 0 || R[i][1] ==  0){
      stk.push(i);
    }else{
      ++cnt;
    } 
  }
  while(SZ(stk)){
    int x = stk.top(); stk.pop();
    // cout<<"Top " << x<<'\n';
    for (auto i : aList[x]){
      if (R[i][0] == 0 || R[i][1] == 0)continue;
      R[i][V[x]]--;
      if (R[i][V[x]] == 0){
        stk.push(i);
        --cnt;
      }
    }
  }
  // cout<<cnt<<'\n';
  if (cnt)cout<<"Yes";
  else cout << "No";
}


Measured memory_bytes: 15220
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
max_a = max(a for a, b in ab)
dp = [0]*(H+max_a)
for i in range(1, H+max_a):
    dp[i] = min(dp[i-a]+b for a, b in ab)
print(dp[H])

Measured memory_bytes: 3784
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;

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

int main(int argc, const char * argv[]) {
    
    ll N;
    cin >> N;
    vector<ll> data = vector<ll>(N, 0);
    vector<ll> result = vector<ll>(N, 0);
    vector<ll> output = vector<ll>();
    ll count = 0;
    for (ll i = 0; i < N; i++) {
        cin >> data[i];
    }
    for (ll i = N - 1; i >= 0; i--) {
        // check current mod
        ll mod = 0;
        for (ll j = i; j < N; j += (i + 1)) {
            mod += result[j];
        }
        if ((mod & 1) != data[i]) {
            result[i] = 1;
            output.push_back(i + 1);
            count++;
        }
    }
    
    cout << count << endl;
    for (ll i = 0; i < count; i++) {
        cout << output[i];
        if (i != count - 1) {
            cout << " ";
        }
    }
    
    return 0;
}

Measured memory_bytes: 4980
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

#define dump(a) (cerr << (#a) << " = " << (a) << endl)

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << '(' << p.first << ", " << p.second << ')';
	return os;
}

template<class Tuple, unsigned Index>
void print_tuple(ostream& os, const Tuple& t) {}

template<class Tuple, unsigned Index, class Type, class... Types>
void print_tuple(ostream& os, const Tuple& t) {
	if(Index > 0) os << ", ";
	os << get<Index>(t);
	print_tuple<Tuple, Index + 1, Types...>(os, t);
}

template<class... Types>
ostream& operator<<(ostream& os, const tuple<Types...>& t) {
	os << '(';
	print_tuple<tuple<Types...>, 0, Types...>(os, t);
	return os << ')';
}

template<class Iterator>
ostream& dump_range(ostream&, Iterator, const Iterator&);

template<typename T>
ostream& operator<<(ostream& os, vector<T> c) {
	return dump_range(os, c.cbegin(), c.cend());
}

template<class Iterator>
ostream& dump_range(ostream& os, Iterator first, const Iterator& last) {
	os << '[';
	for(int i = 0; first != last; ++i, ++first) {
		if(i) os << ", ";
		os << *first;
	}
	return os << ']';
}

int ans;
int n, m;
vector<int> cover;
int used;
vector<vector<int>> edges;

void update(int value) {
	if(used == (1 << n) - 1) {
		ans = value;
	}
}

void dfs(int idx, int sum) {
	if(sum >= ans) return;

	if(idx == n) {
		update(sum);
	}
	else {
		dfs(idx + 1, sum);

		int tmp = used;
		used |= cover[idx];
		dfs(idx + 1, sum + 1);
		swap(used, tmp);
	}
}

int solve() {
	cover.assign(n, 0);
	for(int i = 0; i < n; ++i) {
		cover[i] |= (1 << i);
		for(int j = 0; j < static_cast<int>(edges[i].size()); ++j) {
			cover[i] |= (1 << edges[i][j]);
		}
	}

	used = 0;
	int cnt = 0;
	for(int i = 0; i < n; ++i) {
		if(edges[i].size() == 0) {
			used |= (1 << i);
			++cnt;
		}
	}

	ans = n;
	dfs(0, cnt);
	return ans;
}

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

	while(cin >> n >> m && n) {
		edges.assign(n, vector<int>());
		for(int i = 0; i < m; ++i) {
			int a, b;
			cin >> a >> b;
			edges[a].emplace_back(b);
			edges[b].emplace_back(a);
		}

		cout << solve() << endl;
	}

	return EXIT_SUCCESS;
}

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

int main(){
    ll N, K;
    cin >> N >> K;

    ll ans = 0;
    rep(b, K+1, N+1){
        ll kiri = (N+1)/b;
        ans += (b-K)*kiri;
        ll rem = N - K - (kiri)*b;
        ans += max(0LL, rem+1LL);
    }

    if(K==0) ans = N*N;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math
n = int(input())
nn = int(math.sqrt(n))
li = []
count = 0
for i in range(1,nn+1):
    if n % i == 0:
        li.append(i-1)
        li.append(n//i-1)
for i in li:
    if i == 0:
        continue
    if n % i == n // i:
        count += i
print(count)

Measured memory_bytes: 3272
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    int n;
    cin >> n;
    bool four = false;
    rep(i, n)
    {
        char a;
        cin >> a;
        if (a == 'Y')
        {
            four = true;
        }
    }
    if (four)
    {
        cout << "Four" << endl;
    }
    else
    {
        cout << "Three" << endl;
    }
}

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

int main()
{
	int a, b;
	cin >> a >> b;
	string hu, re;
	int ans = 0;
	for (int i = a; i <= b; ++i)
	{
		hu = re = to_string(i);
		reverse(re.begin(), re.end());
		ans += (hu == re);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def bisect(lst, isok, ok, ng):
    while(abs(ok-ng)>1):
        mid = (ok+ng)//2
        if isok(lst[mid]):
            ok = mid
        else:
            ng = mid
    return [ok, ng]

n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

a.sort()
b.sort()
c.sort()

ans = 0

for i in b:
    x = bisect(a, lambda x:x < i, -1, n)[0]
    y = bisect(c, lambda x:x > i, n, -1)[0]
    ans += (x+1)*(n-y)

print(ans)

Measured memory_bytes: 23296
#include <iostream>
#include <map>
#include <deque>
#include <string>

using namespace std;

int main(void){
	string str;
	
	while(cin >> str && str != "0"){
		int ret = -1;
		map<string,bool> m;
		deque<pair<string,int> > q;
		string curstr,tmpstr;
		int curtime;
		
		q.push_back(make_pair(str,0));
		m[str] = true;
		while(!q.empty()){
			curstr = q.front().first;
			curtime = q.front().second;
			q.pop_front();
			
			//cout << curstr << endl;
			
			bool isended = true;
			
			for(int i=0;i<curstr.size()-1;i++){
				if(curstr[i] != curstr[i+1]) isended = false;
			}
			
			if(isended){
				ret = curtime;
				break;
			}
			
			tmpstr = curstr;
			
			for(int i=0;i<curstr.size()-1;i++){
				if((tmpstr[i] == 'b' && tmpstr[i+1] == 'g') ||
				(tmpstr[i] == 'g' && tmpstr[i+1] == 'b')){
					tmpstr[i] = 'r'; tmpstr[i+1] = 'r';
					//cout << tmpstr << endl;
					if(m[tmpstr] == false){
						m[tmpstr] = true;
						q.push_back(make_pair(tmpstr, curtime+1));
					}
					tmpstr = curstr;
				}else if((tmpstr[i] == 'r' && tmpstr[i+1] == 'g') ||
				(tmpstr[i] == 'g' && tmpstr[i+1] == 'r')){
					tmpstr[i] = 'b'; tmpstr[i+1] = 'b';
					if(m[tmpstr] == false){
						m[tmpstr] = true;
						q.push_back(make_pair(tmpstr, curtime+1));
					}
					tmpstr = curstr;
				}else if((tmpstr[i] == 'b' && tmpstr[i+1] == 'r') ||
				(tmpstr[i] == 'r' && tmpstr[i+1] == 'b')){
					tmpstr[i] = 'g'; tmpstr[i+1] = 'g';
					if(m[tmpstr] == false){
						m[tmpstr] = true;
						q.push_back(make_pair(tmpstr, curtime+1));
					}
					tmpstr = curstr;
				}
			}
		}
		if(ret == -1){
			cout << "NA" << endl;
		}else{
			cout << ret << endl;
		}
	}
}

Measured memory_bytes: 1880
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"



int main() {
	int N; cin >> N;
	for (int i = 0; i < N; ++i) {
		int a, b; cin >> a >> b;
		vector<int>anss;
		if (a < b) {
			for (int j = a; j <= b; ++j) {
				anss.emplace_back(j);
			}
		}
		else if (a == b) {
			anss.emplace_back(a);
		}
		else {
			if (a <=5) {
				for (int j = a; j >= b; --j) {
					anss.emplace_back(j);
				}
			}
			else {
				if (b <= 5) {

					for (int j = a; j <= 9; ++j) {
						anss.emplace_back(j);
					}
					for (int j = 5; j >= b; --j) {
						anss.emplace_back(j);
					}
				}
				else {
					for (int j = a; j <= 9; ++j) {
						anss.emplace_back(j);
					}
					for (int j = 5; j >= 0; --j) {
						anss.emplace_back(j);
					}
					for (int j = 1; j <= b; ++j) {
						anss.emplace_back(j);
					}
				}
			}
		}
		for (int i = 0; i < anss.size(); ++i) {
			cout << anss[i];
			if (i == anss.size() - 1)cout << endl;
			else cout << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 2980
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
static int dsum(int x)
{
	int sum = 0;
	while (x > 0){
		sum += x % 10;
		x /= 10;
	}
	return sum;
}
int main(void)
{
	int n, a, b;
	int i, j;
	int s = 0, d;
	scanf("%d%d%d", &n, &a, &b);

	for (i = 1; i <= n; ++i){
		d = dsum(i);
		if (a <= d&&d <= b){
			s += i;
		}
	}
	printf("%d\n", s);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

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

using namespace std;

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

    int syogen[n][n][2];
    int syogensuu[n];
    
    // input
    for (int i = 0; i < n; i++)
    {
        int a; cin >> a;
        syogensuu[i] = a;
        for (int j = 0; j < a; j++)
        {
            int x, y; cin >> x >> y; 
            syogen[i][j][0] = x;
            syogen[i][j][1] = y;
        }
    }

    //cout << "---" << endl;
    
    int ans = 0;
    int count;
    int who;
    int which; 
    bool check = true;
    for (int i = 0; i < pow(2, n); i++)
    {
        count = 0;

        int bit[n];
        for (int j = 0; j < n; j++)
        {
            if (((i >> ((n-1)-j)) & 1) == 1)
            {
                bit[j] = 1;
            }
            else
            {
                bit[j] = 0;
            }
        }
        /*
        for (int j = 0; j < n; j++)
        {
            cout << bit[j] << " ";
        }
        cout << endl;
        */

        for (int j = 0; j < n; j++)
        {
            check = true;
            if (bit[j] == 1)
            {
                for (int k = 0; k < syogensuu[j]; k++)
                { 
                    
                    who = syogen[j][k][0] - 1;
                    which = syogen[j][k][1];
                    if (bit[who] != which)
                    {
                        count = 0;
                        goto fin;
                    }
                }
                count++;
            }
        }
fin:
        if (ans < count)
        {
            ans = count;
        }

        //cout << count << endl;
        //cout << "---" << endl;
        
    }
    cout << ans << endl;
}


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


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	
	int cnt = 0;
	while (1) {
		int x; cin >> x;

		if (x ==0)break;

		cout << "Case " << ++cnt << ": " << x << endl;
	}
	return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
#define SZ(x) ((int)(x).size())
using namespace std;
typedef pair<int,int> PII;
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define REP(i,n) for (int i = 0; i < n; ++i)
#define FOR(i,a,b) for (int i = a; i <= b; ++i)
#define M 1000000007
#define MM 998244353
#define SZ(a) int((a).size())
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define mod 1000000007
using ll = long long;

//a and b are assumed to be taken modulo p
inline ll add(ll a, ll b, ll p = mod){ ll c = a + b; if(c >= p) c -= p; return c; }
inline ll sub(ll a, ll b, ll p = mod){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll mul(ll a, ll b, ll p = mod){ return (a * 1ll * b) % p; }
 
using VI = vector<int>;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
using VLL = vector<ll>;
using ld = long double;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;     // Initialize result
  
    x = x % p; // Update x if it is more than or
                // equal to p
  
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
  
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*1ll*x) % p;
    }
    return res;
}
const int MX = 2e5+10;
const int MX2 = 1e6+5;

ll INF= 4 * (ll)1e18;
int mx = 2 * (ll)1e9 + 10;
ll A[MX];
ll wt[120];
ll val[120];
ll ans = 0;
vector<ll> fre[5];
int sz[5];
ll getWt[5];
int main(int argc, const char * argv[]) {

    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0); // insert code here...
    int N;
    ll W;
    cin >> N >> W;
    ll mnWt = 2e9;
    FOR(i,1,N) {
        cin >> wt[i] >> val[i];
        mnWt = min(mnWt,wt[i]);
    }
    FOR(i,1,N) {
        getWt[wt[i] - mnWt + 1] = wt[i];
        wt[i] = wt[i] - mnWt + 1;
        fre[wt[i]].PB(val[i]);
    }
    FOR(i,1,4) {
        sort(fre[i].begin(),fre[i].end(),greater<ll>());
        sz[i] = SZ(fre[i]);
        FOR(j,1,sz[i] - 1) {
            fre[i][j] = fre[i][j-1] + fre[i][j];
        }
    }
    for (ll i = 0; i <= sz[1]; i++) {
        for (ll j = 0;j  <= sz[2]; j++) {
            for (ll k = 0; k <= sz[3]; k++) {
                for (ll l = 0; l <= sz[4]; l++) {
                    if (i * getWt[1] + j * getWt[2] + k * getWt[3] + l * getWt[4] <= W) {
                        ans = max(ans,(i>0?fre[1][i - 1]:0) + (j > 0?fre[2][j - 1]:0) + (k > 0?fre[3][k - 1]:0) + (l > 0?fre[4][l - 1]:0));
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
    
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>

using namespace std ;

const int N=1e6+10 ;

struct Edge { int to , nxt ; };
Edge e[N<<1] ;
int lst[N] ;
inline void add ( int u , int v )
{
	static int cnt=0 ;
	e[++cnt]=(Edge){v,lst[u]},lst[u]=cnt,
	e[++cnt]=(Edge){u,lst[v]},lst[v]=cnt;
}

int dfn[N] , low[N] , DFN ;
inline void dfs ( int x , int f )
{
	int i , y ;
	dfn[x]=++DFN;
	for ( i=lst[x],y=e[i].to ; i ; i=e[i].nxt,y=e[i].to )
		if ( y^f ) dfs(y,x);
	low[x]=DFN;
}

int a[N] ;
int n , m ;
int main ()
{
	int i , u , v ;
	scanf("%d%d",&n,&m);
	for ( i=1 ; i<n ; i++ ) scanf("%d%d",&u,&v),add(u,v);
	dfs(1,0);
	while ( m-- ) scanf("%d%d",&u,&v),a[dfn[u]]+=v,a[low[u]+1]-=v;
	for ( i=1 ; i<=n ; i++ ) a[i]+=a[i-1];
	for ( i=1 ; i<=n ; i++ ) printf("%d ",a[dfn[i]]);
	return 0 ;
}


Measured memory_bytes: 26368
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=100,V_I=1000;
int n,m;
int v[N+1],w[N+1];
int dp[N*V_I+1];
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>w[i]>>v[i];
	memset(dp,0x3f,sizeof(dp));
	dp[0]=0;
	for(int i=1;i<=n;i++)for(int j=N*V_I;j>=v[i];j--)
		dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
	for(int i=N*V_I;;i--)if(dp[i]<=m)return cout<<i,0;
	return 0;
}
/*1
3 8
3 30
4 50
5 60
*/
/*2
1 1000000000
1000000000 10
*/
/*3
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/

Measured memory_bytes: 1024
import sys
import numpy as np


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    N = int(input())
    H = [0] + list(map(int, input().split()))
    INF = 10 ** 9
    dp = [INF for _ in range(N + 1)]
    dp[1] = 0
    dp[2] = abs(H[2] - H[1])
    for i in range(2, N + 1):
        tmp1 = dp[i - 1] + abs(H[i] - H[i - 1])
        tmp2 = dp[i - 2] + abs(H[i] - H[i - 2])
        dp[i] = min(tmp1, tmp2)
    print(dp[-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 22748
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>

using namespace std;

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

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
    i64 from, to, cost;
    edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
    edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}
//

#pragma endregion

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

vector< int64_t > divisor(int64_t n) {
    vector< int64_t > ret;
    for (int64_t i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

int main() {
    i64 n, m;
    cin >> n >> m;
    vector<i64> l(m);
    for(int i = 0; i < n; ++i){
        i64 k;
        cin >> k;
        for(int j = 0; j < k; ++j){
            i64 a;
            cin >> a;
            --a;
            l[a]++;
        }
    }
    i64 ans = 0;
    for(int i = 0; i < m; ++i) if(l[i] == n) ++ans;
    cout << ans << endl;
}

// n = am + b (a == b)
// n = a(m + 1) 1, 2, 4, 8


Measured memory_bytes: 256
S=input()

word="A"
word=word[:-1]
num=len(S)
for i in range(num):        
    if S[i]=="0":
        word+=str(0)
    elif S[i]=="1":
        word+=str(1)
    else:
        if len(word)!=0:
           word=word[:-1]
        else:
            word=word
    

print(word)    

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int n,m;
int a[100010];

int main(){
	cin >> n;
	repp(i,0,n){
		cin >> a[i];
		m = max(m,a[i]);
	}
	int p = -1;
	repp(i,0,n) if(a[i] != m && abs(m-2*a[i]) < abs(m-2*p)) p = a[i];
	cout << m << ' ' << p << endl;
	return 0;
}


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


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

    int n; cin >> n;
    vector<int> f(60001,0);
    for(int x = 1; x <= 100; ++x){
        for(int y = 1; y <= 100; ++y){
            for(int z = 1; z <= 100; ++z){
                ++f[x*x+y*y+z*z + x*y + y*z + z*x];
            }
        }
    }
    rep(i,n) cout << f[i+1] << "\n";
}

Measured memory_bytes: 3576
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
	public static void main (String[] args) throws java.lang.Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
	    while(!"0 0 0".equals(line)){
	        String[] lines = line.split(" ");
            List<Integer> list = new ArrayList<Integer>();
            list.add(Integer.parseInt(lines[0]));
            list.add(Integer.parseInt(lines[1]));
            list.add(Integer.parseInt(lines[2]));
            Collections.sort(list);
	        int mid = (int)list.get(list.size()/2);
	        int min = (int)list.get(0);
	        int size = (int)Math.sqrt(mid*mid+min*min);
	        int n = Integer.parseInt(br.readLine());
	        for(int i=0;i<n;i++){
	            int a = Integer.parseInt(br.readLine());
	            if(a*2>size){
	                System.out.println("OK");
	            }else{
	                System.out.println("NA");
	            }
	        }
	        
	        line = br.readLine();
	    }
    }
}

Measured memory_bytes: 24240
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N , M;
vector<int> Swtch;
vector<int> P;
void input(){
    fast_io();
    cin >> N >> M;
    for (size_t i = 0; i < M; i++)
    {
        int k; cin >> k;
        int bit = 0;
        for (size_t j = 0; j < k; j++)
        {
            int s; cin >> s;
            s--;
            bit |= (1<<s);
        }
        Swtch.push_back(bit);        
    }
    for (size_t i = 0; i < M; i++)
    {
        int p; cin >> p;
        P.push_back(p);
    }
}

bool ison(int bit){
    for (size_t i = 0; i < M; i++)
    {
        if(__builtin_popcount(bit&Swtch[i])%2==P[i]) continue;
        return false;
    }
    return true;    
}

int solve(){
    int ans = 0;
    for (int bit = 0; bit < 1<<N; bit++)
    {
        ans += ison(bit);
    }
    cout << ans << endl;    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#define MAX 20

using namespace std;

typedef long long ll;

int main(){
  int N,M,T = 1;

  while(cin >> N >> M , N | M){
    ll cnt = 0;
    vector<int> res(M+1,0);
    res[0] = N;

    while(true){
      vector<int> tmp(M+1,0);

      if(res[M]) break;  
      cnt++;      

      for(int i = 0 ; i < M ; i++){
	if(res[i] >= 2){
	  tmp[i+1] += res[i] / 2;
	  tmp[0] += res[i] / 2;
	  if(res[i] % 2) tmp[i]++;
	}
	else
	  tmp[i] += res[i];
      }

      res = tmp;
    }

    cout << "Case " << T++ << ": ";
    cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>
#include<assert.h>
#include<vector>
#include<string.h>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<string>
#include<iostream>
#include<set>
#include<unordered_set>
#include<map>
#include<queue>
#include<functional>
#include<list>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 200005;
const int MM = 1000000007;

struct UF{
	int t[MX], c[MX];
	void clear(){
		for(int i = 0; i < MX; i++) t[i] = i, c[i] = 1;
	}
	int find(int a){ return t[a] == a ? a : t[a] = find(t[a]); }
	int merge(int a, int b){
		a = find(a), b = find(b);
		t[a] = b, c[b] += c[a];
	}
} uf;

int D[MX], E[MX];
int N;

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", D+i), E[i] = i;
	sort(E+1, E+N+1, [](int l, int r){ return D[l] > D[r]; });
	uf.clear();
	ll ans = 0;
	for(int i = 1; i <= N; i++){
		int c = E[i];
		int a = 1, b = 1;
		if( c >= 2 && D[c-1] > D[c] ) a += uf.c[uf.find(c-1)], uf.merge(c, c-1);
		if( c < N && D[c+1] > D[c] ) b += uf.c[uf.find(c+1)], uf.merge(c, c+1);
		ans += (ll)a * b * D[c];
	}
	printf("%lld\n", ans);
}



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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  VLL h(n);
  rep(i, n) cin >> h[i];
  sort(all(h));
  ll ans = 1e10;
  rep(i, n - k + 1) { chmin(ans, h[i + k - 1] - h[i]); }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int> > Matrix;
const int MOD = 1e9+7;
const int INF =1000000;


int main() {
int n; cin>>n;
string s; cin>>s;
ll res=0;
bool kazu[10][10][10];
REP(i,10)REP(j,10)REP(k,10)kazu[i][j][k]=0;

REP(i,10){
  REP(j,10){
    REP(k,10){
      string v=to_string(i)+to_string(j)+to_string(k);
      bool flag1=0,flag2=0,flag3=0;
      REP(l,n){
        if(flag1==0&&v[0]==s[l])flag1=1;
        else if(flag1==1&&flag2==0&&v[1]==s[l])flag2=1;
        else if(flag2==1&&flag3==0&&v[2]==s[l])flag3=1;
        
      }
      if(flag3==1){
        res++;
        
      }
    }
  }
}

 cout<<res<<endl;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
g = [[] for i in range(n)]
for i in range(m):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append((b, -c))
        
dist = [float('inf') for i in range(n)]
dist[0] = 0
prev = [-1 for i in range(n)]
negative_cycle = False
for k in range(n):
    for i in range(n):
        for dst, cst in g[i]:
            src = i
            if dist[dst] > dist[src] + cst:
                dist[dst] = dist[src] + cst
                prev[dst] = src
                if k == n-1 and dst == n-1:
                    dist[dst] = -float('inf')
                    negative_cycle = True

if negative_cycle:
    print('inf')
else:
    print(-dist[n-1])


Measured memory_bytes: 3444
#%%code
def resolve():
    N=int(input())
    S=input()
    ans=""
    for i in S:
        t=(ord(i)+N)
        if t>=ord("["):
            t-=ord("Z")-ord("A")+1
            
        ans+=chr(t)
    print(ans)

#%%submit! 
resolve()

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
ll ans = 0LL;
int i_index;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];
int main(){
    int a[3];
    int tmp = 0;
    rep(i, 3) cin >> a[i];
    sort(a, a + 3);
    tmp = abs(a[0] - a[1]) + abs(a[1] - a[2]);
    cout << tmp << endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

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

const ll LARGE = (ll)1e10;

int main(void)
{
	int n;
	cin >> n;
	vector<ll> as(n, 0);
	rep(i, n) {
		cin >> as[i];
		as[i] = -as[i];
	}
	set<pair<ll, ll>> s;
	s.insert(make_pair(as[0], 0));
	for (int i = 1; i < n; i++) {
		auto p = s.upper_bound(make_pair(as[i], LARGE));
		if (p == s.end()) {
			s.insert(make_pair(as[i], s.size()));
		}
		else {
			auto id = p->second;
			s.erase(p);
			s.insert(make_pair(as[i], id));
		}
	}
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 7296