akhauriyash/Code-Regression huggingface dataset:
// Author: πα

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

#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long int64_t
const int MOD = 1000000007;

const int N = 1005;
int dp[N][N];
bool g[N][N];

int main()
{
    FastIO;
    int h, w, i, j;
    char c;
    cin >> h >> w;
    for(i = 1; i <= h; ++i)
        for(j = 1; j <= w; ++j)
            cin >> c, g[i][j] = c == '.';
    dp[0][1] = g[0][1] = 1;
    for(i = 1; i <= h; ++i)
        for(j = 1; j <= w; ++j)
            dp[i][j] = g[i][j] * (dp[i][j-1] * g[i][j-1] + dp[i-1][j] * g[i-1][j]) % MOD;
    cout << dp[h][w];
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair
using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int gcd(int a, int b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));}

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

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  int ans = 1;
  int f = 0;
  FOR(i, 1, n){
    if (f == 0){
      if (a[i-1] < a[i]) f = 1;
      if (a[i-1] > a[i]) f = 2;
    }
     if (f == 1){
       if (a[i-1] > a[i]){
         ans++;
         f = 0;
       }
     }

     if (f==2){
       if (a[i-1] < a[i]){
         ans++;
         f = 0;
       }
     }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3668
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

vector<int> A;

int i,j,k,N,K,ans;

int main()
{
  cin>>N>>K;
  for(i=0;i<N;i++)
  {
    cin>>j;
    A.push_back(j);
  }
  sort(A.begin(),A.end());
  ans=0;
  for(i=0;i<K;i++)
  {
    ans+=A[i];
  }
  
  cout<<ans;
}

Measured memory_bytes: 3600
c = [list(map(int, input().split())) for i in range(3)]

for a1 in range(101):
    for a2 in range(101):
        for a3 in range(101):
            b1 = c[0][0] - a1
            b2 = c[0][1] - a1
            b3 = c[0][2] - a1
            
            if a2 + b1 == c[1][0] and a2 + b2 == c[1][1] and a2 + b3 == c[1][2]:
                if a3 + b1 == c[2][0] and a3 + b2 == c[2][1] and a3 + b3 == c[2][2]:
                    print('Yes')
                    quit()
print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,k,p[200010];
double each[200010],now,ans=0;
int main() {
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&p[i]);
	for(int i=1;i<k;i++) {
		each[i]=(double)(1+p[i])*p[i]/2.0/p[i];
		now+=each[i];
	}
	for(int i=k;i<=n;i++) {
		each[i]=(double)(1+p[i])*p[i]/2.0/p[i];
		ans=max(ans,now);
		now+=each[i];
		now-=each[i-k];
	}
	ans=max(ans,now);
	cout<<fixed<<setprecision(9)<<ans;
	return 0;
}


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

struct UnionFind{
    vector<int>p;
    UnionFind(int n){
        p.resize(n,-1);
    }
    int find(int x){
        if(p[x]==-1)return x;
        else return p[x]=find(p[x]);
    }
    void unite(int x, int y){
        x=find(x);
        y=find(y);
        if(x==y)return;
        p[x]=y;
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(n+m);
    rep(i,n){
        int k; cin>>k;
        rep(j,k){
            int l; cin>>l; l--;
            uf.unite(i,l+n);
        }
    }
    bool ok=true;
    rep(i,n-1){
        if(!uf.same(i,i+1))ok=false;
    }
    printf(ok?"YES\n":"NO\n");
}

Measured memory_bytes: 5272
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int[] A = new int[M];
		for(int i = 0;i < M;i++) {
			A[i] = sc.nextInt();
		}
		sc.close();
		// N方面へ
		int costN = 0;
		for(int i = X + 1;i <= N;i++) {
			for(int k = 0;k < M;k++) {
				if(A[k] == i) costN++;
			}
		}
		// 0方面へ
		int costZ = 0;
		for(int i = X - 1;i >= 0;i--) {
			for(int k = 0;k < M;k++) {
				if(A[k] == i) costZ++;
			}
		}
		System.out.println(Math.min(costN,costZ));
	}

}


Measured memory_bytes: 21716
#define _GLIBCXX_DEBUG

#include"bits/stdc++.h"
using namespace std;

//loops
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(ll i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(ll i=0;i<(ll)(n+1);i++)
#define AToB(i,a,b) for(ll i=a;i<(ll)(b+1);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)

//bitsearch
#define BITSEARCH(bit, n) for (int bit = 0; bit < (1<<n); ++bit)
#define isOne(bit, i) bit & (1<<i)


//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back

template<typename T>
std::vector<T> slice(std::vector<T> const &v, int m, int n)
{
    auto first = v.cbegin() + m;
    auto last = v.cbegin() + n + 1;

    std::vector<T> vec(first, last);
    return vec;
}

#define remove_unique(v) v.erase(unique(ALL(v)), v.end())

//comparision
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

//pair
#define fir first
#define sec second
#define mp make_pair

//types
#define ll long long
#define vec vector
#define cord2d pair<int,int>
//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)

//output
void print(int a){ cout << a << endl; }
void print(long long a){ cout << a << endl; }
void print(string a){ cout << a << endl; }
void print(char a){ cout << a << endl; }
void print(double a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T = int>
void print(vec<T> v){ cout << v << endl; }

template <class T = int>
void print2dVec(vec<vec<T>> v2d){for(vec<T> v: v2d) {print(v);}}

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"YES":"NO"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 1000000007;

//maths
int factorial(int k){ int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; }

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

void Main() {
    //code here
    int n = gi, k = gi;
    ll res = k * pow(k-1, n-1);
    print(res);
}


signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Main();
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner src=new Scanner(System.in);
		int a=src.nextInt();
		int b=src.nextInt();
		if(((a>9)||(a<0))||((b>9)||(b<0))) {
			System.out.println(-1);
		}
		else {
			System.out.println(a*b);
		}

	}

}


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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define vi vector< int > 
#define pii pair< int, int >
#define mii map< int , int > 
#define F(start,stop) for(int i=start; i<stop; i++)
#define FRev(start,stop) for(int i=start; i>=stop; i--)
#define debugVector(v) for(int i = 0; it < v.size(); i++) cout << v[i] << " "; cout << endl;
#define debugArray(arr, n) for(int i=0; i<n; i++) cout << arr[i] << " "; cout << endl;
#define MOD1 1000000007
#define MOD2 998244353

int main()
{

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	IOS

	ll n;
	cin >> n;
	ll div[n+1] = {0};

	for(ll i=1; i<=n; i++){
		for(ll j =1; j*i <= n; j++)
			div[i*j]++;
	}


	ll ans = 0;

	for(ll i=1; i<=n; i++){
		ans += (i*div[i]);
	}

	cout << ans << endl;
}

Measured memory_bytes: 81712
n,m=map(int,input().split())
visited = [[False,False,False] for _ in range(n)]
ren = [[] for _ in range(n)]
for i in range(m):
    u,v = map(int,input().split())
    ren[u-1].append(v)
s,t = map(int,input().split())

Q = [(s,0)]
visited[s-1][2]=True
ans = -1

while len(Q)>0:
    curs,curcount = Q.pop(0)
    if curs == t:
        ans = curcount
        break
    for i in ren[curs-1]:
        if not visited[i-1][0]:
            visited[i-1][0]=True
            for j in ren[i-1]:
                if not visited[j-1][1]:
                    visited[j-1][1]=True
                    for k in ren[j-1]:
                        if not visited[k-1][2]:
                            visited[k-1][2]=True
                            Q.append((k,curcount+1))

print(ans)


Measured memory_bytes: 28184
#include <bits/stdc++.h>//万能文件头
using namespace std; 
int n,l,r,ans;
int main()
{
   
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>l>>r;
        ans+=r-l+1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a, b, c;
	int sum;

	// スペース区切りの整数の入力
	scanf("%d %d %d", &a, &b, &c);

	// 整数に
	sum = a * 100 + b * 10 + c;

	// 4で割り切れる？
	if (sum % 4 == 0)
	{
		printf("YES");
	}
	else
	{
		printf("NO");
	}

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	string s;
	cin >> s;
	long sum = 0;
	
	bool f1 = true;
	bool f2 = true;
	rep(i,0,s.size()){
		if(s[i] != '9' && f1){
			f1 = false;
		}
		else if(s[i] != '9'){
			f2 = false;
		}
	}
	if(s.size() == 1 ){
		sum = s[0] - '0';
	}
	else{
		if(f1){
			sum = 9 * s.size();
		}
		else if(f2){
			if(s[0] != '9'){
				rep(i,0,s.size()){
					sum += s[i] - '0';
				}
			}
			else{
				sum = s.size() * 9 - 1;
			}
		}
		else{
			sum += s[0] - '0' - 1;
			rep(i,1,s.size()){
				sum += 9;
			}
		}
	}

	P(sum);
	ret 0;
}

Measured memory_bytes: 256
fun main() {
    val inputs = readLine()!!.split(" ")
    val n = inputs[0].toLong()
    var x = inputs[1].toLong()
    val m = inputs[2].toLong()

    val num = HashMap<Long, Int>()
    val sum = mutableListOf<Long>(0)

    num[x] = 1
    sum.add(x)
    var cnt = 2
    while (cnt <= m+1) {
        x = f(x, m)
        sum.add(sum[cnt - 1] + x)
        if (!num.containsKey(x)) {
            num[x] = cnt
        } else {
            break
        }
        cnt += 1
    }

    val len = cnt - num[x]!!
    val first = if (n >= cnt) sum[cnt - len - 1] else sum[n.toInt()]
    if (n < cnt) {
        println(first)
    } else {
        val middleLen = (n - (cnt - len - 1)) / len.toLong()
        val middle = (sum[cnt-1] - sum[num[x]!!-1]) * middleLen
        val endLen = (n - (cnt - len - 1)) % len
        val end = sum[num[x]!! - 1 + endLen.toInt()] - sum[num[x]!! - 1]

        println(first + middle + end)
    }
}

fun f(x: Long, mod: Long): Long {
    return (x * x) % mod
}


Measured memory_bytes: 44948
#include <cstdio>

int n,x,count;
int solve(int n,int x){
    for(int i = 1;i <= n - 2;i++){
        for(int j = i + 1;j <= n - 1;j++){
            for(int k = j + 1;k <= n;k++){
                if(i + j + k == x)
                    count++;
            }
        }
    }
    return count;    
}

int main(){
    while(true){
        count = 0;
        scanf("%d%d",&n,&x);
        if(n == 0 && x == 0)
            break;
        solve(n,x);
        printf("%d\n",count);
    }

    return 0;
}


Measured memory_bytes: 2668
# include <bits/stdc++.h>
/// my holy template
# define F first    
# define S second
# define mp make_pair
# define pii pair<int,int>         
/// eveything goes according to plan
# define long long long  
# define pb push_back
# define sz(a) (int)(a.size())
/// countdown BEGAN. 10 , 9 , 8 ...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right     

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long MXLL = 9223372036854775807;
const int Sz = 1110111;

using namespace std;

inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
}
int n;

int a[Sz];

int cnt[Sz];

bool solve()
{               
  if (cnt[0] < cnt[2])  
    return 1;
  if (cnt[0] == cnt[2])
    return 1;
                     
  if (cnt[0] - 1 > cnt[2] || (cnt[0] > cnt[2] && cnt[1]))
    return 0;
  else
    return 1;
}
                              
int main() 
{
  Read_rap ();
  cin >> n;
  for (int i = 1;i <= n;i ++) {
    int x;  cin >> x;
    if (x % 4 == 0)
      x = 2;
    else  if (x % 2 == 0) 
      x = 1;
    else 
      x = 0;
    cnt[x] ++;
  }          

  if (solve ())
    cout << "Yes";
  else
    cout << "No";
  


  return 0;
} 










// Coded by Z...

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: chars
    }
    let s: Vec<i32> = s.iter().map(|c| c.to_digit(10).unwrap() as i32).collect();
    let n = s.len();
    let mut b: u64 = 1;
    while b < (1u64 << n) {
        let mut sum = s[0];
        for (i, &v) in s.iter().skip(1).enumerate() {
            if b & (1 << i) != 0 {
                sum += v;
            } else {
                sum -= v;
            }
        }
        if sum == 7 {
            break;
        }
        b += 1;
    }
    for i in 0..n-1 {
        print!("{}", s[i]);
        if b & (1 << i) != 0 {
            print!("+");
        } else {
            print!("-");
        }
    }
    println!("{}=7", s[n-1]);
}


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

int A[100009];

int main() {
	int N, s=0; scanf("%d",&N);
	for(int i=1; i<=N; i++) {
		scanf("%d",&A[i]);
		s ^= A[i];
	}
	if(s) puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int a[100005];
int b[100005];
int c[100005];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		{
			cin>>a[i];
			if(i%2==0)
			b[a[i]]++;
			else 
			c[a[i]]++;
		}
	int maxb1=0,maxb2=0,maxc1=0,maxc2=0;
	int sum=0;
	int temp1,temp2,temp3,temp4;
	for(int i=1;i<1e5+1;i++)
		if(b[i]>maxb1)
			{
				maxb1=b[i];
				temp1=i;
			}
		b[temp1]=0;
		for(int i=1;i<1e5+1;i++)
		if(b[i]>maxb2)
			{
				maxb2=b[i];
				temp2=i;
			}
	for(int i=1;i<1e5+1;i++)
		if(c[i]>maxc1)
			{
				maxc1=c[i];
				temp3=i;
			}
		c[temp3]=0;
	for(int i=1;i<1e5+1;i++)
		if(c[i]>maxc2)
			{
				maxc2=c[i];
				temp4=i;
			}
	if(temp1==temp3)
	cout<<n-maxb1-max(maxb2,maxc2)<<endl;
	else cout<<n-maxb1-maxc1<<endl;
	
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5000 + 10;
typedef long long LL;
const LL MOD = 1e9 + 7;
int n, A, B;
LL f[N][N][2];
LL g[N][N][2], w[N][2];
void add(LL & x, LL y) {
	x += y;
	if (x > MOD) x -= MOD;
}
int main() {
	cin >> n >> A >> B;
	if (A < B) swap(A, B);
	LL tot = 1;
	for (int i = 1; i <= n; i ++) tot = tot * 2 % MOD;
	
	f[0][0][0] = 1; g[0][0][0] = 1; w[0][0] = 1;
	f[0][0][1] = 1; g[0][0][1] = 1; w[0][1] = 1;

	for (int i = 1; i <= n; i ++) {
		for (int j = 0; j < A; j ++) {
			if (i>=1 && j>=1) {
				add(f[i][j][0], g[i-1][j-1][1]);
			}
			if (i-B>=0 && j-B>=0) {
				add(f[i][j][1], g[i-B][j-B][0]);
			}
		}
		for (int t = 1; t <= min(i, B - 1); t ++) {
			add(f[i][0][1], w[i-t][0]);
		}
		g[i][0][1] = f[i][0][1];
		for (int j = 1; j < A; j ++) {
			g[i][j][0]=(g[i-1][j-1][0]+f[i][j][0])%MOD;
			g[i][j][1]=(g[i-1][j-1][1]+f[i][j][1])%MOD;
		}
		
		for(int j = 0; j < A; j ++) {
			add(w[i][0], f[i][j][0]);
			add(w[i][1], f[i][j][1]);
		}
	}
	for (int j = 0; j < A; j ++) {
		for (int k = 0; k < 2; k ++) {
			tot = tot - f[n][j][k];
			tot = (tot % MOD + MOD)	% MOD;	
		}
	}
	cout << tot << endl;
}

Measured memory_bytes: 786528
N=int(input())
B=[int(b) for b in input().split()]
A=[int(a) for a in range(N)]



for i in range(N-2):
    if B[i]<=B[i+1]:
        A[i+1]=B[i]
    if B[i]>B[i+1]:
        A[i+1]=B[i+1]
A[0]=B[0]
A[N-1]=B[N-2]

print(sum(A))


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
	int n; cin >> n;
	cout << n * n * n << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  vector<ll>res(n);
  rrep(i,n){
    ll ts=0;
    for(ll j=i;j<n;j+=i+1){
      ts^=res[j];
    }
    res[i]=ts^a[i];
  }
  ll cnt=0;
  rep(i,n){
    if(res[i]){cnt++;}
  }
  cout<<cnt<<endl;
  rep(i,n){
    if(res[i])cout<<i+1<<" ";
  }
  cout<<endl;
  return 0;

}


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

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long N, T;
  cin >> N >> T;
  vector<long long> t(N);
  for(long long i = 0; i < N; i++) {
    cin >> t[i];
  }
  long long ans = t[0];
  for(long long i = 1; i < N; i++) {
    if(t[i - 1] + T < t[i]) ans += T;
    else ans += (t[i] - t[i - 1]);
  }
  ans += T;

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 4576
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

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

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int N, D, X;
	cin >> N;
	cin >> D >> X;

	int result = X;

	REP(i, N) {
		int day;
		cin >> day;
		if (D - 1 >= day) {
			result += (D - 1) / day + 1;
		}
		else {
			result++;
		}
	}

	cout << result;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
eval"_,*A="+gets.split*?,
s=*$<
q=[]
f=->i{s[i]&.chop&.bytes{|x|A[x-=65]>0&&(q<<(y=s[i].sum-x-75).chr;A[x]-=1;A[y-=65]+=1;f[i+1];A[x]+=1;A[y]-=1;q.pop)}||puts(:Yes,q)+exit}
f[0]
puts:No

Measured memory_bytes: 154060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n, k, q; std::cin >> n >> k >> q;
    std::vector<int> cnt(n);
    for (int i = 0; i < q; i++) {
        int a; std::cin >> a;
        cnt[a - 1]++;
    }
    for (int i = 0; i < n; i++) {
        std::cout << (k <= q - cnt[i] ? "No" : "Yes") << std::endl;
    }
    return 0;
}



Measured memory_bytes: 1024
N,K=map(int,input().split())
A=list(map(int,input().split()))
p=10**9+7

cnt_self=0
for i in range(0,N-1):
  for j in range(i+1,N):
    if A[i]>A[j]:
      cnt_self += 1

cnt_each=0
for i in A:
  for j in A:
    if i>j:
      cnt_each +=1

cnt_A = (K*cnt_self)%p
cnt_B = ((K*(K-1)//2)*cnt_each)%p
ans = (cnt_A+cnt_B)%p

#print(cnt_A,cnt_B)
print(ans)

Measured memory_bytes: 3188
#include <iostream>
using namespace std;
typedef long long ll;

ll rec(ll idx, ll size){
    if(size == 1) return 1;
    if(idx == 0) return 0;
    ll subsize = (size-3) / 2;
    ll subnums = rec(subsize-1, subsize);
    if(idx == size/2) return subnums + 1;
    if(idx == size-1) return subnums*2 + 1;

    ll ret = 0;
    if(idx > size/2){
        ret += subnums + 1;
        idx -= size/2;
    }
    ret += rec(idx - 1, subsize);

    return ret;

}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n, x;
    cin >> n >> x;

    ll size = 1;
    for(int i = 0; i < n; ++i){
        size = size*2 + 3;
    }

    cout << rec(x-1, size) << endl;

}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
long long n, p;
int main() {
	cin>>n>>p;
	if(n == 1ll) {
		cout<<p<<endl;
		return 0;
	}
	long long ans=1ll;
	for(long long i = 2ll; i * i <= p; i++) {
		long long cnt = 0ll;
		while(p % i == 0ll) {
			p /= i;
			cnt++;
		}
		cnt /= n;
		for(long long j = 0; j < cnt; j++) {
			ans *= i;
		}
	}
	cout<<ans<<endl;
	return 0;
}
/*
3 24
Output:2

5 1
Output:1

1 111
Output:111

4 972439611840
Output:206

1000000 1000000000000
Output:1
*/

Measured memory_bytes: 256
n, k = map(int, input().split())

MOD = 10**9+7
result = 0
for i in range(k, n+2):
    min_number = (i - 1) * i / 2
    max_number = (n + (n - i + 1)) * i / 2

    result += max_number - min_number + 1

result = result % MOD
print(int(result))


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

signed main() {
    int N;
    cin >> N;
    vector<int> H(N);
    for (int& x : H) cin >> x;
    H.push_back(1e18);

    int prev = -1;
    int ans = 0;
    int t = 0;
    for (int i = 0; i < H.size(); i++) {
        if (prev >= H[i]) {
            t++;
        }
        else {
            ans = max(ans, t);
            t = 0;
        }
        prev = H[i];
    }
    cout << ans << endl;
}


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

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

    int cnt = 0;
    while (A >= B) {
        B *= 2;
        cnt++;
    }

    while (B >= C) {
        C *= 2;
        cnt++;
    }

    if (cnt <= K) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define fi first
#define se second
#define reset(n,k) memset((n),k,sizeof(n))
#define all(n) n.begin(),n.end()
#define pb push_back
using namespace std;
using ll=long long;
using pii=pair<int,int>;
int main(){
	IOS;
	string s;
	cin>>s;
	bool h1 = 0, h2 = 0;
	for(auto i:s){
		if(i=='A')h1 = 1;
		else h2 = 1;
	}
	cout<<((h1&&h2)?"Yes\n":"No\n");


}


Measured memory_bytes: 256
c = [[int(i) for i in input().split()] for _ in range(3)]
b = [0 for _ in range(3)]
ans = 'Yes'
for i in range(3):
    if i == 0:
        for j in range(3):
            b[j] = c[i][j] - c[i][(j+1)%3]
    else:
        for j in range(3):
            if b[j] != c[i][j] - c[i][(j+1)%3]:
                ans = 'No'
                break
        if ans == 'No':
            break
print(ans)

Measured memory_bytes: 3316
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> A(n), B(m);
  rep(i, n) cin >> A[i];
  rep(i, m) cin >> B[i];

  vector<ll> a(1), b(1);
  rep(i, n) a.push_back(a[i] + A[i]);
  rep(i, m) b.push_back(b[i] + B[i]);

  int ans = 0, j = m;
  rep(i, n + 1) {
    if (a[i] > k) break;
    while (b[j] > k - a[i]) --j;
    ans = max(ans, i + j);
  }

  cout << ans << endl;

  return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())

using LL = long long;
template<class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
  template<class... Args>
  vec(size_t n = 0, Args... args)
    : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template<class T>
struct vec<T, 1> : vector<T> {
  template<class... Args>
  vec(Args... args)
    : vector<T>(args...) {}
};

template<class T>
inline bool asMn(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T& a, const T& b) { return a < b ? a = b, true : false; }
inline int nex(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int pre(int i, int n) { return !i ? n - 1 : i - 1; }

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

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

  string s; cin >> s;
  s.erase(unique(all(s)), s.end());

  cout << sz(s) - 1 << '\n';

  return 0;
}


Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <cstdlib>
#include <iterator>
#include <algorithm>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            for (int k = j + 1; k < n; k++)
            {
                if (a[i] == a[j] or a[i] == a[k] or a[j] == a[k]) continue;
                if (a[i] + a[j] > a[k] and a[i] + a[k] > a[j] and a[k] + a[j] > a[i])
                    count++;
            }
        }
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 3652
#!/usr/bin/env ruby
# require 'pry'

# dpテンプレ
# 最小化
# dp = Hash.new{ Float::INFINITY }
# dp[i] = [dp[i], dp[i-1] + hoge].min
# dp[0] = 0
# 最大化
# dp = Hash.new{ 0 }
# dp[i] = [dp[i], dp[i-1] + hoge].max
# dp[0] = 0

x,y = gets.split(' ').map(&:to_i)

0.upto(100) do |turu|
  0.upto(100) do |kame|
    f = turu*2 + kame*4
    if turu + kame == x && f == y
      puts 'Yes'
      exit
    elsif turu == 100 && kame == 100
      puts 'No'
    end
  end
end



Measured memory_bytes: 14324
#include<stdio.h>

int main(){
  int i,n,min,max,r[200000];

  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&r[i]);

  min = r[0];
  max = r[1]-r[0];

  for(i=1;i<n;i++){
    if(max<r[i]-min) max = r[i]-min;
    if(min>r[i]) min = r[i];
  }
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 1376
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using namespace std;

//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------


int main() {
 string s,t;
 cin>>s>>t;
 int sl,tl,dl=0;
 sl=s.size();
 tl=t.size();
 
 for(int i=0;i<=sl-tl;i++){
     int ll=0;
     for(int j=0;j<tl;j++){
         //cout<<s.at(j+i)<<" "<<t.at(j)<<endl;
         if(s.at(j+i)==t.at(j))ll++;
     }//cout<<ll<<endl;
     dl=max(dl,ll);
 }
 
 cout<<tl-dl<<endl;
}



Measured memory_bytes: 3632
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.c
 * Author: Ivan
 *
 * Created on June 25, 2018, 6:55 PM
 */

#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 60001
#define min(a,b) (((a)<(b))?(a):(b))

typedef struct {
    char item[1000];
    int bt;
}Process;

/*
 * 
 */

Process Queue[MAXSIZE];
int head, tail, num_of_item;
void enqueue(Process x);

Process dequeue();

int main(int argc, char** argv) {
    int total_time = 0, time_quantum, needed_time;
    Process current_process;
    
    scanf("%d %d", &num_of_item, &time_quantum);
    
    for (int i = 1; i <= num_of_item; ++i)
        scanf("%s %d", Queue[i].item, &Queue[i].bt);
    
    head = 1; tail = num_of_item + 1;
    
    while (head != tail)
    {
        current_process = dequeue();
        needed_time = min(time_quantum, current_process.bt);
        current_process.bt -= needed_time;
        total_time += needed_time;
        
        if (current_process.bt > 0) enqueue(current_process);
        else { printf("%s %d\n", current_process.item, total_time); }
    }
    return (EXIT_SUCCESS);
}

void enqueue(Process x)
{
    Queue[tail] = x;
    tail = (tail +1) % MAXSIZE;
}

Process dequeue()
{
    Process x = Queue[head];
    head = (head +1) % MAXSIZE;
    return x;
}


Measured memory_bytes: 60520
N,Q=map(int,input().split())
l=[[] for i in range(N)]
ans=[0 for i in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)
#print(l)

dic=[0 for i in range(N)]

for i in range(Q):
  a,b=map(int,input().split())
  dic[a-1]+=b
#print(dic)

nex=[0]
no=[0]
an=0

while an<N:
  no=nex
  nex=[]
  #print("no",no,"ans",ans)
  for j in no:
    ans[j]+=dic[j]
    an+=1
    for i in l[j]:
      l[i].remove(j)
      ans[i]=ans[j]
      #ans[j]=str(ans[j])
      nex.append(i)
      #print(j,"i",i,"l[i]",l[i],ans,nex,an)
      

for i in range(N):
  ans[i]=str(ans[i])
  
print(" ".join(ans))

    



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

signed main() {
    int a, b, c, z;
    cin >> a;
    cin >> b;
    cin >> c;
    
    if (a==b && a==c) { z = 1; }
    else if (a==b) { z = 2; }
    else if (a==c) { z = 2; }
    else if (b==c) { z = 2; }
    else { z = 3; }

    cout << z << "\n" << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>

using namespace std;


int P[10010]; // 0 ?????? 10000 ?????§????????????????????±?????????
void init(int N) { // ????????? ??????????????¨???????????????????????????
  for (int i=0; i<=N; ++i) P[i] = i;
  // ??¨: ????????? [0,N-1] ????????? [1,N] ?????????????????????
  // ???????????§???????????§???????????????????????§??? [0,N] ???????????¨??????
}
int root(int a) { // a ??? root(??£??¨???) ????±???????
  if (P[a] == a) return a; // a ??? root
  return (P[a] = root(P[a])); // a ????????? root ????±???????a ????????¨??????
}
bool is_same_set(int a, int b) { // a ??¨ b ???????????°?????????????±???????????
  return root(a) == root(b);
}
void unite(int a, int b) { // a ??¨ b ???????????°?????????????????¨??????
  P[root(a)] = root(b);
}


int N=0;
int A[100+10][100+10] = {0};

int cost[10100] = {0};
int src[10100] = {0};
int dst[10100] = {0};

pair<int,int> c_n[10100];



int main() {
  cin >> N;
  init(N+10);
  
  int k=0;
  for(int j=0;j<N;++j){
    for(int i=0;i<N;++i){
      cin >> A[i][j];
      //cout << A[i][j] << "|";
      if (A[i][j] != -1){
	cost[k] = A[i][j];
	src[k] = i;
	dst[k] = j;
	c_n[k] = make_pair(cost[k],k);
	++k;
      }
    }
    //cout << endl;
  }


  sort(c_n, c_n+k);

  

  int num = 0;
  int sum = 0;
  for(int i=0;i<k;++i){
    num = c_n[i].second;
    if(is_same_set(src[num], dst[num]) == 0){
      unite(src[num], dst[num]);
      sum += cost[num];
      //cout << num << " " << sum << endl;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3328
#include<iostream>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a;
  cin>>b;
  cin>>c;
  cin>>d;
  if(a<=b){
    if(c<=d){
      cout<<a+c;
    }
    else{
      cout<<a+d;
    }
  }
  else{
    if(c<=d){
      cout<<b+c;
    }
    else{
      cout<<b+d;
    }
  }
}


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

int main() {
    string s;
    string t;

    cin >> s >> t;

    string x;
    x = t.substr(0, s.size());

    if (s == x && t.size() == s.size() + 1) {
        cout << "Yes" << endl;
    }

    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3600
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	strings := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&strings[i])
	}
	counter := make(map[string]int)
	for _, str := range strings {
		counter[str]++
	}

	result := []string{}
	var maximum int
	for k, v := range counter {
		if v > maximum {
			result = []string{k}
			maximum = v
		} else if v == maximum {
			result = append(result, k)
		}
	}

	sort.Strings(result)
	for _, str := range result {
		fmt.Println(str)
	}
}


Measured memory_bytes: 40576
#include<iostream>
using namespace std;
long long n,ans,k;
long long l[15],r[15],x[25],s[400005],sum[400005];
const long long mod=998244353;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	int flag=0;
	int cnt=1;
	for(int i=1;i<=k;i++){
		cin>>l[i]>>r[i];
	}
	sum[0]=1;
	for(int i=1;i<=n;i++){
		sum[i]=(sum[i-1]+s[i]+10*mod)%mod;
		for(int j=1;j<=k;j++){
			s[i+l[j]]+=sum[i];
			s[i+r[j]+1]-=sum[i];
		}
	}
	cout<<(sum[n]-sum[n-1]+10*mod)%mod;
	/*	
	for(int i=2;i<=200000;i++){
		m[i]=m[i-1]*i%mod;
	}
	if(!flag){
		cout<<0;return 0;
	}
	if(flag<2) x++;
	cout<<x<<endl;
	for(int i=2;i<=x;i++){
		ans=(ans+((m[x]*qpow(m[x-i],mod-2))%mod*qpow(m[i],mod-2)%mod))%mod;
	}
	cout<<ans;*/
}

Measured memory_bytes: 8268
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(m);
  for (int i = 0; i < m; i ++) {
    int k; cin >> k;
    for (int j = 0; j < k; j ++) {
      int t; cin >> t;
      t --;
      a[i].push_back(t);
    }
  }
  vector<int> p(m);
  for (int i = 0; i < m; i ++) cin >> p[i];

  LL ans = 0;
  for (int i = 0; i < (1 << n); i ++) {
    bool flag = true;
    for (int j = 0; j < m; j ++) {
      int sum = 0;
      for (int k = 0; k < a[j].size(); k ++) {
        if (i & (1 << a[j][k])) sum ++;
      }
      if (sum % 2 != p[j]) flag = false;
    }
    if (flag) ans ++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int n;
  cin>>n;
  vector<pair<int,int>> red(n),blue(n);

  REP(i,n){
    int a,b;
    cin>>a>>b;
    red[i]=MP(b,a);
  }
  REP(i,n){
    int a,b;
    cin>>a>>b;
    blue[i]=MP(a,b);
  }
  sort(ALL(red));
  sort(ALL(blue));
  vector<int> used_r(n);
  int idx,ans=0;
  for(int i=0;i<n;i++){
    bool find=false;
    for(int j=0;j<n;j++){
      if(red[j].S<blue[i].F&&red[j].F<blue[i].S){
        if(used_r[j]==0){
          find=true;
          idx=j;
        }
      }
    }
    if(find){
      ans++;
      used_r[idx]=1;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int sx, sy, tx, ty;
void solve() {
  int up = ty - sy;
  int right = tx - sx;
  string ans = "";
  for (int i=0;i<up;i++) {
    ans += 'U';
  }
  for (int i=0;i<right;i++) {
    ans += 'R';
  }
  for (int i=0;i<up;i++) {
    ans += 'D';
  }
  for (int i=0;i<right;i++) {
    ans += 'L';
  }
  ans += 'L';
  for (int i=0;i<=up;i++) {
      ans += 'U';
  }
  for (int i=0;i<=right;i++) {
    ans += 'R';
  }
  ans += "DR";
  for (int i=0;i<=up;i++) {
    ans += 'D';
  }
  for (int i=0;i<=right;i++) {
    ans += 'L';
  }
  ans += "U";
  cout << ans << endl;
}

int main() {
  cin >> sx >> sy >> tx >> ty;
  solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
 
using namespace std;
 
long long int K, A, B;
 
int main(void) {
	cin >> K >> A >> B;
 
	long long int ans = 0;
	long long int count = K;
	long long int num;
 
	if ((A +2< B)) {
		num = (K - A + 1) / 2;
		num = min(K / 2, num);
		ans = (B - A)*num + A;
		if (((K - A + 1) % 2) == 1) { ans++; }
	}
	
 
	ans = max(ans, K + 1);
 
	cout << ans << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
//region Template
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../debug_prettyprint.hpp"
#else
#define debug(...) 42
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#endif
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout<<fixed<<setprecision(12);
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
#define EXIT(answer) { cerr<<"EXIT #"<<__LINE__<<endl; cout<<answer<<endl; exit(0); }
#define sz(v) int(v.size())
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> istream& operator>>(istream& in, pair<T,U> &p) { in>>p.first>>p.second; return in; }
template<typename T> inline vector<T> READ(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
//endregion

template<int S>
struct DisjointSet {
    int parent[S];
    int rank[S];
    int size[S];

    void makeSet(int elem) {
        parent[elem]=elem, rank[elem]=0, size[elem]=1;
    }

    void unionSets(int x, int y) {
        link(findSet(x), findSet(y));
    }

    void link(int x, int y) {
        if(x==y)return;
        if(rank[x]>rank[y]) {
            parent[y]=x;
            size[x] += size[y];
        } else {
            parent[x]=y;
            if(rank[x]==rank[y])
                rank[y]++;
            size[y] += size[x];
        }
    }

    int findSet(int x) {
        if(x!=parent[x]) parent[x]=findSet(parent[x]);
        return parent[x];
    }
};

DisjointSet<200005> ds;


int main() {
    FASTIO


    int n,m; cin>>n>>m;
    FOR(i,n)
        ds.makeSet(i+1);
    FOR(i,m) {
        int a,b; cin>>a>>b;
        ds.unionSets(a,b);
    }
    int ans=0;
    FOR(i,n)
        ans |= MAX(ds.size[i+1]);
    
    cout<<ans<<endl;
}

Measured memory_bytes: 5960
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
using ll = long long;
 
const int nax = 10123;
char k[nax];
const int mod = 1e9 + 7;
 
void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}
 
int main() {
    scanf("%s", k);
    int D;
    scanf("%d", &D);
    int len = strlen(k);
    vector<array<int,2>> dp(D, array<int,2>{});
    vector<array<int,2>> new_dp(D, array<int,2>{});
    // dp[sum][smaller_already] - the number of ways to choose digits so far
    // such that the sum of digits modulo D is 'sum' and 'smaller_already'
    // says whether we already chosen some digit smaller than in K
    dp[0][0] = 1;
    for(int where = 0; where < len; ++where) {
        fill(new_dp.begin(), new_dp.end(), array<int,2>{});
        for(int sum = 0; sum < D; ++sum) {
            for(bool sm_already : {false, true}) {
                for(int digit = 0; digit < 10; ++digit) {
                    if(digit > k[where] - '0' && !sm_already) {
                        break;
                    }
                    add_self(new_dp[(sum+digit)%D][sm_already || (digit < k[where]-'0')],
                        dp[sum][sm_already]);
                }
            }
        }
        swap(dp, new_dp);
    }
    int answer = (dp[0][false] + dp[0][true]) % mod;
    --answer;
    if(answer == -1) {
        answer = mod - 1;
    }
    printf("%d\n", answer);
}


Measured memory_bytes: 256