jiahuimbzuai/CoQuIR huggingface dataset:
//  [ruby]
N = gets.to_i
ans = 0
1.upto(N) do |i|
  count = 0
  1.upto(i) do |j|
    count += 1 if i%i == 0
  end
  ans += 1 if count == 8
end

print ans
//  [ruby]
n=gets.to_i
i=1
while i<=n
  c=0
  (1..i).each{|j|c+=1 if i%j==0}
  if c==8
    p i
    break
  end
  i+=2
end
//  [ruby]
n=gets.to_i
i=1
divisor=0
ans=0
while i<=n
  divisor=0
  1.upto(i) do |j|
    if i%j==0
      divisor+=1
    end
  end
  if divisor==8
    ans=1
  end
  i+=2
end
puts ans
//  [rust]
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let mut cnt = 0;
	let mut ret = 0;
	for i in 1..(n+1) {
		if i%2 == 1 {
			for j in 1..(i+1) {
				if i % j == 0 {
					cnt += 1;
				}
			}
			if cnt == 8 {
				ret += 1;
			}
			cnt = 0;
		}
	}
	println!("{}", ret);
}
//  [rust]
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut cnt = 0;
    for i in 1..n + 1{
        if i % 2 == 0 {
            continue;
        }
        let mut tmp = 0;
        for j in 1..n + 1 {
            if i % j == 0 {
                tmp += 1;
            }
        }
        if tmp == 8 {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}
//  [rust]
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut ans = 0 ;
    for i in 1..n+1 {
        if i % 2 == 0 { continue; }
        let mut divisor_num = 0 ;
        for j in 1..i+1 {
            if i % j == 0 {
                divisor_num += 1;
            }
        }
        if divisor_num == 8 {
            ans += 1;
        }
    }
    println!("{}", ans);
}
//  [rust]
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!{
        n: u8,
    }
    let ans = match n {
        x if x < 105 => 0,
        x if 105 <= x && x < 165 => 1,
        x if 165 <= x && x < 195 => 2,
        x if 195 <= x => 3,
        _ => 0,
    };
    println!("{}", ans);
}
//  [rust]
fn main() {
    let n:usize = read();
    let mut cnt = 0;
    for i in (1..n+1).step_by(2) {
        let mut tmp = 0;
        for j in 1..i+1 {
            if i % j == 0 {
                tmp += 1;
            }
        }
        if tmp == 8 {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}
//  [rust]
use proconio::input;

fn main() {
    input!{
        n: usize,
    }

    let mut cnt = 0;
    for i in 0..=n {
        let mut cnt_yaku = 0;
        if i % 2 != 0 {
            for j in 1..=i {
            if i % j == 0 { cnt_yaku += 1 ;}
            }
        }
        if cnt_yaku == 8 {
            cnt += 1;
        }
    }

    println!("{}", cnt);
}
//  [swift]
let N = Int(readLine()!)!
if N < 105 {
  	print(0)
} else {
  	var ans = 1
    for i in 107.stride(to: N+1, by: 2) {
        var cnt = 0
        for j in 3.stride(to: i, by: 2) {
            if i % j == 0 {
                cnt += 1
            }
        }
        if cnt == 6 {
            ans += 1
        }
    }
  	print(ans)
}
//  [swift]
let N = Int(readLine()!)!
var ans = 0
if N >= 105 {
  	ans += 1
    for i in 107.stride(to: N+1, by: 2) {
        var cnt = 0
        for j in 3.stride(to: i, by: 2) {
            if i % j == 0 {
                cnt += 1
            }
        }
        if cnt == 6 {
            ans += 1
        }
    }
}
print(ans)
//  [swift]
let N = Int(readLine()!)!
var ans = 0
if N >= 105 {
    for i in 105.stride(to: N+1, by: 2) {
        var cnt = 0
        for j in 3..<i {
            if i % j == 0 {
                cnt += 1
            }
        }
        if cnt == 6 {
            ans += 1
        }
    }
}
print(ans)
//  [swift]
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/

let N = readInt()!
var answer = 0
for C in stride(from: 1, to: N+1, by: 2) {
    var num_of_divisors = 0
    for X in 3..<C {
        if C % X == 0 {
            num_of_divisors += 1
        }
    }
    if num_of_divisors == 6 {
        answer += 1
    }
}
print(answer)
//  [swift]
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/

//let N = readInt()!
//var answer = 0
//for C in stride(from: 1, to: N, by: 2) {
//    var num_of_divisors = 0
//    for X in 1...C {
//        if C % X == 0 {
//            num_of_divisors += 1
//        }
//    }
//    if num_of_divisors == 8 {
//        answer += 1
//    }
//}
//print(answer)

/*************** メインプログラム ***************/

let N = readInt()!
var ans = 0
if N < 105 {
    print(ans)
} else {
    for i in stride(from: 1, to: N+1, by: 2) {
        var cnt = 0
        for j in 1..<i {
            if i % j == 0 {
                cnt += 1
            }
        }
        if cnt == 8 {
            ans += 1
        }
    }
    print(ans)
}
//  [swift]
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/

let N = readInt()!
var answer = 0
for C in stride(from: 1, to: N, by: 2) {
    var num_of_divisors = 0
    for X in 1...C {
        if C % X == 0 {
            num_of_divisors += 1
        }
    }
    if num_of_divisors == 8 {
        answer += 1
    }
}
print(answer)
//  [typescript]
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};
const main=()=>{
  let n=tn(),ans=0
  for(let i=1;i<=n;i++){
    if(i%2==1){
      let c=0
      for(let j=1;j<=i;j++){
        if(i%j==0)c++
      }
      if(c==8)ans++
    }
  }
  to(ans)
}
main()
//  [typescript]
import * as fs from 'fs';

namespace AtCoder.abc106 {

    class ProgramB {
        args: string[];

        constructor(args: string[]) {
            this.args = args;
        }

        /**
         * in
         *  105
         * out
         *  1
         */
        main(): void {
            const n: number = parseInt(this.args[0], 10);
            let ans: number = 0;
            for (let i: number = 105; i < n + 1; i = i + 2) {
                let cnt: number = 0;
                for (let j: number = 1; j < i + 1; j++) {
                    if (i % j === 0) cnt++;
                }
                if (cnt === 8) {
                    ans++;
                }
            }
            console.log(ans);
        }
    }

    const args = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
    const prg = new ProgramB(args);
    prg.main();
}
//  [typescript]
function main(input) {
const N  = input.split(/\n|\s/g)[0]
let number = 0;
for(let i=1;i<=N;i++){
  if(i%2===0){continue;}
  let count = 0;
  for(let j=1;j<=i;j++){
    if(i%j===0){count++;}
  }
  if(count===8){number++;}
}
console.log(number)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
import * as fs from 'fs';

namespace AtCoder.abc106 {

    class ProgramB {
        args: string[];

        constructor(args: string[]) {
            this.args = args;
        }

        /**
         * in
         *  105
         * out
         *  1
         */
        main(): void {
            const n: number = parseInt(this.args[0], 10);
            let ans: number = 0;
            for (let i: number = 105; i < n + 1; i++) {
                let cnt: number = 0;
                for (let j: number = 1; j < i + 1; j++) {
                    if (i % j === 0) cnt++;
                }
                if (cnt === 8) ans++;

            }
            console.log(ans);
        }
    }

    const args = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
    const prg = new ProgramB(args);
    prg.main();
}
//  [python]
K, S = map(int, input().split())
X = (S + 2) * (S + 1)
if S - K - 1 >= 0:
  X -= 3 * (S - K + 1) * (S - K)
if S - 2 * K - 2 >= 0:
  X += 3 * (S - 2 * K) * (S - 2 * K - 1)

print(X // 2)
//  [python]
K, S= map(int, input().split())

minZ=max(S-2*K,0)
maxZ=min(S,K)

if minZ>=S-K:
  nZ=maxZ-minZ+1
  max_nY=S-minZ+1
  min_nY=S-maxZ+1
  ans=((max_nY+min_nY)*nZ)//2
  print(ans)
elif maxZ>=S-K:
  nZ_u=maxZ-(S-K)
  max_nY_u=K
  min_nY_u=S-maxZ+1
  
  ans_u=((max_nY_u+min_nY_u)*nZ_u)//2
  
  nZ_l=(S-K)-minZ+1
  max_nY_l=K+1
  min_nY_l=2*K+minZ-S+1
  
  ans_l=((max_nY_l+min_nY_l)*nZ_l)//2
  
  print(ans_u+ans_l)
  
  
else:
  nZ=maxZ-minZ+1
  min_nY=2*K+minZ-S+1
  max_nY=2*K+maxZ-S+1
  ans=((max_nY+min_nY)*nZ)//2
  print(ans)
//  [python]
k, s = map(int, input().split())
if 0 <= s <= k:
    ans = (s+1)*(s+2)/2
    print(int(ans))
elif k < s <= 2*k:
    ans = ((s+1)*(s+2)/2) - ((s-k)*(s-k+1)/2) - ((s-k)*(s-k+1))
    print(int(ans))
elif 2*k < s < 3*k:
    print(3)
else:
    print(1)
//  [python]
k,s = map(int,input().split())
ans = 0

for x in range(k+1):
    for y in range(k+1):
        z = s - x + y
        if 0<=z<=k:
            ans += 1
print(ans)
//  [python]
k,s = map(int,input().split())
ans = 0
if s>3*k:
    print(0)
elif s==3*k:
    print(1)
else:
    for i in range(k+1):
        for j in range(k+1):
            if s-k<=i+j<=s: 
                ans += 1
print(ans)
//  [python]
k,s = map(int,input().split())
ans = 0
if s>3*k:
    print(0)
elif s==3*k:
    print(1)
elif s-k<=0:
    for i in range(s+1,0,-1):
        ans += i
else:
    for i in range(k+1):
        for j in range(k+1):
            if s-k<=i+j<=s: 
                ans += 1
print(ans)
//  [java]
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] data = br.readLine().split(" ");
    
    long k = Long.parseLong(data[0]);
    long s = Long.parseLong(data[1]);
  
    long result = 0;
    
    for (int i=0; i<=k; i++){
      result += getNumAllocation(s-i, k);
    }
    
    System.out.println(result);
  }
  public static long getNumAllocation(long sum, long max){
    if (sum < 0){
      return 0;
    } else if (sum <= max){
      return sum+1;
    } else if (sum <= max*2){
      return 2*max-sum+1;
    } else {
      return 0;
    }
  }
}
//  [java]
import java.io.*;
import java.util.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Iterator<String> sc) {
		int K = Integer.parseInt(sc.next());
		int S = Integer.parseInt(sc.next());
		int sum = 0;
		for (int x = 0; x <= K && x <= S; x++) {
			int remaining = S - x;
			sum += Math.max(Math.min(remaining, K) - Math.max(remaining - K, 0) + 1, 0);
		}
		System.out.println(sum);
	}
}

class Main {
	public static void main(String... args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Iterator<String>() {
			private StringTokenizer tokenizer;

			public boolean hasNext() {
				return true;
			}

			public String next() {
				if (tokenizer == null || !tokenizer.hasMoreTokens()) {
					try {
						tokenizer = new StringTokenizer(reader.readLine());
					} catch (IOException e) {
						throw new UncheckedIOException(e);
					}
				}
				return tokenizer.nextToken();
			}
		});
	}
}
//  [java]
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int k = scanner.nextInt();
		int s = scanner.nextInt();
		scanner.close();

		int count = 0;

		for (int x = 0; x <= k; x++) {
			for (int y = 0; y <= k; y++) {
				for (int z = 0; z <= k; z++) {
					if (x + y + z == s) {
						count++;
					}
				}
			}
		}

		System.out.println(count);

	}

}
//  [java]
import java.util.*;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        
        int K = scanner.nextInt();
        int S = scanner.nextInt();
        
        
        int count = 0;
        for(int i=0;i<=K;i++){
            if(i != S){
                for(int j=0;j<=K;j++){
                    if(i+j != S){
                        count++;
                    }else if(i+j == S)
                    {
                        count++;
                        break;
                    }
                }
            }else if(i == S){
                count++;
            }
        }
        
        System.out.println(count);
    }
}
//  [java]
import java.util.*;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        
        int K = scanner.nextInt();
        int S = scanner.nextInt();
        
        
        int count = 0;
        for(int i=0;i<=K;i++){
            if(i != S){
                for(int j=0;j<=K;j++){
                    if(i+j != S){
                        for(int k=0;k<=K;k++){
                            if(i+j+k == S){
                                count++;
                                break;
                            }
                        } 
                    }else if(i+j == S)
                    {
                        count++;
                        break;
                    }else{
                        break;
                    }
                }
            }else if(i == S){
                count++;
            }
        }
        
        System.out.println(count);
    }
}
//  [cpp]
#include <cstdio>
long long a,b,c,d,i,j,k,x,y,z,ans;
int main(){
	ans=0;
	scanf("%lld %lld",&a,&b);
	for (i=0;i<=a;i++){
		x=i;
		c=b-x;
		if ((c>=0) and (c<=a)){
			ans+=c+1;
		}
		if ((c>a) and (c<=2*a)){
			ans+=2*a-c+1;
		} 
	}
	printf("%lld\n",ans);
}
//  [cpp]
#include<iostream>
using namespace std;

int main(){
	int k, s; cin >> k >> s;
	long long ans = 0;
	for(int x = 0; x <= k; ++x){
		int dec = s - x;
		if(dec < 0){
			continue;
		}
		if(dec >= k){
			dec -= k;
			if(dec > k){
				continue;
			}else{
				ans += k - dec + 1;
			}
		}else{
			ans += dec + 1;
		}
	}
	cout << ans << endl;
	return 0;
}
//  [cpp]
#include <iostream>
using namespace std;

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

int main() {
  int K, S;
  cin >> K >> S;
  int ans;
  REP(x, K+1) {
    int tmp = S - x;
    if ( tmp < 0 ) {
      break;
    } else if ( tmp > K * 2 ) {
      continue;
    } else {
      ans += tmp + 1 - 2 * max(tmp - K, 0);
    }
  }
  cout << ans << endl;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
  	if(n==k){
      return 1;
    }
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// vector<vector<int>> A(3, vector<int>(4));
int main() {
    ll k,s;
    cin>>k>>s;
    ll ans=0;
    for(int i=0; i<k; i++){
        for(int j=0; j<k; j++){
            if(s-i-j<=k&&0<=s-i-j){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
  	if(n==k){
      return 1;
    }
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// vector<vector<int>> A(3, vector<int>(4));
int main() {
    ll k,s;
    cin>>k>>s;
    ll ans=0;
    for(int i=0; i<k; i++){
        for(int j=0; j<k; j++){
            if(S-i-j<=s&&0<=S-i-j){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}
//  [cpp]
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll ans = 0;
    rep(i, min(S, K) + 1){
        if(S - i <= 2 * K && S - K > K){
            ans += K - (S - i - K) + 1;
        }else if(S - i <= K){
            ans += S - i + 1;
        }//cout << "x: " << i << ", ans: " << ans << endl;
    }

    cout << ans << endl;

    return 0;
}
//  [c]
main(k,s){scanf("%d%d",&k,&s);printf("%d\n",(++s*s+s-(k>s?0:3*(s-k)*(s-k-1))+(k*2>s?0:3*(s-2*k-1)*(s-2*k-2)))/2);}
//  [c]
int main(){
  int k,s;
  scanf("%d%d",&k,&s);
  printf("%d\n",(++s*s+s-(k>s?0:3*(s-k)*(s-k-1))+(k*2>s?0:3*(s-2*k-1)*(s-2*k-2)))/2);++s;
  return 0;
}
//  [c]
main(k,s){scanf("%d%d",&k,&s);printf("%d\n",((s+2)*(s+1)-(k>s?0:3*(s-k+1)*(s-k))+(k*2>s?0:3*(s-2*k)*(s-2*k-1)))/2);}
//  [c]
#include <stdio.h>

int main (void){
  
  int K, S;
  
  scanf("%d %d", &K, &S);
  
  int X,Y,Z;
  int count=0;
  
  for (X=0; X<=K; X++){
   for (Y=0; Y<=K; Y++){
     for (Z=0; Z<=K; Z++){
       if (X+Y+Z==S) {count=count+1;}
     }
   }
  }
  
  printf("%d", count);
  
  return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int K, S;

    scanf("%d%d", &K, &S);

    int ans = 0;

    for(int i = 0; i <= K; i++){
        if(i > S){
            break;
        }
        for(int j = 0; j <= K; j++){
            if(i + j > S){
                break;
            }
            for(int k = 0; k <= K; k++){
                if(i + j + k > S){
                    break;
                }
                if(i + j + k == S){
                    ans++;
                }
            }
        }
    }

    printf("%d\n", ans);

    return 0;
}
//  [c]
#include<stdio.h>
int main(void){
	int k,s,x,y,z,a=0;
	scanf("%d %d",&k,&s);
	for(x=0;x<=k;x++){
		if(k*2>=s-x){
			a+=(s-x+1);
		}
	}
	printf("%d",a);
	return 0;
}
//  [javascript]
function Main(input) {
	input = input.split("\n");
	tmp = input[0].split(" ");
	var max = parseInt(tmp[0], 10);
	var sum = parseInt(tmp[1], 10);
	var count = 0;
	if (sum-2*max>=0) {
		for (i=sum-2*max;i<=max;i++) {
			if (sum-max-i>=0) {
				count += 2*max-sum+i+1;
			} else {
				count += sum-i+1;
			}
		}
	} else if (sum >= max){
		for (i=0;i<=max;i++) {
			if (sum-max-i>=0) {
				count += 2*max-sum+i+1;
			} else {
				count += sum-i+1;
			}
		}
	} else {
		for (i=0;i<=sum;i++) {
				count += sum-i+1;
			}
	}
	console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
    input = input.split("\n");
    var line = input[0].split(" ");
    var K = parseInt(line[0]);
    var S = parseInt(line[1]);
    var roop = Math.min(K,S);
    var ans =0;
    for(var A=0;A<=roop;A++){
        if(S-K-A>=0){
            if(2*K-S+A+1>0){
                ans += 2*K-S+A+1;
            }
        }
        else if(S-K-A<0){
            if(S-A+1>0){
                ans += S-A+1;
            }
        }
    }
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
    input = input.split("\n");
    var line = input[0].split(" ");
    var K = parseInt(line[0]);
    var S = parseInt(line[1]);
    var roop = Math.min(K,S);
    var ans =0;
    for(var A=0;A<=roop;A++){
        if(S-K-A>=0 && 2*K-S+A+1>0){
                ans += 2*K-S+A+1;
        }
        else if(S-K-A<0 && S-A+1>0){
                ans += S-A+1;
        }
    }
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function main(input) {
  const args = input.split(' ');
  const N = parseInt(args[0], 10);
  const K = parseInt(args[1], 10);
  let count = 0;
  
  for (let x = 0; x <= N; x++) {
    for (let y = 0; y <= N; y++) {
      for (let z = 0; z <= N; z++) {
        if (K === x + y + z) { count++; }
      }
    }
  }
  console.log(count);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function m(input){
  var a = input.split(' ');
  var K = parseInt(a[0]);
  var S = parseInt(a[1]);
  var s = 0;
  for(let i=0;i<=K;i++){
    for(let j=0;j<=K;j++){
      var v = S-(i+j);
      if(v >= 0 && v <= K){
        s++;
      }
    }
  }
  console.log(s);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function m(I){
  var a = I.split(' ');
  var K = parseInt(a[0]);
  var S = parseInt(a[1]);
  var s = 0;
  for(let i=0;i<=K;i++){
    for(let j=0;j<=K;j++){
      var v = S-(i+j);
      if(v >= 0 && v <= K){
        s++;
      }
    }
  }
  console.log(s);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [go]
package main

import (
  "fmt"
)

func maxInt(a ...int) int {m := a[0]; for _, x := range a {if x > m {m = x}}; return m}
func minInt(a ...int) int {m := a[0]; for _, x := range a {if x < m {m = x}}; return m}

func main() {
  var k, s int 
  fmt.Scan(&k, &s)

  cnt := 0
  for x := 0; x <= minInt(k, s); x++ {
    t := s - x
    if t <= k {
      cnt += t + 1
    } else if t <= k * 2 {
      cnt += k - (t - k) + 1
    }
  }
  fmt.Println(cnt)
}
//  [go]
package main

import "fmt"

func main() {
	var K, S int
	fmt.Scanf("%d %d", &K, &S)

	result := 0
	for x := 0; x <= K; x++ {
		yPlusz := S - x
		if yPlusz > 2*K || yPlusz < 0 {
			continue
		} else if yPlusz > K {
			result += 2*K - yPlusz + 1
		} else {
			result += yPlusz + 1
		}
	}

	fmt.Println(result)
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var k int
	var s int
	fmt.Scan(&k)
	fmt.Scan(&s)

	count := 0
	for i := 0; i <= k; i++ {
		c := k
		if s-i < k {
			c = s - i
		}
		for j := 0; j <= c; j++ {
			if s-i-j <= k {
				count++
			}
		}
	}

	fmt.Println(count)
}
//  [go]
package main

import (
	"fmt"
)

func main() {
  var k, s int
  fmt.Scanf("%d %d", &k, &s)

  ans := 0
  for x := 0; x <= k; x++ {
    for y := 0; y <= k; y++ {
      if x + y > s {
        continue
      }
      for z := 0; z <= k; z++ {
        if x + y + z > s {
          continue
        }
        if x + y + z == s {
          ans++
      	}
      }
    }
  }
  
  fmt.Printf("%d\n", ans)
}
//  [go]
package main

import (
	"fmt"
)

func main() {
  var k, s int
  fmt.Scanf("%d %d", &k, &s)

  ans := 0
  for x := 0; x < k; x++ {
    for y := 0; y < k; y++ {
      if x + y > s {
        continue
      }
      for z := 0; z < k; z++ {
        if x + y + z > s {
          continue
        }
        if x + y + z == s {
          ans++
      	}
      }
    }
  }
  
  fmt.Printf("%d\n", ans)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanInit()

	k := nextInt()
	s := nextInt()
	cnt := 0
	for i := 0; i <= k; i++ {
		for j := 0; j <= k; j++ {
			for m := 0; m <= k; m++ {
				if i+j+m == s {
					cnt++
				}
			}
		}
	}

	fmt.Println(cnt)

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}
//  [ruby]
K, S = gets.split.map(&:to_i)
cnt = 0
min_x = [0, S - 2*K].max
max_x = [K, S].min
min_x.upto(max_x) do |i|
    rest = S - i
    if rest <= K
        cnt += rest + 1
    else
        cnt += K - (rest - K) + 1
    end
end
puts cnt
//  [ruby]
K, S = gets.chomp.split(" ").map(&:to_i)

ans = 0
(0..K).each{|i|
  next if S - i > 2 * K
  if S - i <= K then
    ans += (S - i + 1) if S - i + 1 > 0
  else
    ans += (2 * K - S + i + 1)
  end
}

puts ans
//  [ruby]
K, S = gets.split.map(&:to_i)
 
sum = 0
(0..K).each do |x|
    s = S - x
    break if s < 0
    if s <= K
        sum += s + 1
    elsif s <= 2*K
        sum += 2 * K - s + 1
    end
end
 
puts sum
//  [ruby]
k,s = gets.split.map(&:to_i)
result = 0

for x in 0..k do
  for y in 0..k do
    for z in 0..k do
      val = x+y+z
      if val == s then
        result +=1
      end
    end
  end
end      
        
print result
//  [ruby]
k, s = gets.split.map(&:to_i)

count = 0
(k + 1).times do |i|
  (k + 1).times do |j|
    count += 1 if i + j <= k
  end
end

puts count
//  [ruby]
k, s = gets.split.map(&:to_i)

count = 0
(k + 1).times do |i|
  (k + 1).times do |j|
    count += 1 if s - i - j == k
  end
end

puts count
//  [rust]
#[allow(dead_code)]
fn main() {
    let kk= i::i();
    let ss= i::i();
    let mut count=0;
    for xx in 0..(kk+1) {
        count+=max(0,min(2*kk-ss+xx+1,ss-xx+1));
    }
    println!("{}", count);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i32() -> i32 {
        read()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}
//  [rust]
use std::io::*;
use std::str::FromStr;

/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//main function
fn main() {
    let k: i32 = read();
    let s: i32 = read();
    let mut sum: i32;
    let mut count = 0;
    for i in 0..k+1{
	sum = s-i;
	if sum < 0 {
	    break;
	}
	if k >= sum {
	    count += sum+1;
	}else if k*2 >= sum{
	    count += k*2+1-sum;
	}
    }
    println!("{}",count);
}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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! {
        k: usize,
        s: usize,
    }
    let mut ans: usize = 0;
    for x in 0..k + 1 {
        if x > s {
            break;
        }
        if (x + k * 2) < s {
            continue;
        }
        let mut max: usize = k;
        let mut min: usize = 0;
        if (s - x) < k {
            max = s - x;
        }
        if (x + k) < s {
            min = s - x - k;
        }
        ans = ans + (max - min) + 1;
    }
    println!("{}", ans);
}
//  [rust]
use proconio::input;

fn main() {
    input! {
        k: i32,
        s: i32,
    }

    let mut ans = 0;

    for x in 0..=k {
        for y in 0..=k {
            for z in 0..=k {
                if x + y + z == s {
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans);
}
//  [rust]
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        k: isize,
        s: isize
    };
    let upper = std::cmp::min(k, s);
    let mut count = 0;
    // 0 <= x <= y <= z <= k で考える
    for x in 0..=upper {
        for y in x..=upper {
            let z = s - x - y;
            if (z < 0) || (z < y) || (z > k) {
                break;
            }
            count += if (x == y) && (y == z) {
                1
            } else if (x == y) || (y == z) {
                3
            } else {
                6
            };
        }
    }
    println!("{}", count);
}
//  [rust]
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        k: isize,
        s: isize
    };
    let upper = std::cmp::min(k, s);
    let mut count = 0;
    // 0 <= x <= y <= z <= k で考える
    for x in 0..=upper {
        for y in x..=upper {
            let z = s - x - y;
            if (y > z) || (z > k) {
                break;
            }
            count += if (x == y) && (y == z) {
                1
            } else if (x == y) || (y == z) {
                3
            } else {
                6
            };
        }
    }
    println!("{}", count);
}
//  [swift]
// Sum of Three Integers

func main() {
    let ks = readLine()!.split(separator: " ").map{Int($0)!}
    let k = ks[0]
    let s = ks[1]

    var count = 0

    let xmax = min(k, s)
    let xmin = max(0, s - 2 * k)
    for x in xmin...xmax {
        let ymin = max(s - x - k, 0)
        let ymax = min(s - x, k)
        let current = ymax - ymin + 1
        count += current
    }
    print(count)
}

main()
//  [swift]
import Foundation

var input_lines = [String]()
input_lines.append(readLine()!)
let strings = input_lines[0].componentsSeparatedByString(" ")

let K = (Int)(strings[0])!
let S = (Int)(strings[1])!

var counter = 0

for i in 0...K {
    if (S - i) > (K * 2) {
        continue
    }
    for j in 0...K {
        let k = (S - i - j)
        
        if 0 <= k && k <= K {
            counter += 1
        }
    }
}

print(counter)
//  [swift]
import Foundation
let a = readLine()!.split(separator: " ").map({Int($0)!})
var count = 0
for i in 0 ... a[0] {

    for j in 0 ... a[0] {
    if i + j > a[1] {
        break
    }
        if a[1] - i - j >= 0 && a[1] - i - j <= a[0] {
            count += 1
        }
    }
}
print(count)
//  [swift]
import Foundation
let a = readLine()!.split(separator: " ").map({Int($0)!})
var count = 0
if a[1] > a[0] {
for i in 0 ... a[0] {

    for j in 0 ... a[0] {
    if i + j > a[1] {
        break
    }
            for k in 0 ... a[0] {
            if i + k > a[1] || j + k > a[1] {
                break
            }
         //   print(i,j,k)
                if i + j + k == a[1] {
                    count += 1
            }
        }
    }
}
}
print(count)
//  [swift]
import Foundation
let a = readLine()!.split(separator: " ").map({Int($0)!})
var count = 0
for i in 0 ... a[0] {

    for j in 0 ... a[0] {
//    if i + j > a[1] {
//        break
//    }
            for k in 0 ... a[0] {
//            if i + k > a[1] || j + k > a[1] {
//                break
//            }
         //   print(i,j,k)
                if i + j + k == a[1] {
                    count += 1
            }
        }
    }
}
print(count)
//  [swift]
import Foundation
let a = readLine()!.split(separator: " ").map({Int($0)!})
var count = 0
for i in 0 ... a[0] {

    for j in 0 ... a[0] {
    if i + j > a[1] {
        break
    }
            for k in 0 ... a[0] {
            if i + k > a[1] || j + k > a[1] {
                break
            }
         //   print(i,j,k)
                if i + j + k == a[1] {
                    count += 1
            }
        }
    }
}
print(count)
//  [typescript]
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const k = Number(input.split(' ')[0]);

const s = Number(input.split(' ')[1]);

let result = 0;

for (let x = 0;x<k+1;x++) {
  for (let y = 0;y<k+1;y++) {
    const z = s - x - y;
    if (z > k || z < 0) {
      continue;
    }
    result++;
  }
}

console.log(result);
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [K, S] = input[0].map(Number);

  let count = 0;

  for (let X = 0; X <= K; X++) {
    for (let Y = 0; Y <= K; Y++) {
      const Z = S - (X + Y);

      if (Z >= 0 && Z <= K) {
        count += 1;
      }
    }
  }

  return count;
};

console.log(main(read()));
//  [typescript]
const fs = require('fs');

function getInput(input: string): [number, number]
{
    const [K, S] = input.split(' ').map(Number);

    return [K, S];
}

function calculate(K: number, S: number): number {
    let numberOfTriples = 0;
    const loopSize = Math.min(K, S);

    for (let X = 0; X <= loopSize; X++) {
        for (let Y = 0; Y <= loopSize; Y++) {
            const Z = S - X - Y;

            if (0 <= Z && Z <= K) {
                numberOfTriples++;
            }
        }
    }

    return numberOfTriples;
}

(() => {
    const [K, S] = getInput(fs.readFileSync('/dev/stdin', 'utf8'));

    const answer = calculate(K, S);

    console.log(answer);
})();
//  [typescript]
import * as fs from 'fs';
const input = fs.readFileSync("/dev/stdin", "utf8");
// 
const [k, s] = input.split(" ").map(it => parseInt(it));
let count = 0;

for(let ix = 0; ix <= k; ix++){
  
  for(let iy = 0; iy <= k; iy++){
    if(ix + iy > s)break;
    count++; // z はx,yが決まった時点で一意に決まる
  }
}


console.log(count);
//  [typescript]
import * as fs from 'fs';
const input = fs.readFileSync("/dev/stdin", "utf8");
// 
const [k, s] = input.split(" ").map(it => parseInt(it));
let count = 0;

for(let ix = 0; ix <= k; ix++){
  // qucik check
  let tmpX = ix;
  if(tmpX > s) break;
  
  for(let iy = 0; iy <= k; iy++){
    let tmpY = tmpX + iy;
    if(tmpY > s) break;

    for(let iz = 0; iz <= k; iz++){
      if(ix + iy + iz === s) count++;
    }
  }
}
console.log(count);
//  [typescript]
import * as fs from 'fs';
const input = fs.readFileSync("/dev/stdin", "utf8");
// 
const [k, s] = input.split(" ").map(it => parseInt(it));
let count = 0;

for(let ix = 0; ix <= k; ix++){
  for(let iy = 0; iy <= k; iy++){
    for(let iz = 0; iz <= k; iz++){
      if(ix + iy + iz === s) count++;
    }
  }
}
console.log(count);
//  [python]
from sys import stdin


def f(s, p, P, i):
    # 再帰
    # 順にスイッチを見ていく
    if len(s) == i:
        return 1 if P == p else 0
    # 場合の数
    # そのスイッチを使用しなかった場合 + 使用した場合
    return f(s, p, P, i + 1) + f(s, p, P ^ s[i], i + 1)


def main():
    lines = stdin.readlines()
    N, M = map(int, lines[0].split())
    sn = [[int(j) for j in i.split()[1:]] for i in lines[1:-1]]
    pn = (int(i) for i in lines[-1].split())
    # s[スイッチID]
    # 2進数における桁はそのスイッチを使用している電球
    s = [0] * N
    for i in range(M):
        for j in sn[i]:
            s[j - 1] |= (1 << i)
    # p
    # 2進数における桁は電球 ゼロイチをそのまま2進数とする
    p = 0
    for i, j in enumerate(pn):
        p |= (1 << i) if j == 1 else 0
    print(f(s, p, 0, 0))


main()
//  [python]
#  --*-coding:utf-8-*--

def f(T, X, S, k):
    if k == len(T):
        return 1 if S == X else 0

    return f(T, X, S, k+1) + f(T, X, S^T[k], k+1)
        

    

def main():
    N, M = map(int, input().split())

    T = [0]*N
    for i in range(M):
        L = list(map(int, input().split()))
        for sw in L[1:]:
            T[sw-1] |= (1 << i)

    X = 0
    P = map(int, input().split())
    for i, p in enumerate(P):
        X |= ((1<<i) if p == 1 else 0)



    print(f(T, X, 0, 0))


if __name__ == '__main__':
    main()
//  [python]
from sys import stdin

lines = stdin.readlines()
N, M = map(int, lines[0].split())
sn = [[int(j) for j in i.split()[1:]] for i in lines[1:-1]]
pn = (int(i) for i in lines[-1].split())
# s[スイッチID]
# 2進数における桁はそのスイッチを使用している電球
s = [0] * N
for i in range(M):
    for j in sn[i]:
        s[j - 1] |= (1 << i)
# p
# 2進数における桁は電球 ゼロイチをそのまま2進数とする
p = 0
for i, j in enumerate(pn):
    p |= (1 << i) if j == 1 else 0


def f(P, i):
    # 再帰
    # 順にスイッチを見ていく
    if len(s) == i:
        return 1 if P == p else 0
    # 場合の数
    # そのスイッチを使用しなかった場合 + 使用した場合
    return f(P, i + 1) + f(P ^ s[i], i + 1)


def main():
    print(f(0, 0))


main()
//  [python]
def i_input(): return int(input())


def i_map(): return map(int, input().split())


def i_list(): return list(i_map())


def i_row_list(n): return [i_list() for _ in range(n)]


def bit_search(n):
    bit_ans = []
    for i in range(2 ** n):
        temp = []
        for j in range(n):
            if ((i >> j) & 1):
                temp.append(1)
            else:
                temp.append(0)
        bit_ans.append(temp)
    return bit_ans


def light_check(switchpattern, lightswitches, onstat):
    cnt = 0
    for i in range(len(switchpattern)):
        if switchpattern[i] == 1 and lightswitches[i] == 1:
            cnt += 1
    if cnt % 2 == onstat:
        return 1
    else:
        return 0


n, m = i_map()
kkk = i_row_list(m)
onstates = i_list()
kkk_row = []
for i in range(m):
    tmp = [0] * n
    for j in kkk[i]:
        if j != 0:
            tmp[j - 1] = 1
    kkk_row.append(tmp)

switchpatterns = bit_search(n)
ans = 0
for switchpattern in switchpatterns:
    cnt = 0
    for i in range(m):
        cnt += light_check(switchpattern, kkk_row[i], onstates[i])
    if cnt == m:
        ans += 1

print(ans)
//  [python]
def i_input(): return int(input())


def i_map(): return map(int, input().split())


def i_list(): return list(i_map())


def i_row_list(n): return [i_list() for _ in range(n)]


def bit_search(n):
    bit_ans = []
    for i in range(2 ** n):
        temp = []
        for j in range(n):
            if ((i >> j) & 1):
                temp.append(1)
            else:
                temp.append(0)
        bit_ans.append(temp)
    return bit_ans


def light_check(switchpattern, lightswitches, onstat):
    cnt = 0
    for i in range(len(switchpattern)):
        if switchpattern[i] == 1 and lightswitches[i] == 1:
            cnt += 1
    if cnt % 2 == onstat:
        return 1
    else:
        return 0


n, m = i_map()
kkk = i_row_list(m)
onstates = i_list()
kkk_row = []
for i in range(m):
    tmp = [0] * n
    for j in range(len(kkk[i])):
        if j != 0:
            tmp[j - 1] = 1
    kkk_row.append(tmp)

switchpatterns = bit_search(n)
ans = 0
for switchpattern in switchpatterns:
    cnt = 0
    for i in range(m):
        cnt += light_check(switchpattern, kkk_row[i], onstates[i])
    if cnt == m:
        ans += 1

print(ans)
//  [python]

def i_input(): return int(input())


def i_map(): return map(int, input().split())


def i_list(): return list(i_map())


def i_row_list(N): return [i_list() for _ in range(N)]


def bit_search(n):

    bit_ans=[]
    for i in range(2 ** n):
        tmp=[]
        for j in range(n):
            if ((i >> j) & 1):
                tmp.append(1)
            else:
                tmp.append(0)
        bit_ans.append(tmp)
    return bit_ans

def light_check(switchpattern, lightswitches, onstat):
    cnt=0
    for i in range(len(switchpattern)):
        if switchpattern[i]==1 and lightswitches[i]==1:
            cnt+=1
    if cnt%2==onstat:
        return 1
    else:
        return 0



n,m = i_map()
kkk = i_row_list(m)
onstates=i_list()
kkk_row=[]
for i in range(m):
    tmp=[0]*n
    for j in range(len(kkk[i])):
        if j!=0:
            tmp[j-1]=1
    kkk_row.append(tmp)

switchpatterns=bit_search(n)
ans=0
for switchpattern in switchpatterns:
    cnt=0
    for i in range(len(kkk_row)):
        cnt+=light_check(switchpattern,kkk_row[i],onstates[i])
    if cnt==len(kkk_row):
        ans+=1

print(ans)