akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main()
{
    int r, g, b, n;
    cin >> r >> g >> b >> n;

    int cnt = 0;
    for (int ri = 0; ri <= n / r; ri++)
    {
        int rest = n - r * ri;
        if (rest == 0)
        {
            cnt++;
            continue;
        }
        else if (rest < 0)
        {
            break;
        }

        for (int gi = 0; gi <= n / g; gi++)
        {
            rest = n - r * ri - g * gi;
            if (rest < 0)
            {
                break;
            }

            if (rest % b == 0)
            {
                cnt++;
            }
        }
    }

    cout << cnt << endl;
    return 0;
}


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

using namespace std;

int main() {
    int x, s, e, m;
    scanf("%d",&x);
    s=0;e=45000;
    while(s<=e) {
        m = (s+e)>>1;
        if (m*(m+1)/2<x) s = m+1;
        else e = m-1;
    }
    printf("%d\n",s);

    return 0;
}


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

using namespace std;

using int64 = long long;

int64 Sum(const vector<int64>& xs) {
  int64 value = 0;
  for (int64 x : xs) value += x;
  return value;
}

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

  int n;
  int64 k;
  cin >> n >> k;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) cin >> xs[i];
  int64 sum = Sum(xs);

  vector<int64> ds;
  for (int64 i = 1; i * i <= sum; i++) {
    if (sum % i == 0) {
      ds.push_back(i);
      if (i * i < sum) ds.push_back(sum / i);
    }
  }
  sort(ds.begin(), ds.end());

  int64 ans = 1;
  for (int64 d : ds) {
    // cout << "d: " << d << endl;
    vector<int64> rs(n);
    for (int i = 0; i < n; i++) rs[i] = xs[i] % d;
    sort(rs.begin(), rs.end());
    int64 r_sum = Sum(rs);
    int64 cost = 0;
    for (int i = 0; i < n - (r_sum / d); i++) {
      cost += rs[i];
    }
    if (cost <= k) ans = d;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define N ((int)1e5 + 1)
#define forn(i,x,y) for(int i = int(x); i<int(y); i++)
#define debug(x) cerr << #x << " == " << (x) << '\n';
#define all(V) V.begin(), V.end()
 
template<typename T> ostream &operator<<(ostream &out, const pair<T, T> &P){ out << P.first << ' ' << P.second; return out; }
template<typename T> ostream &operator<<(ostream &out, const vector<T> &V){ for(int i = 0; i<V.size(); ++i) out << V[i] << ' '; return out; }
template<typename T> istream &operator>>(istream &in, vector<T> &V){ for(T &i : V) in >> i; return in; }
template<typename T> istream &operator>>(istream &in, pair<T,T> &P){ in >> P.first >> P.second; return in; }
 
int A[81][81], B[81][81];
int n, m;
 
int dp[81][81][13100];
 
const int inf = 1e8;
 
int solve(int i, int j, int dif) {
    if(i == n - 1 and j == m - 1) {
        int s1 = dif + A[i][j] - B[i][j];
        int s2 = dif + B[i][j] - A[i][j];
        return min(abs(s1), abs(s2));
    }
    if(abs(dif) > 6500) return inf;
 
    int &ans = dp[i][j][dif + 6500];
    if(~ans) return ans;
 
    int s1 = inf, s2 = inf, s3 = inf, s4 = inf;
 
    if(i < n - 1) {
        s1 = solve(i + 1, j, dif + A[i][j] - B[i][j]);
        s2 = solve(i + 1, j, dif + B[i][j] - A[i][j]);
    }
    if(j < m - 1) {
        s3 = solve(i, j + 1, dif + A[i][j] - B[i][j]);
        s4 = solve(i, j + 1, dif + B[i][j] - A[i][j]);
    }
 
    return ans = min(s1, min(s2, min(s3,s4)));
}
 
 
int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
    memset(dp, -1, sizeof dp);
    cin >> n >> m;
    forn(i,0,n) forn(j,0,m) cin >> A[i][j];
    forn(i,0,n) forn(j,0,m) cin >> B[i][j];
 
    cout << solve(0,0,0) << '\n';
 
    return 0;
}
 
/* don't forget to check:
   int overflow
   min/max cases (n = 1)
   printing index of sorted array
   limits for ans (start with inf)
 */

Measured memory_bytes: 336000
program TEST
	! your code goes here

integer::n,i,x
real::t2(100000),t3(100000),a,t4,h(100000),t1
read(*,*)n
read(*,*)t1,a
read(*,*)h(1:n)
!write(*,*)n
!write(*,*)t1
!write(*,*)a
!write(*,*)h()
do i=1,n
t2(i)=t1-0.006*h(i)
t3(i)=(a-t2(i))**2
end do
!write(*,*)t3(2)
x=0
t4=100000000
do i=1,n
if (t4>t3(i)) then
x=i

t4=t3(i)
endif
end do

write(*,*) x


stop
end


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

S = raw_input()

if 0 < int(S[0:2]) < 13:
    if  0 < int(S[2:4]) < 13:
        print "AMBIGUOUS"
    else:
        print "MMYY"
else:
    if  0 < int(S[2:4]) < 13:
        print "YYMM"
    else:
        print "NA"

Measured memory_bytes: 2568
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)

int n, f[5][5], s;
int dp[1<<20];

int rec(int at) {
    if(at==5) return dp[s>>5];
    if((s&(1<<at))==0) return rec(at+1);
    int ans=1<<30;
    rep(xe, 5) for(int ye=at; ye<5; ye++) {
        rep(x, xe+1) for(int y=at; y<=ye; y++) s ^= 1<<(x*5+y);
        ans = min(ans, rec(at+1)+1);
        rep(x, xe+1) for(int y=at; y<=ye; y++) s ^= 1<<(x*5+y);
    }
    return ans;
}

int main() {
    rep(i, 1<<20) dp[i]=1<<30;
    dp[0] = 0;
    rep(b, 1<<20) {
        rep(xe, 4) rep(xs, xe+1) rep(ye, 5) rep(ys, ye+1) {
            int nb=b;
            for(int x=xs; x<=xe; x++) for(int y=ys; y<=ye; y++) {
                nb ^= 1<<(x*5+y);
            }
            dp[nb] = min(dp[nb], dp[b]+1);
        }
    }
    for(;;) {
        scanf("%d", &n);
        if(n==0) return 0;
        memset(f, 0, sizeof(f));
        rep(i, n) rep(j, n) scanf("%d", f[i]+j);
        s = 0;
        rep(i, n) rep(j, n) s|=f[i][j]<<(i*5+j);
        int ans = n<5 ? dp[s] : rec(0);
        rep(i, ans) printf("myon");
        putchar('\n');
    }
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1000000000000;
string alp="abcdefghijklmnopqrstuvwxyz";

int main(){
    int N,M,R;
    cin >> N >> M >>R;
    vector<int> r(R);
    rep (i,R){
        cin >> r[i];
        r[i]--;
    }
    sort(r.begin(),r.end());
    vector<vector<ll>> d(N,vector<ll>(N,INF));
    rep(i,N){
        d[i][i]=0;
    }
    rep(i,M){
        ll A,B,C;
        cin >> A >> B >> C;
        A--,B--;
        d[A][B]=C;
        d[B][A]=C;
    }
    rep(k,N){
        rep(i,N){
            rep(j,N){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    ll ans=INF;
    do {
        ll sum=0;
        rep(i,R-1){
            sum+=d[r[i]][r[i+1]];
        }
        ans=min(ans,sum);
    } while(next_permutation(r.begin(),r.end()));
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <stdio.h>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()

const int N = 1010;
const int inf = 2e9;

int n, m, dp[1 << 13];
int cost[N], keys[N], num;

int main()
{
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> cost[i] >> num;
		for (int j = 0; j < num; j++) {
			int x;
			cin >> x;
			x--;
			if (!(keys[i] & (1 << x))) 
				keys[i] |= (1 << x);
		}
	}
	for (int i = 1; i < (1 << 13); i++)
		dp[i] = inf;
	for (int mask = 1; mask < (1 << n); mask++)
		for (int j = 0; j < m; j++) {
			for (int s = mask; ; s = (s - 1) & mask) {
				if (((s | keys[j]) & mask) == mask) 
					dp[mask] = min(dp[mask], dp[s] + cost[j]);
				if (s == 0) break;
			}

		}
	int ans = dp[(1 << n) - 1];
	cout << (ans == inf ? -1 : ans) << '\n';
}


Measured memory_bytes: 384
def factorize(n):
    fct = []
    b,e = 2,0
    while b*b <= n:
        while n % b==0:
            n = n//b
            e += 1
        if e > 0:
            fct.append((b,e))
        b,e = b+1,0
    if n > 1:
        fct.append((n,1))
    return fct

n,p = map(int,input().split())
ans = 1
for prime,power in factorize(p):
    ans *= pow(prime,(power//n))
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  int odd = (N+1)/2;
  double result = (double)odd/N;
  cout << fixed << setprecision(10) << result << endl;
  return 0;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
cost_mat = []
for i in range(10):
    cost_mat.append(list(map(int, input().split())))

for stop in range(10):
    for start in range(10):
        for end in range(10):
            cost_mat[start][end] = min(cost_mat[start][end], cost_mat[start][stop] + cost_mat[stop][end])
cost = 0
for h in range(H):
    in_ls = list(map(int, input().split()))
    for num in in_ls:
        if not num == -1:
            cost += cost_mat[num][1]
print(cost)

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;



int main(){
  long int n,k; cin>>n>>k;
  vector<long int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  
  long int next=1;
  vector<int> visited(n+1,-1);
  vector<int> q;
  long int loopsize;
  for(int i=0;i<k+1;i++){
    if(visited[next]!=-1){
      break;
    }
    visited[next]=q.size();
    q.push_back(next);
    next=a[next-1];
    
  }
  
  if(k+1==q.size()){
    cout<<q[k];
  }else{
    loopsize=q.size()-visited[next];
    cout<<q[visited[next]+(k-visited[next])%loopsize];
  }
  
   
  
  //cout<<next;
  
  
  return 0;
}

Measured memory_bytes: 6596
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	int64_t A, B;
	char op[4];
	if (scanf("%" SCNd64 "%3s%" SCNd64, &A, op, &B) != 3) return 1;
	switch (op[0]) {
		case '+':
			printf("%" PRId64 "\n", A + B);
			break;
		case '-':
			printf("%" PRId64 "\n", A - B);
			break;
		default:
			puts("ERROR!");
			break;
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int N, L;
	cin >> N >> L;

	vector<int> apple(N, 0);
	int sum = 0;
	for (int i = 0; i < N; i++) {
		apple[i] = L + i;
		sum += apple[i];
	}

	sort(apple.begin(), apple.end(),
		[] (int a, int b){
			return abs(a) < abs(b);
		});


	int ans = sum - apple[0];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll &b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll &b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
ll num=1, ans=0, cnt=0, sum=0;

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

  ll N;
  cin >> N;
  vl S(N+1);
  rep(i, N-1) {
    ll A;
    cin >> A;
    ++S[A];
  }
  rep2(i, N) cout << S[i] << '\n';
  return 0;
}


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

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

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            char[] s = in.next().toCharArray();
            int n = in.nextInt();

            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < s.length; i += n) {
                sb.append(s[i]);
            }

            out.println(sb.toString());
        }

    }
}



Measured memory_bytes: 23380
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = n / 500;
        int b = (n - a * 500) / 5;
        System.out.println(a*1000+b*5);
    }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;

int main(){
    int n;  cin >> n;
    vector<ll>a(n);
    rep(i,n)    cin >> a[i];//dam
    vector<ll>b(n);//yama
    
    for(int i=0;i<n;i++){
        if(i % 2 == 0){
            b[0] += a[i];
        }
        if(i % 2 == 1){
            b[0] -= a[i];
        }
    }
    
    for(int i=0;i<n-1;i++){
        b.at(i+1) =2*a.at(i) - b.at(i);
    }


    for(ll i=0 ; i<n ;i++){
     cout << b.at(i) << " ";
    }
    cout << endl;
    return 0;

}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	string s;
	cin >>n >>s;
	
	VI ct(30);
	rep(i ,n) ct[s[i]-'a']++;
	
	VI a;
	rep(i, 28) if(ct[i]>0) a.push_back(ct[i]);
	int m=sz(a);

	ll ans = 0;
	vector<ll> dp(2);
	dp[0]=1;
	rep(i, m){
		vector<ll> np(2);
		rep(j, 2){
			(np[0] += dp[j]) %=mod;
			(np[1] += dp[j] * a[i]) %=mod;
		}
		swap(dp, np);
	}
	cout << (dp[0] + dp[1] +mod -1 )%mod<<"\n";
	return 0;
}



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

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

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());
            int c = Integer.parseInt(in.next());
            boolean ok = false;

            if (a + b == c) ok = true;
            if (b + c == a) ok = true;
            if (c + a == b) ok = true;
            out.println(ok ? "Yes" : "No");

        }

    }
}



Measured memory_bytes: 35404
N, K = [int(i) for i in input().split()]
nusuke = set(range(1, N + 1))
nusuke_with_treats = set()

for _ in range(K):
    input()
    for i in input().split():
        nusuke_with_treats.add(int(i))

print(len(nusuke - nusuke_with_treats))


Measured memory_bytes: 9172
n, m, x = map(int, input().split())
ca_list = []
budget_list = []

for _ in range(n):
  ca_list.append(input())

for i in range(2 ** n):
  bit_list = []
  for j in range(n):
    if (i >> j) & 1:
      bit_list.append(j)
  #print(bit_list)
  budget = 0
  point_list = [0] * m
  for b in bit_list:
    text = list(map(int, ca_list[b].split()))
    point_list = [x + y for (x, y) in zip(text[1:], point_list)]
    budget += text[0]
  #print(budget, point_list)
  if min(point_list) >= x:
    budget_list.append(budget)

if budget_list == []:
  print('-1')
else:
  print(min(budget_list))



Measured memory_bytes: 9128
n, m = map(int, input().split())
q_re = set()
ac = 0
wa = 0
dic_wa = {}
for i in range(m):
    q, re = input().split()
    if(re == "WA" and q not in q_re): 
        if(q not in dic_wa): dic_wa[q] = 1
        else: dic_wa[q] += 1
    if(re == "AC" and q not in q_re): 
        ac += 1
        q_re.add(q)
        if(q in dic_wa): wa += dic_wa[q]
print(ac, wa)

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

int main() {
  int n, k;
  cin >> n >> k;
  if(n <= k) puts("1");
  else {
    n -= k;
    int pos = n / (k - 1), yu = n % (k - 1);
    printf("%d\n", pos + 1 + (yu > 0));
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
	int n;
	double x1,x2,x3,y1,y2,y3,x,y,r;
	scanf("%d",&n);
	    for(int i=0;i<n;i++){
        scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
        x=((y2-y1)*((y3*y3-y1*y1)+(x3*x3-x1*x1))-(y3-y1)*((y2*y2-y1*y1)+(x2*x2-x1*x1)))/
                (2*((x3-x1)*(y2-y1)-(x2-x1)*(y3-y1)));
        if(y2 != y1){
            y=(2*(x1-x2)*x+(y2*y2-y1*y1)+(x2*x2-x1*x1))/(2*(y2-y1));
        }else{
            y=(2*(x1-x3)*x+(y3*y3-y1*y1)+(x3*x3-x1*x1))/(2*(y3-y1));
        }
 
        r = sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
        printf("%.3lf %.3lf %.3lf\n",x,y,r);
    }
    return 0;
}


Measured memory_bytes: 2124
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

int main() {
    ios::sync_with_stdio(false);
    map<ll, int> G;
    int N;
    cin >> N;
    for (int i = 0;i < N;i++) {
    	int k;
    	cin >> k;
    	G[-k]++;
    }
    ll a = 0;
    ll b = 0;
    for (map<ll, int>::iterator it = G.begin();it != G.end();++it) {
    	int m = it->second;
    	if (m >= 2) {
    		if (a == 0) {
    			a = it->first;
    			m -= 2;
    		}
    	}
    	if (m >= 2) {
    		if (b == 0) {
    			b = it->first;
    		}
    	}
    }
    cout << a * b << endl;
    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, A, B;
  cin >> N >> A >> B;
  cout << min(A, B) << " " << max(0, A + B - N) << '\n';
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

/*
Frog 1 - AtCoder DP

f(i) = min cost to reach i'th stone 
We can get to any (i) stone from i-2 or i-1 stone.
oneS = |h(i)-h(i-1)|
twoS = |h(i)-h(i-2)|
f(i) = min(f(i-1)+OneS, 
            f(i-2)+TwoS)
*/

int main() {
    int n; cin >> n;
    vector<int> arr(n+1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    vector<int> dp(n+1, 0);
    dp[2] = abs(arr[2] - arr[1]);
    for (int i = 3; i <= n; i++) {
        dp[i] = min((dp[i-1] + abs(arr[i]-arr[i-1])),
                                    (dp[i-2]+abs(arr[i]-arr[i-2])));
    }
    cout << dp[n] << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct starrysky{
  int n;
  starrysky(){}
  starrysky(int n_){init(n_);};
  vector<int> data,datm;
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    data.clear();
    datm.clear();
    data.resize(2*n-1,0);
    datm.resize(2*n-1,0);
  }
  void add(int a,int b,int x,int l,int r,int k){
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b){
      data[k]+=x;
      return;
    }
    add(a,b,x,l,(l+r)/2,k*2+1);
    add(a,b,x,(l+r)/2,r,k*2+2);
    datm[k]=min(datm[k*2+1]+data[k*2+1],datm[k*2+2]+data[k*2+2]);
  }
  void add(int a,int b,int x){
    add(a,b,x,0,n,0);
  }
  int query(int a,int b,int l,int r,int k){
    if(r<=a||b<=l) return INT_MAX;
    if(a<=l&&r<=b){
      return data[k]+datm[k];
    }
    return min(query(a,b,l,(l+r)/2,k*2+1),query(a,b,(l+r)/2,r,k*2+2))+data[k];
  }
  int query(int a,int b){
    return query(a,b,0,n,0);
  }
};
#define MAX 333333
string buf;
int dp[MAX],imos[MAX];
signed main(){
  int n,q;
  cin>>n>>q;
  cin>>buf;
  set<int> s;
  for(int i=0;i<n;i++) {
    if(buf[i]=='(') dp[i]=1;
    else dp[i]=-1;
    if(buf[i]==')') s.insert(i);
  }
  imos[0]=dp[0];
  for(int i=1;i<n;i++) imos[i]=imos[i-1]+dp[i];
  starrysky ss(n);
  for(int i=0;i<n;i++) ss.add(i,i+1,imos[i]);
  for(int i=0;i<q;i++){
    int p;cin>>p;p--;
    if(dp[p]==1){
      dp[p]*=-1;
      s.insert(p);
      ss.add(p,n,-2);
      int k=*s.begin();
      s.erase(k);
      dp[k]*=-1;
      ss.add(k,n,2);
      cout<<k+1<<endl;
    }else{
      //cout<<p<<endl;
      dp[p]*=-1;
      s.erase(p);
      ss.add(p,n,2);
      int l=0,r=p;
      while(l+1<r){
	int m=(l+r)/2;
	//cout<<m<<":"<<ss.query(m,n)<<endl;
	if(ss.query(m,n)>=2) r=m;
	else l=m;
      }
      cout<<r+1<<endl;
      dp[r]*=-1;
      s.insert(r);
      ss.add(r,n,-2);
    }
  }
  return 0;
}

Measured memory_bytes: 31432
#include<cstdio>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
const int N=202202;
ll solve(ll x){
	if (x==1)	return 1;
	return 2ll*solve(x/2)+1;
}
int main(){
	ll n;
	scanf("%lld",&n);
	printf("%lld\n",solve(n));
	return 0;
}

Measured memory_bytes: 128
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main(){
	let r = read();
    let x:isize = r[0];
    let y:isize = r[1];
    println!("{}", x+y/2);
}


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

int main(int argc, char const* argv[])
{
  const int dx[] = { -1, 0, 1, 0 };
  const int dy[] = { 0, -1, 0, 1 };

  int N;
  while (true) {
    std::cin >> N;
    if (N == 0)
      break;
    if (N == 1) {
      std::cout << "1 1" << std::endl;
      continue;
    }
    std::vector<std::pair<int, int> > boxes(N);
    boxes[0] = std::make_pair(0, 0);
    for (int i = 1; i < N; ++i) {
      int n, d;
      std::cin >> n >> d;
      boxes[i] = std::make_pair(boxes[n].first + dx[d], boxes[n].second + dy[d]);
    }
    int min_x = 0, min_y = 0, max_x = 0, max_y = 0;
    for (int i = 0; i < N; ++i) {
      int x = boxes[i].first, y = boxes[i].second;
      if (x < min_x)
        min_x = x;
      if (max_x < x)
        max_x = x;
      if (y < min_y)
        min_y = y;
      if (max_y < y)
        max_y = y;
    }
    int w = (max_x - min_x) + 1;
    int h = (max_y - min_y) + 1;
    std::cout << w << " " << h << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1196
S = str(input())
S = S[::-1]
D = ["dream", "dreamer", "erase", "eraser"]
for i, d in enumerate(D):
    D[i] = d[::-1]

can = True
i = 0
while i<len(S):
    can2 = False
    for d in D:
        if S[i:i+len(d)]==d:
            can2 = True
            i += len(d)
    if can2!=True:
        can = False
        break

if can==True:
    print("YES")
else:
    print("NO")




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

struct Edge {
	int to;
	int64_t dist{1};

	// int64_t cost;
	// int from;
	// int rev_i;
};
using EdgeVec = std::vector<Edge>;
using EdgeLists = std::vector<EdgeVec>;

//////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////// ここからコピペ ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

template <typename Metric = int64_t>
class BellmanFord {
private:
	const EdgeLists& edges_;
	const int source_;
	std::vector<Metric> distance_;
public:
	const Metric inf, negative_inf;

	BellmanFord(const EdgeLists& edges, const int source)
		: edges_(edges), source_(source), distance_(edges.size(), std::numeric_limits<Metric>::max()),
		inf(std::numeric_limits<Metric>::max()), negative_inf(std::numeric_limits<Metric>::min())
	{
		distance_[source] = 0;
		for (int loop{}; loop < (int)edges_.size(); loop++)
			for (int now{}; now < (int)edges_.size(); now++)
				if (distance_[now] != inf)
					for (const Edge& next: edges_[now])
						distance_[next.to] = std::min(distance_[next.to], distance_[now] + next.dist);
		
		std::vector<bool> isInCycle(edges_.size());
		std::queue<int> updatedQueue;
		for (int from{}; from < (int)edges_.size(); from++)
			if (distance_[from] != inf)
				for (const Edge& next: edges_[from])
					if (!isInCycle[next.to] && distance_[from] + next.dist < distance_[next.to])
					{
						isInCycle[next.to] = true;
						updatedQueue.push(next.to);
					}
		while (!updatedQueue.empty())
		{
			int now{updatedQueue.front()};
			updatedQueue.pop();
			distance_[now] = negative_inf;
			for (const Edge& next: edges_[now])
				if (!isInCycle[next.to])
				{
					isInCycle[next.to] = true;
					updatedQueue.push(next.to);
				}
		}
	}

	// get distance_
	Metric operator[](const int index) const
	{
		return distance_[index];
	}

	decltype(distance_.begin()) begin() { return distance_.begin(); }
	decltype(distance_.end()) end() { return distance_.end(); }

	bool negativeCycleExists() const
	{
		for (const Metric& dist: distance_)
			if (dist == negative_inf)
				return true;
		return false;
	}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////// ここまでコピペ ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()
{
	int V, E, r;
	scanf("%d%d%d", &V, &E, &r);
	EdgeLists edges(V);
	for (int i{}; i < E; i++)
	{
		int s, t, d;
		scanf("%d%d%d", &s, &t, &d);
		edges[s].push_back({t, d});
	}
	BellmanFord<> bellmanFord(edges, r);
	
	if (bellmanFord.negativeCycleExists())
		puts("NEGATIVE CYCLE");
	else
		for (auto& e: bellmanFord)
			if (e == bellmanFord.inf)
				puts("INF");
			else
				printf("%lld\n", e);
	return 0;
}


Measured memory_bytes: 3244
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;

#define FOUND 1
#define NOT_FOUND -1

bool compare(string s1, string s2){
  if(s1.size() == s2.size()) return s1 < s2;
  return s1.size() < s2.size();
} 

int main(){
  string in, sub;
  string seq;
  bool flag = true;
  while(getline(cin, in)){
    if(!flag && (in.size() == 0 || cin.eof())){
      if(cin.eof()) sub += in;   
      flag = true;
      
      map<char, int > mp;
      set<char> data;

      for(int i = 0 ; i < sub.size() ; i++) data.insert(sub[i]);
      for(int i = 0 ; i < sub.size() ; i++) mp[ sub[i] ] = NOT_FOUND;
      
      int ans = 0;
      int len = (1<<29);
      string ans2;
      
      for(int i = 0 ; i < seq.size() ; i++){
	if(data.find(seq[i]) == data.end()) continue;
	mp[ seq[i] ] = i;
	
	int left = (1<<29);
	bool ok = true;
	for(int j = 0 ; j < sub.size() ; j++){
	  if(mp[ sub[j] ] == NOT_FOUND){
	    ok = false;
	    break;
	  }
	  left = min(left, mp[ sub[j] ]);
	}
	
	if(!ok) continue;
	
	if(i - left == len) ans++;
	if(i - left < len){
	  len = i - left;
	  ans = 1;
	  //cout << "i = " << i << " left = " << left << endl;
	  //cout << i << endl;
	  ans2 = seq.substr(left, i-left+1);
	  //cout << seq.substr(left, i-left+1) << endl;
	}
	
      }
      
      cout << ans << endl << endl;
      if(ans != 0){
	for(int i = 0 ; i < ans2.size() ; i += 72){
	  cout << ans2.substr(i, 72) << endl;
	}
	if(!cin.eof()) cout << endl;
      }

      //cout << "ans_len = " << len << endl;
      //cout << "ans_cnt = " << ans << endl;
      //cout << "seq = " << seq << endl;
      //cout << "sub = " << sub << endl;
      //cout << endl;
      seq = "", sub = "";
      continue;
    }
    else if(flag && in.size() != 0){
      seq += in;
      continue;
    }
    else if(flag && in.size() == 0){
      flag = false;
      continue;
    }
    else if(!flag && in.size() != 0){
      sub += in;
      continue;
    }
  
    

  }
  
  return 0;
}

Measured memory_bytes: 1832
from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]

A_counter = Counter(A)
ans = 0
for A_content in A_counter.values():
  ans += A_content * (A_content-1)//2


for i in range(len(A)):
  dif = 0
  if A_counter[A[i]] > 1:
    dif = A_counter[A[i]] - 1
  print(ans - dif)



Measured memory_bytes: 26780
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
	int map[100][100];
	int dp[100][100];
	
	int X, Y;
	while (scanf("%d %d", &X, &Y), X + Y){
		for (int i = 0; i < 100; i++){
			dp[0][i] = 1;
			for (int j = 1; j < 100; j++){
				dp[j][i] = 0;
			}
		}
		memset(map, 0, sizeof(map));
		
		for (int i = 0; i < Y; i++){
			for (int j = 0; j < X; j++){
				scanf("%d", &map[i][j]);
			}
		}
		
		for (int i = 0; i < Y; i++){
			for (int j = 0; j < X; j++){
				if (map[i][j] == 0){
					for (int k = -1; k <= 1; k++){
						if (j + k >= 0 && j + k < X && (map[i + 1][j + k] == 0 || (k == 0 && map[i + 1][j + k] == 2)) && (i < Y - 1 || k == 0)){
							dp[i + 1][j + k] += dp[i][j];
						}
					}
				}
				else if (map[i][j] == 2){
					dp[i + 2][j] += dp[i][j];
				}
			}
		}
		
		int sum = 0;
		for (int i = 0; i < X; i++){
//			printf("%d ", dp[Y][i]);
			sum += dp[Y][i];
			sum += dp[Y + 1][i];
		}
		
		printf("%d\n", sum);
	}
	
	return 0;
}

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

#define rep(i,n)  for(int i=0;i<n;++i)
#define per(i,n)  for(int i=n-1;i>=0;--i)
#define sc1(a)  scanf("%d",&a)
#define sc2(a,b)  scanf("%d %d",&a,&b)
#define sc3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define sl1(a)  scanf("%lld",&a)
#define sl2(a,b)  scanf("%lld %lld",&a,&b)
#define sl3(a,b,c)  scanf("%lld %lld %lld",&a,&b,&c)
#define PI 3.1415926535897932

int main(){
    int n,m,ans;
    vector <int> d(6);
    for(auto&e:d) sc1(e);
    sc1(n);
    rep(i,n) {
        int a,b;
        sc2(a,b);
        //if ((a==1 && b==2)||(a==2 && b==6)||(a==6 && b==5) || (a==5 && b==1)) {
        if ((a==d[0] && b==d[1])||(a==d[1] && b==d[5])||(a==d[5] && b==d[4]) || (a==d[4] && b==d[0])) {
            printf("%d\n",d[2]);
        } else if ((a==d[0] && b==d[4])||(a==d[4] && b==d[5])||(a==d[5] && b==d[1]) || (a==d[1] && b==d[0])) {
            printf("%d\n",d[3]);
        } else if ((a==d[0] && b==d[3])||(a==d[3] && b==d[5])||(a==d[5] && b==d[2]) || (a==d[2] && b==d[0])) {
            printf("%d\n",d[1]);
        } else if ((a==d[0] && b==d[2])||(a==d[2] && b==d[5])||(a==d[5] && b==d[3]) || (a==d[3] && b==d[0])) {
            printf("%d\n",d[4]);
        } else if ((a==d[2] && b==d[1])||(a==d[1] && b==d[3])||(a==d[3] && b==d[4]) || (a==d[4] && b==d[2])) {
            printf("%d\n",d[5]);
        } else {
            printf("%d\n",d[0]);
        }
    }
    return 0;
}



Measured memory_bytes: 3204
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    string s = read!string;
    string t = s.translate(['A': 'T', 'T': 'A', 'C': 'G', 'G': 'C']);
    writeln(t);
}


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

int main() {
	int n;
	int a[3];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[0] >> a[1] >> a[2];
		sort(a, a + 3);
		if (a[2] * a[2] == a[1] * a[1] + a[0] * a[0]) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 3116
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int K = in.nextInt();

      if (N % K == 0) {
        System.out.println(0);
      } else {
        System.out.println(1);
      }
    }
  }
}

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


int main(){
    string S;
    char C;
    int Q,T,F,a;
    cin >> S >> Q;
    deque<char>str;
    a=S.size();
    for(int i=0; i<a; i++){
        str.push_back(S[i]);
    }
    bool rev=false;
    for(int i=0; i<Q; i++){
        cin >>T;
        if(T==1){
            rev=!rev;

        }
        else{
            cin >> F >> C;
            if(rev){
                F=3-F;
            }
            if(F==1){
                str.push_front(C);
            }
            else{
                str.push_back(C);
            }
        }
    }
    if(rev){
        reverse(str.begin(),str.end());
    }
    a=str.size();
    for (int i = 0; i < a; i++){
        cout << str[i];
    }
    
    cout << endl;

}


Measured memory_bytes: 896
n = int(input())
d = list(map(int, input().split()))
d.sort()
len(d)
len(d)//2
if len(d)%2 == 1:
    print(0)
if len(d)%2 == 0:
    s = d[len(d)//2]-d[len(d)//2-1]
    print(s)


Measured memory_bytes: 14396
void main() {
	auto S_ = rs;
	auto T = rs;
	string res = 'z'.repeat(51).to!string;

	foreach(i; 0..S_.length - T.length + 1) {
		bool flag = true;
		foreach(j; 0..T.length) {
			if(S_[j+i] == '?') continue;
			if(S_[j+i] != T[j]) {
				flag = false;
				break;
			}
		}
		if(flag) {
			string tmp = "";
			foreach(j; 0..S_.length) {
				if(i <= j && j < i + T.length) {
					tmp ~= T[j-i];
				} else {
					tmp ~= (S_[j] == '?' ? 'a' : S_[j]);
				}
			}
			res = min(res, tmp);
		}
	}
	writeln(res == 'z'.repeat(51).to!string ? "UNRESTORABLE" : res);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long int answers[87];

long long int lucas(int n){
  if (answers[n] != -1) return answers[n];
  long long int temp = lucas(n-1) + lucas(n-2);
  answers[n] = temp;
  return temp;
}

int main(){
  	memset(answers, -1, sizeof answers);
	answers[0] = 2;
	answers[1] = 1;
    int n;
    cin >> n;
    
    cout << lucas(n) << endl;
    return 0;
}

Measured memory_bytes: 384
N,M = map(int,input().split())
Data = [0]*M
for _ in range(N):
    fabList = list(map(int,input().split()))
    fabList.pop(0)
    for f in fabList:
        Data[f-1] += 1
ans = 0
for i in range(M):
    if Data[i] == N:
        ans += 1

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#define INF 0x3f3f3f3f
#define int long long
using namespace std;
//typedef long long LL;
const int maxn=1e5+6;
const int mod=1e9+7;
queue<int>q;
int read(){        
    int s = 0, f = 1;        
    char ch = getchar();        
    while(!isdigit(ch)) {        
        if(ch == '-') f = -1;        
        ch = getchar();        
    }        
    while(isdigit(ch)) {        
        s = s * 10 + ch - '0';        
        ch = getchar();        
    }        
    return s * f;        
}    
signed main(){
	int k;
	cin>>k;
	for(int i=1;i<=9;i++)  q.push(i);
	int ans;
	while(k--){
		ans=q.front();
		q.pop();
		if(ans%10!=0)  q.push(ans*10+ans%10-1);
		q.push(ans*10+ans%10);
		if(ans%10<9)   q.push(ans*10+ans%10+1);
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 1000010
int main(){
    int n;
    cin>>n;
    set<ll> t;
    int fl=0;
    while(n--){
        ll x;
        cin>>x;
        if(t.count(x)==0)t.insert(x);
        else fl=1;
    }
    if(fl)cout<<"NO";
    else cout<<"YES";
    return 0;

}

Measured memory_bytes: 9600
#include <stdio.h>

int h,w,c[100][100];
char ban[100][101];

int count(int x, int y) {
   int t,tt,i,j;

   if (c[x][y]>=0) return c[x][y];
   if (x<h-1) {
      if (ban[x][y]==ban[x+1][y]) 
         t=count(x+1,y);
      else 
         if (ban[x][y]=='.')    t=count(x+1,y);
         else                   t=count(x+1,y)+1;
   } else t=9999;
   if (y<w-1) {
      if (ban[x][y]==ban[x][y+1]) tt=count(x,y+1);
      else if (ban[x][y]=='.')    tt=count(x,y+1);
      else                        tt=count(x,y+1)+1;
   } else tt=9999;
   if (t>tt) t=tt;
   c[x][y]=t;
   return t;
}

int main(){
   int i,j,t;

   scanf("%d %d",&h,&w);
   for (i=0;i<h;i++) {
      scanf("%s",ban[i]);
      for (j=0;j<w;j++) c[i][j]=-1;
   }
   if (ban[h-1][w-1]=='.') c[h-1][w-1]=0;
   else                    c[h-1][w-1]=1;
   printf("%d\n",count(0,0));
   return 0;
}


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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define ll  long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi      vector<int>
#define pii     pair<int,int>
#define piii    pair<pair<int,int>,int>
#define all(v)  v.begin(), v.end()

int mod = 1000000007;
const int N = 1005;

// gcd
ll gcd(ll a , ll b)
{
    if ( b == 0)
    return a;
    return gcd( b, a % b);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

    ll ans = 0;
    ll n, k;
    cin >> n >> k;
    if ( k == 0)
    {
        cout << n * n ;
        return 0;
    }
    for ( int b = k + 1; b <= n; b ++)
    {
        ll x = b - k;
        ll y = n / b;
        if ( n % b == 0)
        {
            ans += x * y;
        }
        else
        {
            if ( n % b >= k)
                ans += x * y + n % b - k + 1;
            else
                ans += x * y;
        }
    }
    cout << ans ;
    return 0;
}


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

using namespace std;

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

  int c[n];
  int alg[n][m]={0};

  for(int i=0;i<n;i++){
    cin >> c[i];
    for(int j=0; j<m ; j++){
      cin >> alg[i][j];
    }
  }

  int cost =100000000;
  for( int i=0;i<(1<<n);i++){
    int now_cost = 0;
    int rikai[m] = {0};
    for (int j=0;j<n;j++){
      if (i>>j&1){
        now_cost+=c[j];
        for (int k=0;k<m;k++){
          rikai[k]+=alg[j][k];
        }
      }
      bool check = true;
      for (int j=0;j<m;j++) if (rikai[j]<x) check=false;
      if (check) cost = min(cost,now_cost);
    }

  }
  if (cost ==100000000) cout << -1 << endl;
  else cout << cost << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
int main()
{
	int n, m, x, y, z;
	cin >> n >> m;

  	vector<int> a(m);
    for (int i = 0; i < m; i++) {
      cin >> x;
      z = 0;
	  for (int j = 0; j < x; j++) {
        cin >> y;
        z += (1 << (y - 1));
      }
      a[i] = z;
    }

  	vector<int> b(m);
    for (int i = 0; i < m; i++) {
      cin >> b[i];
    }

    int ggg = 0;
    x = pow(2, n);
    for (int i = 0; i < x; i++) {
      int w = 0;
	  for (int j = 0; j < m; j++) {
        y = a[j] & i; 
        z = 0;
	    for (int k = 0; k < n; k++) {
          if (y & 0x01) {
            z++;
          }
          y >>= 1;
        }
        if (b[j] == (z & 0x01)) {
          w++;
        }
      }
      if (w == m) {
        ggg++;
      }
    }
  
    cout << ggg << endl;
  
	return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main(){
    int n, k;
    cin >> n >> k;
    k = min(k, n-1);
    combination c(n);
    mint ans = 0;
    for(int i = 0; i <= k; i++){
        ans += c(n, i) * c(n-1, i);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    int tmp=0;
    for(int i=0;i<k;i++){
        tmp+=a[i];
    }
    cout<<tmp<<endl;
    return 0;
}

Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
O = input()
E = input()
text = ""
if len(O) == len(E):
    for i in range(len(O)):
        text += O[i] + E[i]
else:
    for i in range(len(O) - 1):
        text += O[i] + E[i]
    text += O[-1]
print(text)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node *Node;

void insert(int);
void Inorder(Node);
void Preorder(Node);
Node find(int);
void delete(int);
Node successor(Node);
Node minimum(Node);

Node root;

int main(){
  char s[10];
  int k, n, i;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    if(i<n)break;
  }
  
  for(i = 0; i < n; i++){
    scanf("%s", s);

    if(s[0] == 'i'){
      scanf("%d", &k);
      insert(k);
    }
    else if(s[0] == 'f'){
      scanf("%d", &k);
      printf(find(k) == NULL ? "no\n" : "yes\n");
    }
    else if(s[0] == 'd'){
      scanf("%d", &k);
      delete(k);
    }
    else{
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }
  }
  
  return 0;
}

void insert(int k){
  Node z, x = root, y = NULL;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NULL;
  z->right = NULL;

  while(x != NULL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NULL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void Inorder(Node u){
  if(u == NULL) return;
  Inorder(u->left);
  printf(" %d", u->key);
  Inorder(u->right);
}

void Preorder(Node u){
  if(u == NULL) return;
  printf(" %d", u->key);
  Preorder(u->left);
  Preorder(u->right);
}

Node find(int k){
  Node x = root;

  while(x != NULL){
    if(k == x->key)
      return x;
    else if(k < x->key)
      x = x->left;
    else
      x = x->right;
  }
  return NULL;
}

void delete(int k){
  Node z, x, y;

  z = find(k);

  if(z->left == NULL || z->right == NULL) y = z;
  else y = successor(z);

  if(y->left != NULL) x = y->left;
  else x = y->right;

  if(x != NULL) x->parent = y->parent;

  if(y->parent == NULL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->key = y->key;
}

Node successor(Node x){
  Node y;
  
  if(x->right != NULL) return minimum(x->right);

  y = x->parent;
  while(y != NULL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

Node minimum(Node x){
  while(x->left != NULL) x = x->left;
  return x;
}



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

typedef long long ll;


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k;
    cin>>k;
    ll sum=0;
    for(int a=1;a<=k;a++){
        for(int b=1;b<=k;b++){
            for(int c=1;c<=k;c++){
                sum+=__gcd(a,__gcd(b,c));
            }
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3652
//@author yash2040
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define pb push_back
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	fast();
	int t=1;
	//0cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		int ans=0;
		for(auto it:s)
		{
			ans+=(it-'0')%9;
		}
		ans=ans%9;
		if(ans==0)
		cout<<"Yes"<<endl;
		else
		cout<<"No"<<endl;
	}
}








Measured memory_bytes: 3780