akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <climits>
#include <functional>

using std::string;
using std::cout;
using std::cin;
using std::vector;
using ull = unsigned long long;
using ll = long long;
using std::pair;
int main(){
    ull n;
    cin >> n;
    string s;
    vector<pair<ll,ll>> a0;
    vector<pair<ll,ll>> a1;
    ll total_parenth = 0;
    for(ull i=0; i<n; i++){
        cin >> s;
        ll bottom=0, l=0,total=0;
        for(int m=0; m<s.size(); m++){
            if(s[m]=='('){
                total++;
                total_parenth++;
            }else{
                total--;
                total_parenth--;
            }
            bottom = std::min(bottom, total);
        }
        // a.push_back(pair(total,pair(l,r)));
        if(total>=0){
            a0.emplace_back(bottom, total);
        }else{
            a1.emplace_back(-total+bottom,-total);
        }

    }


    // # of '(' == # of ')' -> false:No
    if(total_parenth!=0LL){
        cout << "No\n";
        return 0;
    }
    std::sort(a0.rbegin(), a0.rend());
    std::sort(a1.rbegin(), a1.rend());

    ll now = 0;
    for(int i=0; i<a0.size(); i++){
        
        if(now+a0[i].first < 0){
            cout << "No\n";
            return 0;
        }
        now += a0[i].second;
    }
    now = 0;
    for(int i=0; i<a1.size(); i++){
        
        if(now+a1[i].first < 0){
            cout << "No\n";
            return 0;
        }
        now += a1[i].second;
    }
    cout << "Yes\n";

    return 0;
}

Measured memory_bytes: 19000
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
const double EPS = 1e-10;
double X[210];
double Y[210];
double U[210];
double V[210];
double ABS(double a){return max(a,-a);}
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%lf%lf%lf%lf",X+i,Y+i,U+i,V+i);
	}
	int ret=1;
	for(int i=0;i<a;i++){
		int cnt=0;
		for(int j=0;j<a;j++){
			if(ABS(X[i]-X[j])<EPS&&ABS(Y[i]-Y[j])<EPS&&ABS(U[i]-U[j])<EPS&&ABS(V[i]-V[j])<EPS){
				cnt++;
				continue;
			}
			vector<double>t;
			double x1=X[j]-X[i];
			double Y1=Y[j]-Y[i];
			double u1=U[j]-U[i];
			double v1=V[j]-V[i];
			int now=2;
			for(int k=0;k<a;k++){
				if(k==i||k==j)continue;
				double x2=X[k]-X[i];
				double y2=Y[k]-Y[i];
				double u2=U[k]-U[i];
				double v2=V[k]-V[i];
				double A=u1*v2-u2*v1;
				double B=u1*y2+x1*v2-v1*x2-Y1*u2;
				double C=x1*y2-Y1*x2;
				if(ABS(A)>EPS){
					if(B*B-4*A*C>EPS){
						t.push_back((-B+sqrt(B*B-4*A*C))/A/2);
						t.push_back((-B-sqrt(B*B-4*A*C))/A/2);
					}else if(B*B-4*A*C>-EPS){
						t.push_back(-B/A/2);
					}
				}else if(ABS(B)>EPS){
					t.push_back(-C/B);
				}else{
					if(ABS(C)<EPS)now++;
				}
			}
			std::sort(t.begin(),t.end());
			int has=0;
			ret=max(ret,now);
			for(int k=0;k<t.size();k++){
				if(t[k]<-EPS)continue;
				if(k==0||ABS(t[k]-t[k-1])<EPS)has++;
				else has=1;
				if(ABS(X[i]+U[i]*t[k]-X[j]-U[j]*t[k])>EPS||ABS(Y[i]+V[i]*t[k]-Y[j]-V[j]*t[k])>EPS){
					ret=max(ret,now+has);
				}else{
					int tmp=0;
					for(int l=0;l<a;l++){
						if(ABS(X[i]+U[i]*t[k]-X[l]-U[l]*t[k])<EPS&&ABS(Y[i]+V[i]*t[k]-Y[l]-V[l]*t[k])<EPS)tmp++;
					}
					ret=max(ret,tmp);
				}
			}
		}
		ret=max(ret,cnt);
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 1100
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int a,b,c;
    while (scanf("%d%d%d",&a,&b,&c)!=EOF)
    {
        if(a+b>=c)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#define MOD 1000000007
typedef long long ll;
using namespace std;

map<pair<int,int>,int> mp;

int find(int x,int *w){
  if(w[x]==x) return x;
  else return w[x]=find(w[x],w);
}

int main(){
  int n,k,l;
  cin>>n>>k>>l;
  int a[n+1],b[n+1];
  for(int i=1;i<=n;i++){
    a[i]=i;
    b[i]=i;
  }
  int p,q,r,s;
  for(int i=1;i<=k;i++){
    cin>>p>>q;
    p=find(p,a);
    q=find(q,a);
    if(p!=q) a[p]=q;
  }

  for(int i=1;i<=l;i++){
    cin>>r>>s;
    r=find(r,b);
    s=find(s,b);
    if(r!=s) b[r]=s;
  }

  int u,v;
  for(int i=1;i<=n;i++){
    u=find(i,a);
    v=find(i,b);
    mp[{u,v}]++;
  }
  for(int i=1;i<=n;i++){
    u=find(i,a);
    v=find(i,b);
    cout<<mp[{u,v}]<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 13568
#include <stdio.h>

int main(void){
    int w,h;

    scanf("%d %d", &h, &w);
    while (w!=0 || h!=0){
        for (int i=0; i<h; i++){
            for (int j=0; j<w; j++){
                if ((i+j) % 2 == 0) printf("#");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
        scanf("%d %d", &h, &w);
    }
    return 0;
}

Measured memory_bytes: 1000
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <math.h>
using namespace std;
//for (int i = 0; i < N; i++){}

int main() {
    int N;
    long long x;
	cin >> N >> x;
    long long a[N];

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

    long long res = 0;
    long long j, j1;
    for (int i = 0; i < N-1; i++){
        if((a[i]+a[i+1]) > x){
            j = a[i+1] + a[i] - x;
            j1 = a[i+1];
            if(j>a[i+1]){
                a[i+1] = 0;
                a[i] = j - j1;
            }else{
                a[i+1] = x - a[i];
            }
            res += j;
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-9;

ll d[200000];
vector<edge> G[200000];
vector<string> st;

void f(int u, int v, ll w) {
	edge e = {u, v, w};
	G[u].push_back(e);
}

int g(string s) {
	return lower_bound(st.begin(), st.end(), s) - st.begin();
}

void dijkstra(int n, vector<edge> G[], int s, ll d[]) {
	fill(d, d + n, LLONG_MAX); d[s] = 0;
	priority_queue<ll_i, vector<ll_i>, greater<ll_i> > q;
	q.push(ll_i(0, s));
	while (!q.empty()) {
		ll_i p = q.top(); q.pop();
		int u = p.second;
		if (p.first > d[u]) continue;
		for (int i = 0; i < G[u].size(); i++) {
			edge e = G[u][i];
			if (d[e.v] > d[u] + e.w) {
				d[e.v] = d[u] + e.w;
				q.push(ll_i(d[e.v], e.v));
			}
		}
	}
}

int main() {
	int N, T; cin >> N >> T;
	string A, B; cin >> A >> B;
	vector<int> a(N);
	vector<vector<string> > s(N);
	vector<vector<int> > t(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		s[i].resize(a[i]);
		for (int j = 0; j < a[i]; j++)
			cin >> s[i][j];
		t[i].resize(a[i] - 1);
		for (int j = 0; j + 1 < a[i]; j++)
			cin >> t[i][j];
	}
	st.push_back(A);
	st.push_back(B);
	for (int i = 0; i < N; i++)
		for (int j = 0; j < a[i]; j++)
			st.push_back(s[i][j]);
	sort(st.begin(), st.end());
	st.erase(unique(st.begin(), st.end()), st.end());
	int n = st.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < a[i]; j++) {
			int u = g(s[i][j]);
			f(u, n + j, T*1000000+1);
			f(n + j, u, 0);
		}
		for (int j = 0; j + 1 < a[i]; j++) {
			f(n + j, n + j + 1, t[i][j]*1000000);
			f(n + j + 1, n + j, t[i][j]*1000000);
		}
		n += a[i];
	}
	dijkstra(n, G, g(A), d);
	ll ans = d[g(B)];
	if (ans == LLONG_MAX) {
		cout << -1 << endl;
		return 0;
	}
	cout << ans / 1000000 - T << ' ' << ans % 1000000 - 1 << endl;
}

Measured memory_bytes: 29648
#include <iostream>
using namespace std;
int main()
{
    int x,y,tmp;
    cin >> x >> y;
    if(x<y)
    {
        tmp=x;
        x=y;
        y=tmp;
    }

    while(y>0)
    {
        tmp=y;
        y=x%y;
        x=tmp;
    }
    cout << x <<endl;
    return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;

int main()
{
  int n;
  cin >> n;
  int num = 0;
  for(int i = 0; i < n; i++){
    int l, r;
    cin >> l >> r;
    num += r - l + 1;
  }
  
  cout << num << endl;
}

Measured memory_bytes: 256
/* written by : vipin kumar */
#include<iostream>
using namespace std;
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#define int long long int
#define mod 1000000007
int32_t main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     int a;
     cin>>a;
     int answer=a+a*a+a*a*a;
     cout<<answer<<endl;
}


Measured memory_bytes: 3636
import java.util.*;

class Main {
	public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        
        int limit;  //n
        int answer; //正解の合計
        int count  = 0;  //組み合わせ数

        while(true){
            limit = sc.nextInt();
            answer = sc.nextInt();

            if(limit == 0 && answer == 0)   break;
            count = 0;
            for(int i = 1;i <= limit - 2;i++){
                for(int j = i + 1;j <= limit - 1;j++){
                    for(int k = j + 1;k <= limit;k++){
                        if((i+j+k) == answer) count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
}



Measured memory_bytes: 26772
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	int n; cin >> n;
	vector<int> p(n);
	rep(i, n) cin >> p[i];

	int ans = 0;
	int m = p[0];

	rep(i, n) {
		if (p[i] <= m) ans++;
		m = min(m, p[i]);
	}

	dunk(ans);
	return 0;
}


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

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

  ll N; cin >> N;
  ll M; cin >> M;
  vector<ll> l(M, 0), r(M, 0);

  if (M % 2 == 0) {
    for (ll i = 0; i < N; i++) {
      if ((i + 1) >= M - i) break;
      l[i] = i + 1;
      r[i] = M - i;
    }
    for (ll i = 0; i < N; i++) {
      if ((M + i + 1) >= 2 * M + 1 - i) break;
      l[i + M / 2] = M + i + 1;
      r[i + M / 2] = 2 * M + 1 - i;
    }
  } else {
    for (ll i = 0; i < N; i++) {
      if ((i + 1) >= M + 1 - i) break;
      l[i] = i + 1;
      r[i] = M + 1 - i;
    }
    for (ll i = 0; i < N; i++) {
      if ((M + i + 2) >= 2 * M + 1 - i) break;
      l[i + (M + 1) / 2] = M + i + 2;
      r[i + (M + 1) / 2] = 2 * M + 1 - i;
    }
  }

  for (ll i = 0; i < M; i++) {
    cout << l[i] << ' ' << r[i] << '\n';
  }
  return 0;
}

Measured memory_bytes: 4388
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<map>
using namespace std;
const int maxn = 2e5 + 5;
int n;
int a[maxn];
map<int,int>s;
bool isok(int mid) {
	s.clear();
	for(int i=2;i<=n;i++) {
		if(a[i]<=a[i-1]) {
			while(!s.empty()&&((s.rbegin()->first) )>a[i]) {
				s.erase(--s.end());
			}
			for(int j=a[i];j>=1;j--) {
				if(s[j]+1==mid) {
					s.erase(j);
				} else {
					s[j]++; break;
				}
				if(j==1) return 0;
			}
		}
	}
	return 1;
}
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
	}
	bool fl = 1;
	for(int i=2;i<=n;i++) {
		if(a[i]<=a[i-1]) {
			fl = 0; break;
		}
	}
	if(n==1||fl) {
		puts("1"); return 0;
	}
	int L = 2; int R = n,mid,ans;
	while(L<=R){
		mid = (L+R)>>1;
		if(isok(mid)) ans = mid , R = mid - 1;
		else L = mid + 1;
	}
	printf("%d",ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());




int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    bool da = 1;
    bool win = 0;
    while(1){
        if(a <= 0){
            break;
        }
        if(c <= 0){
            win = 1;
            break;
        }
        if(da){
            da = 0;
            c -= b;
        }
        else{
            da = 1;
            a -= d;
        }
    }
    if(win)cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define db double
#define ld long double
#define IOS  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#pragma GCC optimize(2)
#define ull unsigned long long
#define maxn 1020
ll lcm(ll a,ll b){return a*b/__gcd(a,b);}
signed main()
{
    IOS
    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z;
    return 0 ;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,i,j,v[26];
	char c;
	bool flag;
	cin >> n;
	while(n){
		flag = false;
		for(j=0; j<26; ++j){
			v[j] = 0;
		}
		for(i=1; i<=n; ++i){
			cin >> c;
			if(flag){
				continue;
			}
			c -= 'A';
			++v[c];
			flag = true;
			for(j=0; j<26; ++j){
				if(v[j]>v[c]){
					c = j;
				}
			}
			for(j=0; j<26; ++j){
				if(j==c){
					continue;
				}
				if(v[j]+(n-i)>=v[c]){
					flag = false;
					break;
				}
			}
			if(flag){
				cout << (char)(c+'A') << " " << i << endl;
			}
		}
		if(!flag){
			cout << "TIE" << endl;
		}
		cin >> n;
	}
	return 0;
}



Measured memory_bytes: 3052
H, W, K = map(int, input().split())
S = [input() for h in range(H)]

# 横の割り方を全通り試す(2**(H-1))
ans = float('inf')
for i in range(2**(H-1)):
    _ans = bin(i).count('1')
    chocos = [list(map(int, S[0]))]
    for j in range(H-1):
        if i >> j & 1:
            chocos.append(list(map(int, S[j+1])))
        else:
            for w in range(W):
                chocos[-1][w] += int(S[j+1][w])
    
    ns = len(chocos)
    nums = [0] * ns
    is_next = False
    flag = False
    for w in range(W):
        for j in range(ns):
            nums[j] += chocos[j][w]
            if chocos[j][w] > K:
                _ans = float('inf')
                flag = True
                break
            if nums[j] > K:
                _ans += 1
                is_next = True
                break
        if flag:
          flag = False
          break        
        if is_next:
            for j in range(ns):
                nums[j] = chocos[j][w]
            is_next = False
    
    ans = min(ans, _ans)

print(ans)

Measured memory_bytes: 52444
n,m=map(int,input().split())
l=[]
for i in range(n):
    a=list(map(str,input().split()))
    v=int(a[0])
    a.pop(0)
    for i in range(v):
        l.append(a[i])
s=[]
i=0
while i<m:
    i+=1
    i=str(i)
    s.append(l.count(i))
    i=int(i)
print(s.count(n))

Measured memory_bytes: 3064
n=int(input())
inp=[]
for i in range(n):
	inp.append(input().split())



cllist=list(range(1,53))


for i in inp:
	cl,rank= i[0],int(i[1])
	if cl=="S":
		cllist.remove(rank)
	elif cl=="H":
		cllist.remove(rank+13)
	elif cl=="C":
		cllist.remove(rank+26)
	elif cl=="D":
		cllist.remove(rank+39)

for i in cllist:
	if 0< i and i < 14:
		print(f"S {i}")
	elif 13 < i and i< 27:
		print(f"H {i-13}")
	elif 26 < i and i< 40:
		print(f"C {i-26}")
	elif 39 < i:
		print(f"D {i-39}")




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

#define lld long long
#define pp pair<int,int>
#define pb push_back
#define MOD 10007
#define left lleft
#define right rright
#define INF 2000000000
#define LINF 1000000000000000000LL
#define next nnext

using namespace std;

int d[102][102];
lld X,Y;

void dfs(int x,int y){
	if(d[x][y] != 0) return;
	d[x][y] = 2;
	for(int i=1; i*2<=x; i++){
		dfs(x-i*2,y+i);
		if(d[x-i*2][y+i] == 2){
			d[x][y] = 1;
			return;
		}
	}
	for(int i=1; i*2<=y; i++){
		dfs(x+i,y-i*2);
		if(d[x+i][y-i*2] == 2){
			d[x][y] = 1;
			return;
		}
	}
}

int main(){
	scanf("%lld %lld",&X,&Y);
	if(abs(X-Y) <= 1) puts("Brown");
	else puts("Alice");

	return 0;
}


Measured memory_bytes: 256
'use strict';
(function(stdin) {
    var inputs = stdin.toString();
    var cols = inputs.split('\n')[0].split(' ').map(Number);
    var a = cols[0];
    var b = cols[1];
    var c = cols[2];
    if (a < b && b < c) {
        console.log('Yes');
    } else {
        console.log('No');
    }
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7380
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <list>
#include <stack>

using namespace std;

/* constant */

const int INF = 1 << 30;
const int mod = 1000000007;

/* typedef */

typedef long long ll;

/* global variables */
vector<int> v(4, 0);

/* function */
bool judge(int x, int y, int z);

/* main */
int main() {

    while (1) {
        int a, b, c; cin >> a >> b >> c;
        if (a < b) swap(a, b);
        if (b < c) swap(b, c);
        if (a < b) swap(a, b);

        if (!judge(a, b, c)) {
            cout << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' << v[3] << '\n';
            return 0;
        }
    }

}

bool judge(int x, int y, int z) {

    bool triangle = true;

    if (x >= y + z or y >= x + z or z >= x + y) {
        triangle = false;
    }
    else {
        v[0]++;
        int A = y * y + z * z - x * x;
        if (A == 0) {
            v[1]++;
        }
        else if (A > 0) {
            v[2]++;
        }
        else {
            v[3]++;
        }
    }

    return triangle;
}



Measured memory_bytes: 3120
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int n;
	cin >> n;
	
	REP(_, n) {
		string o, m;
		cin >> o >> m;

		int size = m.size();
		REP(i, o.size()) {
			string nm = m;

			switch(o[o.size()-i-1]) {
			case 'J':
				REP(j, size) {
					nm[(j+1)%size] = m[j];
				}
				break;
			case 'C':
				REP(j, size) {
					nm[j] = m[(j+1)%size];
				}
				break;
			case 'E':
				if(size%2) {
					REP(j, size/2) {
						nm[j] = m[j+size/2+1];
						nm[j+size/2+1] = m[j];
					}
				} else {
					REP(j, size) {
						nm[j] = m[(j+size/2)%size];
					}
				}
				break;
			case 'A':
				REP(j, size) {
					nm[j] = m[size-j-1];
				}
				break;
			case 'M':
				REP(j, size) {
					if('0' <= m[j] && m[j] <= '8') {
						nm[j]++;
					} else if(m[j] == '9') {
						nm[j] = '0';
					}
				}
				break;
			case 'P':
				REP(j, size) {
					if('1' <= m[j] && m[j] <= '9') {
						nm[j]--;
					} else if(m[j] == '0') {
						nm[j] = '9';
					}
				}
				break;
			}

			m = nm;
		}
		cout << m << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    ll x;
    cin >> x;
    if(x==3 || x==5 || x==7){
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void){
    int a,b;
    long double h,m,deg;
    scanf("%d %d %Lf %Lf",&a,&b,&h,&m);
    deg=2*3.141592653589793238462643383*(h/12+m/60/12-m/60);
    printf("%20.20f",sqrt(a*a+b*b-2*a*b*cos(deg)));
}

Measured memory_bytes: 2524
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


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

//Ctrl+Aを使わない

Measured memory_bytes: 256
N, L = map(int, input().split())

true_pie = (2 * L + N - 1) * N // 2
min_diff = None
answer = None
for i in range(1, N + 1):
    apple = L + i - 1
    pie = (2 * L + N - 1) * N // 2 - apple
    diff = abs(true_pie - pie)
    
    if (min_diff is None) or (diff <= min_diff):
        min_diff = diff
        answer = pie

print(answer)

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

	string s;
	cin >> s;

	if (s=="Sunny") {
		cout << "Cloudy" <<endl;
		return 0;
	} 

	if (s=="Cloudy") {
		cout << "Rainy" <<endl;
		return 0;
	} 
	if (s=="Rainy") {
		cout << "Sunny" <<endl;
		return 0;
	} 

}

Measured memory_bytes: 256
#if __has_include("D:/dhiraj/Programming/debug.h")
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
#endif

// Loops --------------------------------------------------------------------

#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)

// Extra --------------------------------------------------------------------

#define ull                 unsigned long long int
#define ll                  long long int
#define ld                  long double
#define endl                '\n'
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()

// Template -----------------------------------------------------------------

template <typename T> 
inline bool inrange(T a, T l, T r) {
    if(l>r) swap(l,r);
    return (a>=l and a<=r);
}
template <typename T, typename U> 
inline bool exist(T val, U &any) {
    return (any.find(val) != any.end());
}
// multiple input
template <typename T> 
inline void inp(T &any) {
    cin >> any;
}
template <typename T, typename... U> 
inline void inp(T &a, U &...b) {
    cin >> a; inp(b...);
}
// scan vector
template <typename T> 
inline istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream &operator>>(istream &in, pair<T,U> &a) {
    in >> a.first >> a.second; 
    return in;
}

// Solve --------------------------------------------------------------------

void solve(ll &T)
{
    ll n;
    std::cin>>n;

    double x = 100;
    ll year = 0;
    while(x<n)
    {
        // d(x);
        x += (ll)(x/100);
        year++;
    }
    std::cout<<year<<endl;
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int t = 1;
    loop(i,1,t+1)
    {
        cerr<<"Case #"<<i<<"\n";
        solve(i);
    }
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
#define MN 605
pair<int,int> mp[MN<<1];
int N,D1,D2,cc;
bool col[MN][MN][2];
struct node{int x,y;};
vector<node> G[5];
void solve(int D,int l){
	register int i,j,k,ct=0,squ=1;
	while(~D&1){ct++;D>>=1;}
	squ=1<<(ct>>1);
	if(~ct&1){
		for(i=0;i<N*2;i++)for(j=0;j<N*2;j++)col[i][j][l]=((i/squ)+(j/squ))&1;
	}
	else{
		for(i=0;i<N*2;i++)for(j=0;j<N*2;j++) col[i][j][l]=(i/squ)&1;
	}
}
int main(){
	register int i,j;
	N=read(),D1=read(),D2=read();
	solve(D1,0),solve(D2,1);
	for(i=0;i<N<<1;i++)for(j=0;j<N<<1;j++)
	G[col[i][j][0]+col[i][j][1]<<1].push_back((node){i,j});
	for(i=0;i<4;i++)if(G[i].size()>=N*N){
		for(j=0;j<N*N;j++) printf("%d %d\n",G[i][j].x,G[i][j].y);
		return 0;
	}
	return 0;
}

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

const int maxn=4e5+10;

int n,k,H,T;
bool rev,a[maxn];

int main()
{
#ifdef h10
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
#endif
	int i;
	char c;
	scanf("%d%d",&n,&k);
	for (i=1;i<=n;i++)
	{
		c=getchar();
		while (c!='A'&&c!='B') c=getchar();
		a[i]=c=='A';
	}
	H=1; T=n; rev=0;
	for (i=1;i<=k&&T<n+n;i++)
	{
		if ((a[H]^rev)==1) {a[H]^=1; continue;}
		H++; T++; rev^=1; a[T]=rev^1;
	}

	if (i>k)
	{
		for (i=H;i<=T;i++)
			putchar(a[i]^rev?'A':'B');
		return 0;
	}
	if ((a[H]^rev)==0)
	{
		for (i=1;i<=n;i++)
			putchar(i&1?'B':'A');
		return 0;
	}
	else
	{
		if ((k-i+1)&1)
		{
			for (i=1;i<=n;i++)
				putchar((i&1)&&i!=1?'A':'B');
		}
		else
		{
			for (i=1;i<=n;i++)
				putchar(i&1?'A':'B');
		}
	}
}


Measured memory_bytes: 768
// #define __LOCAL_DEBUG__
#include<bits/stdc++.h>
using namespace std;
#ifdef __LOCAL_DEBUG__
# define _debug(x) { cerr << "\033[94m" << __func__ << " " << #x << ": " << (x) << "\n\033[0m"; }
#else
# define _debug(...) {((void) 0);}
#endif
#define REP(i, n) for (int i = (0); i < (n); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define EACH(x, arr) for (auto& x : arr) 
#define ITR(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define CLR(x, v) memset(x, v, sizeof (x))
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
using LL = long long;
using PII = pair<int, int>;
using VI = vector<int>;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 5005;

int n, m;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
void MAIN() {
    cin >> n;
    int g = 0;
    REP(i, n) {
        int x;
        cin >> x;
        g = gcd(g, x);
    }
    cout << g << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int TC = 1;
    // cin >> TC;
    REP(tc, TC) {
        // cout << "Case " << tc + 1 << ": ";
        MAIN();
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define For( i , a ) for(int i=1;i<=a;i++)
#define ort (b+s)/2
#define y2 asrwjaelkf
#define y1 asseopirwjaelkf
#define set multiset

using namespace std;

typedef long long Lint;
typedef double db;
typedef pair<int,int> ii;
typedef pair<int,char> ic;
typedef pair<db,db> dd;
typedef pair<ii,int> iii;
typedef pair<ii,ii> i4;

const int maxn = 100020;
const int maxm = 1000020;
const int MOd = 998244353;


int main() {

    //freopen("asd.in","r",stdin);
    //freopen("output17.txt","w",stdout);
    int a;
    string s;
    scanf("%d",&a);
    cin >> s;
    if( a >= 3200 ) cout << s << endl;
    else cout << "red" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fr first
#define se second

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

int N,M;
string S;

signed main(){
  cin>>N>>M;
  if(M>=N)print("unsafe")
  else print("safe")
  
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long N = scn.nextLong();
		int ans = 0;
		long A = 1;
		for(long i = (long)Math.sqrt(N);i > 0;i--) {
			if(N%i==0) {
				A = N/i;
				break;
			}
		}

		while(A >0) {
			ans++;
			A/=10;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 25172
#include<stdio.h>

int main(){
  long long n;
  long long bulb[5];
  long long count = 0;
  int i;
  long long min;

  scanf("%lld",&n);
  scanf("%lld%lld%lld%lld%lld",&bulb[0],&bulb[1],&bulb[2],&bulb[3],&bulb[4]);

  min = bulb[0];
  for(i = 1; i < 5; i++){
    if(min >= bulb[i])min = bulb[i];
  }

  count = n/min;

  if(n%min != 0){
    count += 5;
  }
  else{
    count += 4;
  }

  printf("%lld",count);
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>

using namespace std;
typedef long long LL;
LL a,b;
int main(){
    scanf("%lld%lld",&a,&b);
    if(a==1||b==1){
        printf("1");
        return 0;
    }
    if((a*b)%2){
        printf("%lld",(a*b)/2+1);
    }
    else printf("%lld",a*b/2);
    return 0;
}


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

const ll mod = 1e9 + 7;


ll modExpo(ll a, ll b, ll m) {
	ll ans = 1;
	a = a % m;
	while (b > 0) {
		if (b & 1) ans = (ans * a) % m;
		b >>= 1;
		a = (a*a) % m;			
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n, ans = 0;
	cin >> n;
	ans = ans + modExpo(10, n, mod);
	ans = (ans - modExpo(9, n, mod) + mod) % mod;
	ans = (ans - modExpo(9, n, mod) + mod) % mod;
	ans = (ans + modExpo(8, n, mod)) % mod;
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3648
import math
N = int(input())
A = [int(x) for x in input().split()]
s = sum(A)
if s % N== 0:
    ave = s // N
    ans = [(x - ave)**2 for x in A]
    ans = sum(ans)
    print(ans)
    exit()
else:
    ave1, ave2 = math.ceil(s / N), math.floor(s / N)
    ans1 = [(x - ave1)**2 for x in A]
    ans2 = [(x - ave2)**2 for x in A]
    ans = min(sum(ans1), sum(ans2))
    print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<math.h>
#define ll long long int
#define l(i,a,b) for(ll i =a;i<b;i++)
#define PI 3.14159265358979323846264338327950
using namespace std;
int main(){
	ll n;
	cin>>n;
	cout<<(n/500)*1000+(n%500)/5 * 5<<"\n";
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>
int asc(const void *a,const void *b)
{
	return *(int *)a-*(int *)b;
}
int main()
{
	unsigned long long int n;
	scanf("%lld",&n);
	unsigned long long int i;
	int a[100005],b[100005],c[100005];
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
		scanf("%d",&b[i]);
	for(i=0;i<n;i++)
		scanf("%d",&c[i]);
	qsort(a,n,sizeof(int),asc);
	qsort(b,n,sizeof(int),asc);
	qsort(c,n,sizeof(int),asc);
	a[n]=2000000000;
	c[n]=2000000000;
	unsigned long long int j,k;
	unsigned long long int ans=0;
	i=j=k=0;
	while(a[i]>=b[j] && j<n)
		j++;
	for(;j<n;j++)
	{
		while(a[i]<b[j])
			i++;
		while(b[j]>=c[k])
			k++;
		ans+=i*(n-k);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,k;
	cin>>n>>k;
	ll ar[n];
	for(ll i=0;i<n;i++)cin>>ar[i];
	ll ans[n];
	ans[n-1]=0;
	for(ll i=n-2;i>=0;i--)
	{
		ll a=999999999;
		for(ll j=i+1;j<n &&j<=i+k;j++)
		{
			a=min(a,max(ar[i]-ar[j],ar[j]-ar[i])+ans[j]);
		}
		ans[i]=a;
	}
	cout<<ans[0];
	return 0;
}

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

const int INF = 1001001001;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, 0, n) cin >> a[i] >> b[i] >> c[i];
    vector<vector<int>> dp(n, vector<int> (3, -INF));
    dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0];
    rep(i, 0, n-1){
        dp[i+1][0] = max(dp[i+1][0], max(dp[i][1] + a[i+1], dp[i][2] + a[i+1]));
        dp[i+1][1] = max(dp[i+1][1], max(dp[i][0] + b[i+1], dp[i][2] + b[i+1]));
        dp[i+1][2] = max(dp[i+1][2], max(dp[i][0] + c[i+1], dp[i][1] + c[i+1]));
    }
    int mx = 0;
    rep(i, 0, 3){
        mx = max(mx, dp[n-1][i]);
    }
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 6912
#include<stdio.h>

int main(){

  int i;
  int length;
  
  scanf("%d",&length);

  int A[length];

  for (i = 0 ; i < length ; i++){
    scanf("%d",&A[i]);
  }

  int flag = 1;
  int j;
  int tmp;
  int counter = 0;
  

  while (flag){
    flag = 0;
    for(j = length - 1 ; j > 0 ; j-- ){
      if( A[j] < A[j - 1] ){

	tmp = A[j];
	A[j] = A[j - 1];
	A[j - 1] = tmp;

	flag = 1;
	counter++;
      }
    }
  }


  for(i = 0 ; i < length ; i++){
    printf("%d",A[i]);
    if(i < length - 1)printf(" ");
  }
  
  printf("\n");

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



Measured memory_bytes: 2140
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ll N, M, V, P;
	cin >> N >> M >> V >> P;

	vector <ll> A(N);
	for (int ii = 0; ii < N; ++ii){
		cin >> A[ii];
	}

	//大きい順にソート
	sort(A.rbegin(), A.rend());
	A.push_back(1e10);	//最後にダミーを追加

	ll borderScore = A[P-1];	//ボーダーのスコア

	//(スコア，人数)のベクタを作成
	vector <pair<ll, ll>> B;
	ll prevScore = A[0];
	ll prevNum = 1;
	for (int ii = 1; ii < A.size(); ++ii){
		if (A[ii] == prevScore){
			prevNum++;
		} else {
			B.push_back(make_pair(prevScore, prevNum));
			prevScore = A[ii];
			prevNum = 1;
		}
	}

	//トップグループ，ボーダーグループの数を計算
	ll topNum = 0;
	ll borderNum = 0;
	ll outOfBorderIdx = 0;
	for (int ii = 0; ii < B.size(); ++ii){
		if (B[ii].first > borderScore){
			topNum += B[ii].second;
		} else if (B[ii].first == borderScore) {
			borderNum += B[ii].second;
		} else {
			outOfBorderIdx = ii;
			break;
		}
	}

	//自分以下のグループに含まれる総数を計算
	vector <ll> lowerNum(B.size());
	ll cnt = 0;
	for (int ii = 0; ii < B.size(); ++ii){
		lowerNum[ii] = N - cnt;
		cnt += B[ii].second;
	}


	ll ans = topNum + borderNum;
	//ボーダーより下の問題が採用されうるかどうか判定
	ll total = 0;
	for (int ii = outOfBorderIdx; ii < B.size(); ++ii){
		ll boxNum = N - (P - 1 + lowerNum[ii]);
		if (boxNum == 0) {
		} else {
			if (ii == outOfBorderIdx){
				ll tmp = topNum + borderNum - (P - 1);
				total += B[ii-1].first * tmp;
			} else {
				total += B[ii-1].first * B[ii-1].second;
			}

			ll cnt = max(0LL, V - (N - boxNum));
			ll tmpTotal = total + cnt * M;
			ll tmpScore = (tmpTotal + boxNum - 1) / boxNum;

			ll refScore = max(borderScore, tmpScore);
			ll score = B[ii].first + M;	//ボーダーより下の問題のスコア

			if (score >= refScore){
				ans = ans + B[ii].second;
			}
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 4084
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

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

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

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

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}
void solve() {
    /*
   ll n,m;
   cin >> n >> m;
   bool a[n+1];
   rep(i,0,m) a[i] = false;
   ll tmp;

   rep(i,0,m){
       cin >> tmp;
       a[tmp] = true;
   }
   ll dp[n+1];
   rep(i,0,n+1) dp[i] = 0;

   dp[0] = 1;
   for(ll i = 0;i < n;i++){
       for(ll j = i+1;j <= min(n,i+2);j++){
        if(!a[j]){
               dp[j] += dp[i];
               dp[j] %= MOD;
            }
       }
    }

   cout << dp[n] << endl;
   */

  ll n,m;
  cin >> n >> m;
  vector<ll> k(m),p(m);
  vector<vector<ll>> s(m);
  rep(i,0,m){
      cin >> k[i];
      rep(j,0,k[i]){
          ll a;
          cin >> a;
          a--;
          s[i].push_back(a);
      }
  }
  rep(i,0,m) cin >> p[i];
  int ans = 0;
  //スイッチがn個あるので,2^n通り.n <= 10より,ビット全探索する.
  
  for(int i = 0;i < (1<<n);i++){
      bool o = true;
      for(int j = 0;j < m;j++){
          int c = 0;
          for(int p = 0;p< k[j];p++){
              //スイッチがオンになっている部分の個数を求める.
              if((i >> s[j][p]) & 1){
                  c++;
              }
          }
          c%=2;
          if(c!=p[j]){
              o = false;
          }
      }
      if(o){
          ans++;
      }
  }
  
  cout << ans << endl;
}
/*
20log10(sqrt(1+100w^2))
if w = 10

(10001) = 100
*/
int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int cnt2(int n){
	int res = 0;
	while(n > 0){
		if (n % 2 != 0) break;
		n /= 2;
		++res;
	} // end while

	return res;
}

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

	int N; cin >> N;
	vector<int> a(N, 0);
	rep (i, N) cin >> a[i];

	int res = 0;
	rep (i, N) res += cnt2(a[i]);

	cout << res << endl;
	
	return 0;
}

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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007
#define PI 3.141592653589793238462643383

signed main()
{
	init();
	solve();
}

bool x[4];

void init()
{
	string s;
	cin >> s;
	rep(i, s.length()) {
		if (s[i] == 'N') x[0] = true;
		if (s[i] == 'S') x[1] = true;
		if (s[i] == 'E') x[2] = true;
		if (s[i] == 'W') x[3] = true;
	}
}

void solve()
{
	PRINT(x[0] == x[1] && x[2] == x[3]);
}




Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args){
      Scanner in = new Scanner(System.in);
      String input = in.next();
      if(input.length() == 2){
           System.out.println(input);
     }else{
         StringBuilder sb = new StringBuilder();
         for(int i = input.length()-1; i >= 0; i--){
              sb.append(input.substring(i, i+1));
         }
         System.out.println(sb.toString());
      }  
}

}

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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b>c+d)cout<<"Left"<<endl;
    else if(a+b<c+d)cout<<"Right"<<endl;
    else cout<<"Balanced"<<endl;

    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
using namespace std;
int b, c, cnt, x[11];
void dfs(int i){
   if(x[i] > b){
       b = x[i];
       dfs(i+1);
       cnt++;
   }
   if(x[i] > c){
       c = x[i];
       dfs(i+1);
       cnt++;
   }
}

int main(void){
   int N;
   cin >> N;
   while(N != 0){
       b = 0;
       c = 0;
       cnt = 0;
       for(int i = 0; i < 10; i++){
           cin >> x[i];    
       }
       dfs(0);
       if(cnt == 11)   cout << "YES" << endl;
       else    cout << "NO" << endl;
       N--;
   }
   return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int>a(100010);
    ll ans =0;
    rep(i,n){
        ll x;
        cin >>x;
        ans+=x;
        a[x]++;
    }
    int q;
    cin >>q;
    rep(i,q){
        ll b,c;
        cin >>b>>c;
        ans = ans - b * a[b] + c * a[b];
        a[c]+=a[b];
        a[b] =0;
        cout<< ans <<endl;
    }
}



Measured memory_bytes: 3720
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var ai = Sarray();
            var free = 0L;
            var rate = new bool[8];
            foreach (var a in ai)
            {
                if (3199 < a)
                    ++free;
                else
                    rate[a / 400] = true;
            }
            var max = rate.Count(r => r) + free;
            var min = Max(rate.Count(r => r), 1);
            WriteLine($"{min} {max}");
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 11476
//----------------------Shanu Garg here---------------------
//-------------Search on youtube : Shanu Garg---------------
//-Studying at National Institute of Technology Delhi(NITD)-
//---------------------From Delhi, India--------------------

#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define f(i,n) for(auto i=0;i<n;i++)
#define fr(i,n) for(auto i=n-1;i>=0;i--)
#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)
#define fl(i,x) for(auto i : x)
#define nl cout<<"\n";
#define ll long long int
#define vi vector<int>
#define pr pair<ll, ll>
#define vll vector<pr>
#define vl vector<ll>
#define mid(a,b) ((a+b)/2)
#define pb push_back
#define LCM(a,b) ((a*b)/__gcd(a, b))
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;

class triplet{ll f, s, t;};

vl in(ll n){vl v;ll x;
    f(i,n)
    cin>>x, v.pb(x%mod);
    return v;}
void out(vl v){fl(i,v)cout<<i;}
void out(vl v, char ch){
    fl(i,v)
    cout<<i<<ch;}

void solve(){
    ll n, a;
    cin>>n>>a;
    ll ans=0;
    ans += (n%a) ? 1 : 0;
    cout<<(n/a)+ans;
}

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

Measured memory_bytes: 3656
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 ? "Possible" : "Impossible" ) << endl;
}


Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split(" "))
dy, dx = ty - sy, tx - sx
ans = "U" * dy + "R" * dx
ans += "D" * dy + "L" * dx
ans += "L" + "U" * (dy+1) + "R" * (dx+1) + "D"
ans += "R" + "D" * (dy+1) + "L" * (dx+1) + "U"
print(ans)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <math.h>
#include <time.h>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)

#define PI M_PI
#define INF 1000000000
#define MOD 1000000007;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<bool>> vvb;


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

	inv = N;
	reverse(inv.begin(), inv.end());

	if (N == inv) cout << "Yes" << endl;
	else cout << "No" << endl;

	
	return 0;
}



Measured memory_bytes: 256