akhauriyash/Code-Regression huggingface dataset:
/*
 * A.cpp
 *
 *  Created on: 2017/05/06
 *      Author: jln
 */
#define MYDEBUG
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <queue>
#include <stack>

#ifdef MYDEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define all(x) x.begin(), x.end()
#define umap unordered_map
using namespace std;

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
	out << "[";
	size_t last = v.size() - 1;
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i];
		if (i != last)
			out << ",";
	}
	out << "]";
	return out;
}
const int maxm = 10001;
const int maxt = 1261;
int N, M;
int r;
int q;
int tl[maxm][maxt];
void solve() {
	while (cin >> N >> M, (N || M)) {
		cin >> r;
		vector<stack<int> > stu(M + 1); //????????°????????????????????¨???
		for (int i = 0; i < maxm; ++i) {
			for (int j = 0; j < maxt; ++j) {
				tl[i][j] = 0;
			}
		}

		for (int i = 0; i < M + 1; ++i) { //init
			stu[i] = stack<int>();
		}

		for (int i = 0; i < r; ++i) { //?????°??°, input
			int t, n, m, s;
			cin >> t >> n >> m >> s;
			if (s == 0) { //pop
				if (stu[m].empty()) {
					debug("stack is empty!");
					return;
				}
				int ts = stu[m].top();
				int te = t;
				stu[m].pop();
				if (stu[m].empty()) {
					for (int time = ts; time <= te; ++time) { //?????£?????¨????????????ON
						tl[m][time] = 1;
					}
				}
			} else { //push
				stu[m].push(t);
			}
		}

		cin >> q;
		for (int j = 0; j < q; ++j) { //?????¨?????°, output
			int ts, te, m;
			cin >> ts >> te >> m;
			int ans = 0;
			//for (int t = ts; t <= te; ++t) {
			//	printf("%3d ", t);
			//}
			//cout << endl;
			int cnt = 0, past = 0;
			for (int t = ts; t <= te; ++t) {
				if (past == 1 && tl[m][t] == 0)
					cnt++;
				past = tl[m][t];
				//printf("%3d ", tl[m][t]);
				ans += tl[m][t];
			}
			//cout << endl;
			cout << ans - cnt - tl[m][te] << endl;
		}
	}
}

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

Measured memory_bytes: 58580
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

alias Edge = Tuple!(int, "to", int, "cost");
immutable inf = 10^^9 + 7;

void main() {
    int n, m, s;
    scan(n, m, s);

    auto adj = new Edge[][](n, 0);

    foreach (i ; 0 .. m) {
        int a, b, c;
        scan(a, b, c);
        adj[a] ~= Edge(b, c);
    }

    auto dist = dijkstra(adj, s);

    foreach (i ; 0 .. n) {
        if (dist[i] == inf) {
            writeln("INF");
        }
        else {
            writeln(dist[i]);
        }
    }
}

auto dijkstra(Edge[][] adj, int s) {
    alias Pair = Tuple!(int, "num", int, "dist");
    immutable inf = 10^^9 + 7;

    int N = adj.length.to!int;

    auto dist = new int[](N);
    dist[] = inf;
    dist[s] = 0;

    auto q = BinaryHeap!(Array!Pair, "a.dist > b.dist")();
    q.insert(Pair(s, 0));

    int rep = N - 1;

    while (!q.empty && rep) {
        auto v = q.front;
        q.popFront();

        if (dist[v.num] < v.dist) continue;

        rep--;

        foreach (e ; adj[v.num]) {
            if (dist[e.to] > dist[v.num] + e.cost) {
                dist[e.to] = dist[v.num] + e.cost;
                q.insert(Pair(e.to, dist[e.to]));
            }
        }
    }

    return dist;
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}



struct Queue(T) {
    private {
        int N, head, tail;
        T[] data;
    }

    this(int n) {
        N = n + 1;
        data = new T[](N);
    }

    bool empty() {
        return head == tail;
    }

    bool full() {
        return (tail + 1) % N == head;
    }

    T front() {
        return data[head];
    }

    void push(T x) {
        assert(!full);
        data[tail++] = x;
        tail %= N;
    }

    void pop() {
        assert(!empty);
        head = (head + 1) % N;
    }

    void clear() {
        head = tail = 0;
    }
}

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

typedef pair<string, string> pss;
map<pss, int> mp;


long long ans, n;
string s;
int main() {
	cin >>n >> s;
	int mid = (int)s.size() / 2, mid2 = (int)s.size() - mid;
	for (int i = 0; i < (1<<mid); i++) {
		string s1, t1;
		for (int j = 0; j < mid; j++) {
			if ((i>>j) & 1) 
				s1 += s[j];
			else 
				t1 += s[j];
		}
		reverse(t1.begin(), t1.end());
		mp[pss(s1, t1)]++;
	}
	for (int i = 0; i < (1<<mid2); i++) {
		string s1, t1;
		for (int j = 0; j < mid2; j++) {
			if ((i>>j) & 1) 
				s1 += s[j+mid];
			else 
				t1 += s[j+mid];
		}
		reverse(s1.begin(), s1.end());
		ans += mp[pss(s1, t1)];
		
	}
	cout << ans;
}

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

          using namespace std;
          typedef long long ll;
          ll s;
          int n;
int itr[535];
          int main()
          {
            cin >> n;
            for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
            for(int q = 1; q <= n; q++)
              s += __gcd(i, __gcd(j, q));
            cout << s;  
          }

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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(){
	int h,w,d,q;
	cin >> h >> w >> d;
	vector<pair<int,int>> a(h*w);
	REP(i,h) REP(j,w){
		int in;
		cin >> in;
		a[in-1].first = i;
		a[in-1].second = j;
	}
	
	vector<ll> cost(h*w);
	for(int i=0; i<h*w; i++){
		if(i<d){
			cost[i] = 0;
			continue;
		}
		cost[i] = cost[i-d];
		cost[i] += abs(a[i].first-a[i-d].first) + abs(a[i].second-a[i-d].second);
	}
	
	vector<ll> ans;
	cin >> q;
	REP(i,q){
		int l,r;
		cin >> l >> r;
		ans.push_back(cost[r-1]-cost[l-1]);
	}
	
	REP(i,q) cout << ans[i] << endl;
		
	return 0;
}

Measured memory_bytes: 5724
N=int(input())
A=[int(x) for x in input().split()]
F=0

n=0
while 1:

    #すべで偶数かチェック
    for i in range(N):
        if A[i]%2==0:
            continue
        else:
            F=1
    
    if F==1:break

    for i in range(N):
        A[i]=A[i]/2
    n+=1

print(n)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

#define MAX 52

vector<int> v;

vector<pair<int, int> > ev;


int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		v.push_back(a);
	}
	int mxab = 0;
	int miab = 0;
	int mxid;
	int miid;
	for (int i = 0; i < n; i++) {
		if (v[i] >= 0) {
			mxab = max(mxab, abs(v[i]));
			if (abs(v[i]) == mxab) {
				mxid = i;
			}
		}
		if(v[i]<=0) {
			miab = max(miab, abs(v[i]));
			if (abs(v[i]) == miab) {
				miid = i;
			}
		}
	}
	if (miab <= mxab) {
		for (int i = 0; i < v.size(); i++) {
			ev.push_back({ mxid, i });
		}
		for (int i = 1; i < v.size(); i++) {
			ev.push_back(make_pair(i-1, i));
		}
	}
	else {
		for (int i = 0; i < v.size(); i++) {
			ev.push_back({ miid,i });
		}
		for (int i = v.size() - 1; i >= 1; i--) {
			ev.push_back(make_pair(i, i-1));
		}
	}
	cout << ev.size() << endl;
	for (int i = 0; i < ev.size(); i++) {
		printf("%d %d\n", ev[i].first + 1, ev[i].second + 1);
	}
	return 0;
}

Measured memory_bytes: 256
"""
author : halo2halo
date : 8, Jan, 2020
problem : ABC149
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A, B = map(int,read().split())
print(6 - A - B)


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

using namespace std;
typedef long long ll;

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

  char a, b;
  cin >> a >> b;

  int cmp = (a - 'A') - (b - 'A');
  if (cmp > 0) cout << '>' << "\n";
  else if (cmp < 0) cout << '<' << "\n";
  else cout << '=' << "\n";
}


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

int main(){
  int n, k;
  string s;
  cin>> n;
  cin>> s;
  cin>> k;

  size_t size = s.length();
  for(int i=0;i<size;i++){
    if(s[i] != s[k-1])
      s[i] = '*';
  }

  cout<<s<<endl;

  return 0;
}


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

using namespace std;
#define ll long long int
vector < ll > vv;

int main()
{
    ll a,b,k,i,j;
    cin>>a>>b>>k;
    ll cnt=0;
    for(i=1; i<=100000; i++)
    {
        if(a%i==0 && b%i==0)
        {
            vv.push_back(i);
        }
    }

    sort(vv.rbegin(),vv.rend());
    cout<<vv[k-1]<<endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=1000000000000000010LL;
const int MAX=500010;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
int main(){
    int n,m;cin>>n>>m;
    int d[110][110];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j){
                d[i][j]=0;
            }else{
                d[i][j]=INF;
            }
        }
    }
    int a[1010],b[1010],c[1010];
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i]>>c[i];a[i]--;b[i]--;
        d[a[i]][b[i]]=c[i];
        d[b[i]][a[i]]=c[i];
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                d[i][j]=min(d[i][k]+d[k][j],d[i][j]);
            }
        }
    }
    int ans=0;
    for(int i=0;i<m;i++){
        if(d[a[i]][b[i]]<c[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $N);
fscanf(STDIN, "%s", $S);
$arrS = str_split($S);
$prev = '';
$ans = 0;
for ($i = 0; $i < $N; $i++) {
    if ($prev !== $arrS[$i]) {
        $ans++;
    }
    $prev = $arrS[$i];
}
echo $ans;


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

int main() {
  int N, K;
  cin >> N >> K;
  int value = 1;
  rep(i, N) {
    int a = value * 2;
    int b = value + K;
    if ( a < b ) {
      value = a;
    }
    else {
      value = b;
    }
  }
  cout << value << endl;
}


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define A first
#define B second
#define MOD 1000000007

typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;

int mulmd(ll a, ll b){
    ll ret = (a * b) % MOD;
    return (int)ret;
}

inline int power(ll x, ll y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = mulmd(res, x);
        y = y >> 1;
        x = mulmd(x, x);
    }
    return (int)res;
}

int submd(ll a, ll b){
    ll ret = a - b;
    if(ret < 0){
        ret += MOD;
    }
    return (int)ret;
}

int addmd(ll a, ll b){
    ll ret = (a + b) % MOD;
    return (int)ret;
}

int invPow(ll a){
    return power(a, MOD - 2, MOD);
}

const int N = 1e5 + 5;

int a[N], b[N], c[N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, n) cin >> b[i];
    FOR(i, 1, n - 1) cin >> c[i];
    int s = 0;
    FOR(i, 1, n){
        int cur = a[i];
        s += b[cur];
        if(i == 1) continue;
        else {
            if(a[i] == a[i - 1] + 1){
                s += c[a[i - 1]];
            }
        }
    }
    cout << s;

}

/**
    Check out for boundary cases, (n = 1 or n = 0)
    check for integer overflow

**/



Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.*;

public class Main{
	
	class C implements Comparable<C>{
		int ind, value;

		public C(int ind, int value) {
			this.ind = ind;
			this.value = value;
		}

		@Override
		public int compareTo(C o) {
			return o.value - this.value;
		}
	}

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if((n|m) == 0) break;
			int [][] data = new int[n][m];
			for(int i = 0; i < n; i++){
				for(int j = 0; j < m; j++){
					data[i][j] = sc.nextInt();
				}
			}
			int [] freq = new int[m];
			for(int i = 0; i < m; i++){
				for(int j = 0; j < n; j++){
					if(data[j][i] == 1) freq[i]++;
				}
			}
			C [] str = new C[m];
			for(int i = 0; i < m; i++){
				str[i] = new C(i + 1, freq[i]);
			}
			Arrays.sort(str);
			for(int i = 0; i < str.length - 1; i++){
				System.out.print(str[i].ind + " ");
			}
			System.out.println(str[m-1].ind);
		}
	}

	
	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

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

int c[33], s[444][33], l[33];
int main() {
    int d, r = 0;
    cin >> d;
    for(int i = 0; i < 26; i++)
        cin >> c[i];
    for(int i = 0; i < d; i++)
        for(int j = 0; j < 26; j++)
            cin >> s[i][j];
    for(int i = 0; i < d; i++) {
        auto m = 0.;
        int t = 0;
        for(int j = 0; j < 26; j++) {
            double p = s[i][j];
            p += c[j] * (i + 1 - l[j]);
            for(int k = 1; k < 10; k++)
                if(i + k < d)
                    p -= s[i + k][j] * (10 - k) * .01;
            if(p > m)
                m = p, t = j;
        }
        cout << t + 1 << '\n';
        l[t] = i + 1;
        r += s[i][t];
        for(int j = 0; j < 26; j++)
            r -= c[j] * (i + 1 - l[j]);
    }
    cerr << r << '\n';
    return 0;
}


Measured memory_bytes: 3684
#include<stdio.h>
main(){
  int a[1000000]={0},i,j,n,cnt;
  while(scanf("%d",&n)!=EOF){
    for(i=0;i<=n;i++)a[i]=0;
    cnt=0;
    for(i=2;i<=n;i++){
      if(a[i]==0){
	cnt++;
	for(j=1;i*j<=n;j++){
	  a[i*j]=1;
	}	   
      }
    }


    printf("%d\n",cnt);
  }
  return 0;
}

Measured memory_bytes: 4508
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = int_fast64_t;
using P = pair<int,int>;

int main(){
    int N;
    cin >> N;
    vector<pair<string,pair<int,int>>> res(N);
    rep(i,N){
        string s;
        int p;
        cin >> s >> p;
        res[i] = {s, {-p, i+1}};
    }

    sort(all(res));

    for(auto p : res){
        cout << p.second.second << endl;
    }
}


Measured memory_bytes: 256
//submitted by HimJ
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;
const int mxn=1e5+1;
ll dp[13][mxn];
vector<ll> arr;
ll solve(ll i,ll sum)
{
	if(sum==0)
	return 0;
	if(i<0)
        return INT_MAX;
    if(dp[i][sum]!=-1)
        return dp[i][sum];
    if(sum>=arr[i])
    {
        return dp[i][sum]=min(solve(i-1,sum),1+solve(i,sum-arr[i]));
    }
    return dp[i][sum]=solve(i-1,sum);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  ll t=1;
  //cin>>t;
    while(t--){
    ll i,n;
    arr.pb(1);
    ll temp=6;
    while(temp<mxn)
    {
        arr.pb(temp);
        temp*=6;
    }
    temp=9;
    ms(dp,-1);
    
    while(temp<mxn)
    {
        arr.pb(temp);
        temp*=9;
    }
  //  cout<<arr.size();
cin>>n;
cout<<solve(11,n);
    }
  return 0;
  }



Measured memory_bytes: 10368
from itertools import permutations
import math

def distance(p1, p2):
    return math.sqrt(((p1[0] - p2[0])**2) +  ((p1[1] - p2[1])**2))


n = int(input())
paths = []
for _ in range(n):
  x, y = map(int, input().split())
  paths.append((x, y))



paths = list(permutations(paths))
avg = 0
for path in paths:
    for i in range(len(path) - 1):
        avg += distance(path[i], path[i+1])

print(avg / len(paths))


Measured memory_bytes: 7972
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

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

    vector<int> k(m);
    vector<vector<int> > s(m);

    rep(i, m){
        cin >> k[i];
        rep(j, k[i]){
            int t;
            cin >> t;
            t--;
            s[i].push_back(t);
        }
    }

    vector<int> p(m);
    rep(i, m){
        cin >> p[i];
    }
    int ans = 0;
    for(int bit = 0; bit < (1<<n); ++bit){
        int b = bit;
        vector<int> switches(n, 0);
        vector<int> on(n, 0);
        
        rep(i, n){
            switches[i] = b & 1;
            b = b >> 1;
        }

        rep(i, m){
            rep(j, k[i]){
                int ss = s[i][j];
                if(switches[ss] == 1) on[i]++;
            }
        }

        bool check = true;
        rep(i, m){
            if(p[i] != on[i] % 2) check = false;
        }

        if(check)   ++ans;
    }


    cout << ans << endl;


}

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

using namespace std;

int N;
int Id[15], Dist[15], Weight[15];
int DpWeight[1 << 15], traceInfo[15][1 << 15];
double DpTime[15][1 << 15];

double getTime(double dist, double weight) {
	return dist * (70 + weight) / 2000.0;
}

double judge(int now, int visited) {
	double curTime,resTime;

	if (DpTime[now][visited] != -1) {
		return DpTime[now][visited];
	}
	if (visited == (1 << N) - 1) {
		return 0;
	}

	resTime = DBL_MAX;
	for (int i = 0; i < N; ++i) {
		if (((visited >> i) & 1) == 1) {
			continue;
		}
		curTime = judge(i, visited^(1<<i)) + getTime(abs(Dist[i] - Dist[now]), DpWeight[visited]);
		if (curTime < resTime) {
			resTime = curTime;
			traceInfo[now][visited] = i;
		}
	}

	return DpTime[now][visited] = resTime;
}

void solve(int limit) {
	int id;
	double timeMin, curTime;

	for (int i = 0; i < N; ++i) {
		fill(DpTime[i], DpTime[i] + limit, -1);
	}

	timeMin = DBL_MAX;
	for (int i = 0; i < N; ++i) {
		curTime = judge(i, 1 << i);
		if (curTime < timeMin) {
			timeMin = curTime;
			id = i;
		}
	}

	--limit;
	cout << Id[id];
	for (int i = 1 << id; i < limit; i^=(1<<id)) {
		id = traceInfo[id][i];
		cout << " " << Id[id];
	}
	cout << endl;
}

int main() {
	int limit;

	memset(DpWeight, 0, sizeof(DpWeight));
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> Id[i] >> Dist[i] >> Weight[i];
	}

	limit = 1 << N;
	for (int i = 1; i < limit; ++i) {
		for (int j = 0; j < N; ++j) {
			if (((i >> j) & 1) == 1) {
				DpWeight[i] += Weight[j] * 20;
			}
		}
	}
	solve(limit);

	return 0;
}


Measured memory_bytes: 8784
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}

signed main(){

    int N, M; cin >> N >> M;
    vec A(N), B(M);
    readv(A), readv(B);
    SORT(A); SORT(B);

    bool f = true;
    REP(i, N - 1) if(A[i] == A[i + 1]) f = false;
    REP(i, M - 1) if(B[i] == B[i + 1]) f = false;
    if(!f){
        cout << 0;
        return 0;
    }

    int mod = 1000000007;

    int ans = 1;
    IFOR(n, 1, N * M + 1){
        int i0 = Lower_bound(A, n);
        int j0 = Lower_bound(B, n);
        if(i0 == N || j0 == M){
            cout << 0;
            return 0;
        }
        if(A[i0] == n && B[j0] == n){
            ans *= 1;
        }else if(A[i0] == n){
            ans *= M - j0;
        }else if(B[j0] == n){
            ans *= N - i0;
        }else{
            ans *= max((N - i0) * (M - j0) - (N * M - n), 0LL);
        }

        ans %= mod;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
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;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}




int N;

int main () {
  ll ct = 0;
  cin >> N;

  Rep(i, N) {
    ll tmp;
    cin >> tmp;
    if (tmp % 2 == 1) ct++;
  }

  if (ct % 2 == 1) {
    cout << "NO\n";
  } else {
    cout << "YES\n";
  }
}

Measured memory_bytes: 256
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n=N()
l=LN(n)
sl=sorted(l)
d={}
ans=0
for i,j in enumerate(sl):
    d[j]=i%2
for i,j in enumerate(l):
    if d[j]!=i%2:
        ans+=1
print(ans//2)

Measured memory_bytes: 17136
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m,k;
  cin >> n >> m >> k;
  ll a[n],b[m];
  rep(i,n) R a[i];
  rep(i,m) R b[i];
  ll ans=MAXL;
  rep(i,k) {
    int x,y,z;
    cin >> x >> y >> z;
    x--,y--;
    ans=min(ans,a[x]+b[y]-z);
  }
  sort(a,a+n);
  sort(b,b+m);
  ans=min(ans,a[0]+b[0]);
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 1792
N = int(input())
A = [0] + list(map(int,input().split()))
A_sums = [0 for _ in range(N+1)]
A_sums_rev = [0 for _ in range(N+1)]

for idx in range(0,N-1):
  A_sums[idx+1] = A_sums[idx] + A[idx+1]

for idx in range(N-1,0,-1):
  A_sums_rev[idx] = A_sums_rev[idx+1] + A[idx+1]
  
print(min([abs(i-j) for i,j in zip(A_sums[1:-1],A_sums_rev[1:-1])]))

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

using namespace std;

int count(string s, char next_color) {
    int cnt = 0;
    for (int i = 0; i < (int)s.length(); i++) {
        if (next_color != s[i]) {
            cnt++;
        }
        next_color = (next_color == '0') ? '1' : '0';
    }

    return cnt;
}

int main() {
    int bstart_cnt = 0;
    int wstart_cnt = 0;

    string S;
    cin >> S;

    bstart_cnt = count(S, '0');
    wstart_cnt = count(S, '1');

    cout << min(bstart_cnt, wstart_cnt) << endl;
    return 0;
}



Measured memory_bytes: 512
n,a,b,c,d=map(int,input().split())
s=str(input())
s=list(s)
cnts=0
cnti=0
space=0
iwa=0
temp=0
next=0
if c<d:
  for i in range(a-1,d):
    if s[i]==".":
      cnts=cnts+1
      space=max(space,cnts)
      cnti=0
    else:
      cnti=cnti+1
      iwa=max(iwa,cnti)
      cnts=0
  if iwa>1:
    print("No")
  else:
    print("Yes")
else:
  for i in range(a-1,c):
    if s[i]==".":
      if i<=b-2:
        cnts=0
      cnts=cnts+1
      space=max(space,cnts)
      cnti=0
    else:
      cnti=cnti+1
      iwa=max(iwa,cnti)
      cnts=0
    if i==d-1:
      temp=space
      if s[i-1]=="." and s[i+1]==".":
        next=1
  if iwa>1:
    print("No")
  elif temp<3 and next==0:
    print("No")
  else:
    print("Yes")

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

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define rep(i, n) for(int i=0;i<(int)(n);i++)

int main(void){
	int a, b, c;
	scanf("%d%d%d",&a,&b,&c);
	if(a+b+c>=22){
		printf("bust\n");
	}
	else{
		printf("win");
	}
    return 0; 
}


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

using namespace std;

class UnionFind {
	vector<int> data;

public:
	int independentSet;
	UnionFind(int size) : data(size, -1), independentSet(size) {}
	bool unionSet(int x, int y) {
		x = root(x);
		y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y];
			data[y] = x;
			independentSet--;
		}
		return x != y;
	}
	bool findSet(int x, int y) { return root(x) == root(y); }
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	int size(int x) { return -data[root(x)]; }
};

class Solution {
public:
	void solve() {
		int n, q;
		cin >> n >> q;
		UnionFind uf(n);
		while (q--) {
			int t, u, v;
			cin >> t >> u >> v;
			if (t == 0)
				uf.unionSet(u, v);
			else
				cout << (uf.findSet(u, v) ? 1 : 0) << "\n";
		}
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 3932
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>

#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)

using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;
long long cnt[26];
char S[222222];
int main() {
	scanf("%s", S);
	n = strlen(S);
	REP(i, n) cnt[S[i]-'a']++;
	long long ans = 0;
	REP(i, 26) ans += (cnt[i]*(n-cnt[i]));
	printf("%lld\n", ans/2+1);

	return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<ll> X1(N), Y1(N), Z1(N);
    vector<ll> X2(N), Y2(N), Z2(N);
    vector<ll> xs, ys, zs;
    for (int i = 0; i < N; i++) {
        cin >> X1[i] >> Y1[i] >> Z1[i];
        cin >> X2[i] >> Y2[i] >> Z2[i];
        xs.push_back(X1[i]); xs.push_back(X2[i]);
        ys.push_back(Y1[i]); ys.push_back(Y2[i]);
        zs.push_back(Z1[i]); zs.push_back(Z2[i]);
    }

    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());

    sort(ys.begin(), ys.end());
    ys.erase(unique(ys.begin(), ys.end()), ys.end());

    sort(zs.begin(), zs.end());
    zs.erase(unique(zs.begin(), zs.end()), zs.end());
    
    ll res = 0;
    for (int i = 0; i < (int)xs.size()-1; i++) {
        for (int j = 0; j < (int)ys.size()-1; j++) {
            for (int k = 0; k < (int)zs.size()-1; k++) {
                int cnt = 0;
                for (int l = 0; l < N; l++) {
                    if (X1[l] <= xs[i] && xs[i+1] <= X2[l] &&
                        Y1[l] <= ys[j] && ys[j+1] <= Y2[l] &&
                        Z1[l] <= zs[k] && zs[k+1] <= Z2[l]) {
                        cnt++;
                    }
                }
                if (cnt >= K) {
                    res += (xs[i+1] - xs[i]) * (ys[j+1] - ys[j]) * (zs[k+1] - zs[k]);
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3156
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============



int main()
{
    ll N;
    cin >> N;
    vector<ll> a(N), b(N);
    rep(i, N)cin >> a[i] >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    if (N % 2 == 1) {
        ll mn = a[(N - 1) / 2];
        ll mx = b[(N - 1) / 2];
        cout << mx - mn + 1 << endl;
    }
    else {
        ll mn = a[N / 2 - 1] + a[N / 2];
        ll mx = b[N / 2 - 1] + b[N / 2];
        cout << mx - mn + 1 << endl;
    }

    return 0;
}


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

using namespace std;

const int mod = 1e9 + 7;

int n,m, l, r, ans;
int dp[302][302][302];
vector<pair<int, int> >q[302];

bool ok (int i, int j, int k) {
  int r = max(i, max(j, k));
  for (auto it : q[r]) {
    int l = it.first, x = it.second;
    int nr = 0;
    if (i >= l) nr++;
    if (j >= l) nr++;
    if (k >= l) nr++;
    if (nr != x)
      return 0;
  }
  return 1;
}

int main()
{
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    q[y].push_back({x, c});
  }
  dp[0][0][0] = 1;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      for (int k = 0; k <= n; k++) {
        if (!dp[i][j][k])
          continue;
        if (i && i == j)
          continue;
        if (j && j == k)
          continue;
        if (k && i == k)
          continue;
        if (ok(i, j, k) == 0) {
          dp[i][j][k] = 0;
          continue;
        }
        int mx = max(i, max(j, k));
        dp[mx + 1][j][k] += dp[i][j][k];
        dp[i][mx + 1][k] += dp[i][j][k];
        dp[i][j][mx + 1] += dp[i][j][k];
        dp[mx + 1][j][k] %= mod;
        dp[i][mx + 1][k] %= mod;
        dp[i][j][mx + 1] %= mod;
        if (mx == n) {
          ans = (ans + dp[i][j][k]) % mod;
        }
      }
  cout << ans;
  return 0;
}


Measured memory_bytes: 107904
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef __int128_t lll;
typedef pair <int, int> P;
typedef vector<lll> vec;
typedef vector<vec> mat;
ll MOD;
ll L,A,B;
mat mul(mat A, mat B){
    mat C(A.size(), vec(B[0].size()));
    rep(i,0,A.size()){
        rep(k,0,B.size()){
            rep(j,0,B[0].size()){
                C[i][j]+=A[i][k]*B[k][j]%MOD;
                C[i][j]%=MOD;
            }
        }
    }
    return C;
}

mat pow(mat A, ll n){
    mat B(A.size(), vec(A.size()));
    rep(i,0,A.size()){
        B[i][i]=1;
    }
    while(n>0){
        if(n&1) B=mul(B,A);
        A=mul(A,A);
        n>>=1;
    }
    return B;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>L>>A>>B>>MOD;
    ll last=A+B*(L-1);
    ll ans=0;
    bool X=true;
    while(X){
        ll ret=1, rett=1;
        rep(i,0,19){
            if(A<ret){
                break;
            }
            else{
                ret*=10;
                rett=ret%MOD;
            }
        }
        ll u=ret;
        ll n=(u-A-1)/B;
        if(last<u){
            n=(last-A)/B;
            X=false;
        }
        mat a(3,vec(3,0));
        mat b(3, vec(1,0));
        a[0][0]=rett; a[0][1]=1; a[0][2]=0;
        a[1][0]=0; a[1][1]=1; a[1][2]=B%MOD;
        a[2][0]=0; a[2][1]=0; a[2][2]=1;
        b[0][0]=ans; b[1][0]=A; b[2][0]=1;
        a=mul(pow(a,n+1), b);
        ans=a[0][0];
        A=A+B*(n+1);
    }
    cout <<ans<<"\n";
}

Measured memory_bytes: 256
n=int(input())
dic={0:'a',1:'b',2:'c',3:'d',4:'e',5:'f',6:'g',7:'h',8:'i',9:'j'} 
#標準形の文字列は同型の文字列の中で辞書順最小であることから、新たに付け加えるべき文字は順にa,b,c...となる
ans=[['a',1]]
for i in range(1,n):
 tmp=[]
 for prev,val in ans:
   for j in range(val+1): 
    #(今見ている文字列に使われている文字の種類数+1)種類の文字を付け加える
     if j!=val: 
        #今見ている文字列に使われている文字を付け加えるとき、文字の種類数は増加しない
       tmp.append([prev+dic[j],val])
     else: 
      #今見ている文字列に使われていない文字を付け加えるとき、文字の種類数が増加する
       tmp.append([prev+dic[j],val+1])
 ans=tmp
ans=sorted(ans,key=lambda x:x[0]) 
#生成した標準形の文字列を辞書順昇順に並べ替える
for i in range(len(ans)):
 print(ans[i][0])

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

using namespace std;

#define N 30000
#define M 500
#define LL long long

const LL mod=1000000007;
LL n,m,p,s1,s2,ans,cnt,sum,a[N],f[N][M],g[N][M],vis[N],fac[N],ifac[N];

LL inv(LL x){return x==1?1:(mod-mod/x)*inv(mod%x)%mod;}

LL P(LL x,LL y){return fac[x]*ifac[x-y]%mod;}

int main(){
	scanf("%lld%lld%lld",&n,&p,&m);
	if (n<p){puts("0"); return 0;}
	fac[0]=1; for (LL i=1;i<=n;++i) fac[i]=fac[i-1]*i%mod;
	ifac[n]=inv(fac[n]); for (LL i=n-1;i>=0;--i) ifac[i]=ifac[i+1]*(i+1)%mod;
	for (LL i=1;i<p;++i){
		f[0][i]=1;
		g[0][i]=g[0][i-1]+f[0][i];
	}
	for (LL i=1;i<=n;++i)
		for (LL j=1;j<p;++j){
			f[i][j]=(f[i-1][j+1]*(p-j)+g[i-1][j])%mod;
			g[i][j]=(g[i][j-1]+f[i][j])%mod;
		}
	for (LL i=1;i<=m;++i) scanf("%lld",&a[i]);
	sum=1; for (LL i=1;i<=n-m;++i) sum=sum*p%mod;
	for (LL i=1;i<=p;++i){
		if (!vis[a[i]]) ++cnt;
		++vis[a[i]];
	}
	for (LL i=1;i+p-1<=m;++i){
		if (cnt==p){
			printf("%lld\n",sum*(n-m+1)%mod);
			return 0;
		}
		--vis[a[i]]; if (!vis[a[i]]) --cnt;
		if (!vis[a[i+p]]) ++cnt; ++vis[a[i+p]];
	}
	memset(vis,0,sizeof vis);
	for (LL i=1;i<=m;++i)
		if (!vis[a[i]]){vis[a[i]]=1; ++s1;}
		else break;
	memset(vis,0,sizeof vis);
	for (LL i=m;i;--i)
		if (!vis[a[i]]){vis[a[i]]=1; ++s2;}
		else break;
	ans=sum*(n-m+1);
	if (s1==m){
		LL tmp=0;
		for (LL i=1;i<=n;++i)
			for (LL j=m;j<p&&i+j-1<=n;++j)
				if (i+j-1<n) tmp=(tmp+f[i-1][j]*P(p-m,j-m)%mod*g[n-i-j][j])%mod;
				else tmp=(tmp+f[i-1][j]*P(p-m,j-m))%mod;
		ans=(ans-tmp+mod)%mod;
	}
	else
		for (LL i=1;i+m-1<=n;++i)
			ans=((ans-f[i-1][s1]*f[n-(i+m-1)][s2])%mod+mod)%mod;
	printf("%lld\n",ans);
	
	return 0;
}
			

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

int main(){
  int a,b; 
  cin >> a >> b;
  if(a%3==0 || b%3==0 || (a+b)%3 == 0){
    cout << "Possible" << endl;
  }
  else{
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 3604
#include<stdio.h>
#include<string.h>
int main()
{
	char s[101];
	while(scanf("%s",s) != EOF)
	{
	
	
	
	int ans=0;
	for(int i=0;i<strlen(s);i++)
	{
		if(s[i]=='C')
		{
			int j=i;
			for(i=j;i<strlen(s);i++)
			{
				if(s[i]=='F')
				{
				ans=1;}
				
			}
			

		}	
	}
	
	if(ans==1)
		{
		printf("Yes\n");}
		else
					{
					printf("No\n");}
		
	}
	
	
	
	
	return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> p(m);
  vector<int> q(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    p[i].resize(k);
    for (int j = 0; j < k; j++) cin >> p[i][j];
  }
  for (int i = 0; i < m; i++) cin >> q[i];
  int ans = 0;
  for (int i = 0; i < (1 << n); i++) {
    bool ok = true;
    for (int j = 0; j < m; j++) {
      int b = 0;
      for (auto &k : p[j]) {
        b += (i >> (k - 1)) & 1;
      }
      if (b % 2 != q[j]) ok = false;
    }
    if (ok) ans++;
  }

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


Measured memory_bytes: 256
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
#include <limits>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc
{
    // 宣言
    long long a;

    public:
        // 素因数分解
        void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            //printf("%d * ", a);
             v.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    v.push_back(n);
    //printf("%d\n", n);
}
vector<int> divisor(int n) {
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    std::sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    //std::stack<int> stack;
    int n;
    cin >> n;
    int ans = 0;
    vector<int> a(n);
    vector<int> cnt(10000000, 0);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        cnt[a[i]] ++;
    }
    if(cnt[1] > 1){
                cout << 0 << endl;
                return 0;
            }
    for(int i = 0; i < n; i++){
        bool jud = true;
        vector<int> yaku = divisor(a[i]);
        for(auto j : yaku){
            if(cnt[j] >= 1){
                if(j == a[i] && cnt[j] == 1){
                    continue;
                }
                jud = false;
                break;
            }
            
        }
        if(jud){
            ans ++;
            //cout << a[i] << " ";
        }
    }
    //cout << endl;
    cout << ans << endl;
    return 0;
}






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

int main(void){
	long long int  a,b,c,d,e;
  cin >> a >> b >> c ;
if((b+c)%2 == 0){
  cout <<"Alice" << endl;
}
  else{
    cout << "Borys" << endl;
  }
}

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

int	main() {
	int N;
	cin >>N;
	vector<int> L(N);
	for (int i=0; i<N; i++)
		cin >>L.at(i);
	sort(L.begin(), L.end());
	long S=0;
	for (int i=0; i<L.size()-2; i++) {
		for (int j=i+1; j<L.size()-1; j++) {
			if (L.at(j)-L.at(i)>=L.back())
				break;
			for (int k=j+1; k<L.size(); k++) {
				if (L.at(k)<=L.at(j)-L.at(i))
					continue;
				if (L.at(k)>=L.at(i)+L.at(j))
					break;
				S++;
			}
		}
	}
	cout <<S <<endl;
	return 0;
};


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

L = [0] * N

for i in range(N):
  A = int(input())
  if A == 0:
    L[i] = []
  else:
    L[i] = [list(map(int, input().split()))]
  for j in range(1,A):
    L[i].append(list(map(int, input().split())))
    
#print(L)

ans = 0
for i in range(2**N):
  pat = str(format(i, '0' + str(N) + 'b'))
  flg = True
  #S = [-1] * (N)
  for j in range(N):
    if pat[j] == "1": # trueman
      for rule in L[j]:
        if pat[rule[0]-1] == "0" and rule[1] == 1:
          flg = False
          break
        if pat[rule[0]-1] == "1" and rule[1] == 0:
          flg = False
          break
  #print("XXX", flg, pat, j)
  if flg:
    work = 0
    for ch in pat:
      if ch == "1":
        work += 1
    #print("XXX", flg, pat, j, work)
    ans = max(ans, work)
    
print(ans)

Measured memory_bytes: 3188
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

	ll sign = 1;
	if (a + b - c < 0) sign = -1;

	if ((a + b < c) && ((a + b - c) * (a + b - c) > 4 * a * b))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import kotlin.math.*

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() //single long
private fun readDouble() = readLn().toDouble() //single double

private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map{it.toLong()} // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles

fun main(){
    val n = readInt()

    var counter = 0

    val remain = n/2

    if(n%2 == 0){
        for(i in 1 until n/2){
            for(j in 1 until n){
                if(i*j < n){
                    counter ++
                }else{
                    break
                }
            }
        }
    }else{
        for(i in 1 until n/2 +1){
            for(j in 1 until n){
                if(i*j < n){
                    counter ++
                }else{
                    break
                }
            }
        }
    }

    println(remain + counter)

}

Measured memory_bytes: 34988
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>=0;(i)--)
typedef long long lint;

int main(){
int N,M;
cin >>N>>M; tuple<int,int,int,int>s[M] ;
rep(i,M) {
    int a,b;
    cin>>a>>b;
   s[i]= make_tuple(a,b,i,0);
}
sort(s,s+M);
 int count,d,e,f,g,tmp;
 count=1;
rep(i,M){
  
    tie(d,e,f,g)=s[i];
    if(i==0){
        tmp=d;
        s[i]=make_tuple(f,d,e,count);
        count++;
    }else if(tmp==d){
         s[i]=make_tuple(f,d,e,count);
         count++;
    }else{
        count=1;
        tmp=d;
         s[i]=make_tuple(f,d,e,count);
         count++;
    }
}
sort(s,s+M);
rep(i,M){
    tie(d,e,f,g)=s[i];
    cout << setfill('0') << right << setw(6) << e;
    cout << setfill('0') << right << setw(6) << g<<endl;
}

}
   
 



  


Measured memory_bytes: 3072
#coding:utf-8
n = input()
a,b = map(int,input().split())
p = list(map(int,input().split()))

first=0
second=0
third=0

for i in p:
  if i <= a:
    first +=1
  elif i <= b:
    second +=1
  else:
    third +=1

print(min([first,second,third]))


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

using namespace std;

const int maxn = 5007;

int n,K;
int a[maxn];
bitset<maxn>f;

int main(){
	scanf("%d%d",&n,&K);
	for(int i = 1; i <= n; ++i)scanf("%d",&a[i]),a[i] = min(a[i],K);
	sort(a + 1,a + n + 1);
	f[0] = 1;
	int sum = 0;
	for(int i = 1; i <= n; ++i)sum += a[i];
	for(int i = n; i; --i){
		bool FAIL = 0;
		for(int j = max(K - sum,0); j <= K - 1 && !FAIL; ++j)
			if(f[j])FAIL = 1;
		if(!FAIL){
			printf("%d\n",i);
			exit(0);
		}
		f |= (f << a[i]);
		sum -= a[i];
	}puts("0");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;
ll h[100000];
int ans[100000];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>h[i];
	ans[n-1]=0;
	for(int i=n-2;i>-1;i--)
	{
		if(h[i]>=h[i+1])
			ans[i]=ans[i+1]+1;
		else
			ans[i]=0;
	}
	int aa=0;
	for(int i=0;i<n;i++)
		aa=max(aa,ans[i]);
	cout<<aa<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<math.h>
#define PI 3.141592/180
using namespace std;

int main()
{
	int a,b,C;
	double S,L,h;

	cin >> a >> b >>C;

	h = b * sin(C*PI);

	S = a * h / 2;

	L = sqrt((a*a)+(b*b)-(2*a*b*cos(C*PI))) + a + b;

	cout << S << ' ' << L << ' ' << h << endl ;

	return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


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

  int n;
  cin>>n;
  vi p(n),q(n);
  rep(i,n){
    cin>>p[i];
  }
  rep(i,n){
    cin>>q[i];
  }

  int a=0,b=0;
  vi v(n);
  rep(i,n){
    v[i]=i+1;
  }
  int cnt=1;
  do{
    bool s=true;
    rep(i,n){
      s&=v[i]==p[i];
    }
    if(s) a=cnt;
    s=true;
    rep(i,n){
      s&=v[i]==q[i];
    }
    if(s) b=cnt;
    cnt++;
  }while(next_permutation(all(v)));

  cout<<abs(a-b)<<endl;



}

Measured memory_bytes: 256