package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"reflect"
	"sort"
	"strconv"
	"strings"
	// "regexp"
)

/* sort */
type pair struct {
	index  int64
	p1, p2 interface{}
}
type pairs []pair

func (slice pairs) Len() int {
	return len(slice)
}

func (slice pairs) Less(i, j int) bool {
	return slice[i].index < slice[j].index
}

func (slice pairs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

/* sort */
type Int64Slice []int64

func (slice Int64Slice) Len() int {
	return len(slice)
}

func (slice Int64Slice) Less(i, j int) bool {
	return slice[i] < slice[j]
}

func (slice Int64Slice) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}
func Int64s(a []int64)                    { sort.Sort(Int64Slice(a)) }
func Int64sSliceAreSorted(a []int64) bool { return sort.IsSorted(Int64Slice(a)) }

const (
	initialBufSize = 1e4
	maxBufSize     = 1e8
	INF            = 1e8
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
	di      = []int64{-1, 0, 1, 0}
	dj      = []int64{0, -1, 0, 1}
)

func main() {
	buf := make([]byte, initialBufSize)
	scanner.Buffer(buf, maxBufSize)
	scanner.Split(bufio.ScanWords)
	A, B, C := readInt(), readInt(), readInt()
	K := readInt()
	a := []int64{A, B, C}
	Int64s(a)
	a[2] = a[2] * int64(math.Pow(2, float64(K)))
	fmt.Println(sum(a))
}

/*==========================================
 *             Library
 *==========================================*/
func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}
func doubleAry(h int64, w int64, init int64) (res [][]int64) {
	res = make([][]int64, h)
	for i := int64(0); i < h; i++ {
		res[i] = make([]int64, w)
		for j := int64(0); j < w; j++ {
			res[i][j] = init
		}
	}
	return
}

func aryEq(a []int64, b []int64) bool {
	return reflect.DeepEqual(a, b)
}

func clone(n []int64) (r []int64) {
	r = make([]int64, len(n))
	for i := 0; i < len(n); i++ {
		r[i] = n[i]
	}
	return
}
func write(s string) {
	writer.WriteString(s)
}

func print() {
	writer.Flush()
}

// scanner.Split(bufio.ScanWords) をコメントアウトしないと使用不可
func readLine() (s string) {
	if scanner.Scan() {
		s = scanner.Text()
	}
	return s
}

func readInt() (read int64) {
	scanner.Scan()
	read, err := strconv.ParseInt(scanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return
}

func readFloat() (read float64) {
	scanner.Scan()
	read, err := strconv.ParseFloat(scanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return
}

func readRunes() (read []rune) {
	scanner.Scan()
	for _, v := range scanner.Text() {
		read = append(read, v)
	}
	return
}

func readString() (read string) {
	scanner.Scan()
	read = scanner.Text()
	return
}

func readStrings() (read []string) {
	scanner.Scan()
	for _, v := range scanner.Text() {
		read = append(read, string(v))
	}
	return
}

func s2i(s string) int64 {
	var intVal, e = strconv.ParseInt(s, 10, 64)
	if e != nil {
		panic(e)
	}
	return intVal
}

func i2s(i int64) string {
	var strVal = strconv.FormatInt(i, 10)
	return strVal
}

func s2f(s string) float64 {
	var floatVal, e = strconv.ParseFloat(s, 64)
	if e != nil {
		panic(e)
	}
	return floatVal
}

func abs(i int64) int64 {
	return int64(math.Abs(float64(i)))
}

func max(a ...int64) int64 {
	ans := int64(0)
	for i, v := range a {
		if i == 0 {
			ans = v
		}
		if ans < v {
			ans = v
		}
	}
	return ans
}
func min(a ...int64) int64 {
	ans := int64(0)
	for i, v := range a {
		if i == 0 {
			ans = v
		}
		if ans > v {
			ans = v
		}
	}
	return ans
}

func sum(i []int64) int64 {
	sum := int64(0)
	for _, val := range i {
		sum += val
	}
	return sum
}

func split(s string) []string {
	return strings.Fields(s)
}

func strAry2intAry(strs []string) []int64 {
	var ret = make([]int64, 0, len(strs))
	for _, str := range strs {
		var intVal = s2i(str)
		ret = append(ret, intVal)
	}
	return ret
}

func intAry2strAry(nums []int64) []string {
	var ret = make([]string, 0, len(nums))
	for _, num := range nums {
		var strVal = i2s(num)
		ret = append(ret, strVal)
	}
	return ret
}

func ary2str(strs []string) string {
	return strings.Join(strs, " ")
}

func reverse(res []int64) []int64 {
	for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 {
		res[i], res[j] = res[j], res[i]
	}
	return res
}
func reverseStr(res []string) []string {
	for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 {
		res[i], res[j] = res[j], res[i]
	}
	return res
}

func ini(res []int, init int) {
	if len(res) == 0 {
		return
	}
	res[0] = init
	for i := 0; i < len(res); i++ {
		copy(res[i:], res[:i])
	}
}

//
// func regexpExample() {
//     // Your code here!
//     var str = "13:20"
//     r := regexp.MustCompile(`(\d+):(\d+)`)
//     fmt.Println(r.FindStringSubmatch(str))
// }

// type Country struct {
//     gold int
//     silver int
//     blonze int
// }

// // 複数ソートのサンプル
// func stableSortExample() []Country{
//     var country = []Country {
//         {gold:1, silver:2, blonze:3},
//         {gold:1, silver:2, blonze:3},
//         {gold:1, silver:3, blonze:2},
//         {gold:1, silver:3, blonze:3},
//     }
//     sort.SliceStable(country, func(i, j int) bool { return country[i].blonze > country[j].blonze })
//     sort.SliceStable(country, func(i, j int) bool { return country[i].silver > country[j].silver })
//     sort.SliceStable(country, func(i, j int) bool { return country[i].gold > country[j].gold })
//     return country
// }


package main

import (
	"fmt"
	"math"
)

func main() {
	var A, B, C int
	var K float64
	fmt.Scanf("%d %d %d", &A, &B, &C)
	fmt.Scan(&K)

	if A > B && A > C {
		A *= int(math.Pow(2, K))
		fmt.Println(A)
	} else if B > C {
		B *= int(math.Pow(2, K))
	} else {
		C *= int(math.Pow(2, K))
	}
}


package main

import (
	"fmt"
	"math"
	"sort"
)

// maxInt はint型のスライスの最大値を返す関数
func maxInt(a []int) int {
	sort.Sort(sort.IntSlice(a))
	return a[len(a)-1]
}

func main() {
	var n1, n2, n3 int
	var num int

	fmt.Scanf("%d %d %d", &n1, &n2, &n3)
	fmt.Scanf("%d", &num)

	fmt.Println(n1 + n2 + n3*int(math.Pow(float64(2), float64(num))))
}


package main

import (
	"fmt"
	"sort"
)

// maxInt はint型のスライスの最大値を返す関数
func maxInt(a []int) int {
	sort.Sort(sort.IntSlice(a))
	return a[len(a)-1]
}

func main() {
	var n1, n2, n3 int
	var num int

	fmt.Scanf("%d %d %d", &n1, &n2, &n3)
	fmt.Scanf("%d", &num)

	fmt.Println(n1 + n2 + n3 + num*maxInt([]int{n1, n2, n3}))
}


# frozen_string_literal: true

a, b, c = gets.split.map(&:to_i).sort
k = gets.to_i

puts a + b + 2**k * c


abc = gets.chomp.split(' ').map(&:to_i)
k = gets.chomp.to_i
puts abc.max * (2 ** k) + abc.min(2).inject(:+)


# https://atcoder.jp/contests/abc096/tasks/abc096_b

A, B, C = gets.split.map(&:to_i).sort
K = gets.to_i

puts A + B + C * (2 ** K)


ary = gets.split.map(&:to_i).sort
k = gets.to_i
k.times do
  a[2] *= 2
end
puts a.inject(:+)


ary = gets.split.map(&:to_i)
k = gets.to_i
max = ary.max
k.times do
  max*=2
end
ary.delete(ary.max)
ary.each do |i| max+=i end
puts max


ary = gets.split.map(&:to_i)
k = gets.to_i
max = ((ary.max)*k*2)
ary.delete(ary.max)
ary.each do |i| max+=i end
puts max


use text_io::*;
use std::cmp::*;

fn main() {
    let a: i32 = read!();
    let b: i32 = read!();
    let c: i32 = read!();
    let d: u32 = read!();
    let e: i32 = max(a,max(b,c));
    println!("{}",a+b+c-e+e*2_i32.pow(d))
}


use std::io::*;
use std::str::FromStr;

pub 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")
}

use std::cmp::max;

fn main() {
    let a: usize = read();
    let b: usize = read();
    let c: usize = read();
    let k: usize = read();
    let maxv = max(a, max(b, c));

    let mut ans = a + b + c;
    let mut kmaxv = maxv;
    let mut cnt = 0;

    while cnt < k {
        cnt += 1;
        kmaxv *= 2;
    }
    ans += kmaxv;
    println!("{}", ans - maxv);
}


use std::io;
use std::cmp::max;

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 mut a = v[0];
	let mut b = v[1];
	let mut c = v[2];
	let mut ret = 0;
	let v:Vec<i32> = procon_read();
	let k = v[0];
	for i in 0..k {
		ret = max(max(2*a+b+c, a+2*b+c), a+b+2*c);
		if ret == 2*a+b+c {
			a = 2*a;
		}else if ret == a+2*b+c {
			b = 2*b;
		}else{
			c = 2*c;
		}
	}
	println!("{}", ret);
}


#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;

    input!{
        a: usize, b: usize, c: usize, k: usize,
    }

    let v = vec![a, b, c];
    let max = v.iter().max().unwrap();
    let others_sum = v
                            .iter()
                            .filter(|x| *x != max)
                            .sum::<usize>();
    println!("{}", max * 2usize.pow(k as u32) + others_sum);
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


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! {
        abc: [u32;3],
        k: u32,
    }
    let mx = abc.iter().max().unwrap();
    println!("{}",
        abc.iter().sum::<u32>() - mx + mx * 2 * k);
}


// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"5 3 11
1"# => r#"30"#,

r#"3 3 4
2"# => r#"22"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        mut abc: [u64; 3],
        k: u64,
    }
    abc.sort();
    (abc[0] + abc[1] + abc[2] * (2 * k)).to_string()
}


import Foundation

let abc = readLine()!.componentsSeparatedByString(" ")
let k = Int(readLine()!)!
let a = Int(abc[0])!
let b = Int(abc[1])!
let c = Int(abc[2])!

var m = max(a, b, c)
var m2: Int = m
for i in 0..<k {
    m2 *= 2
}

var m3: Int = 0
if m == a {
    m3 = m2 + b + c
} else if m == b {
    m3 = m2 + a + c
} else if m == c {
    m3 = m2 + a + b
}

print("\(m3)")


import Foundation

let line = readLine()!
let numbers = line.componentsSeparatedByString(" ")

var first = Int(numbers[0])!
var second = Int(numbers[1])!
var third = Int(numbers[2])!

let count = Int(readLine()!)!

for _ in 0..<count {
    if first >= second && first >= third {
        first = first * 2
    } else if second >= first && second >= third {
        second = second * 2
    } else if third >= first && third >= second {
        third = third * 2
    }
}

print("\(first + second + third)")


import Foundation

main()

func main() {
    let abc = readLine()!.split(separator: " ").map { Int($0)! }
    let k = Double(readLine()!)!
    let sorted = abc.sorted()
    let ans = sorted.reduce(sorted.last! * (Int(pow(2.0, k)) - 1), +)
    print(ans)
}


import Foundation

let allLines = readLine()!
let count = Int(allLines.components(separatedBy: "\n")[1])!
let numbers = allLines.components(separatedBy: "\n")[0].components(separatedBy: " ")

var first = Int(numbers[0])!
var second = Int(numbers[1])!
var third = Int(numbers[2])!

for _ in 0..<count {
    if first >= second && first >= third {
        first = first * 2
    } else if second >= first && second >= third {
        second = second * 2
    } else if third >= first && third >= second {
        third = third * 2
    }
}

print("\(first + second + third)")


import Foundation

let abc = readLine()!.componentsSeparatedByString(" ")
let k = Int(readLine()!)!
let a = Int(abc[0])!
let b = Int(abc[1])!
let c = Int(abc[2])!

var m = max(a, b, c)
var m2: Int = 0
for i in 0..<k {
    m2 = m * 2
}

var m3: Int = 0
if m == a {
    m3 = m2 + b + c
} else if m == b {
    m3 = m2 + a + c
} else if m == c {
    m3 = m2 + a + b
}

print("\(m3)")


import Foundation

let abc = readLine()!. componentsSeparatedByString(" ")
let k = Int(readLine()!)!
let a = Int(abc[0])!
let b = Int(abc[1])!
let c = Int(abc[2])!

var m = max(a, b, c)
var m2: Int = 0
for i in 0..<k {
    m2 = m * 2
}

var m3: Int = 0
if m == a {
    m3 = m2 + b + c
} else if m == b {
    m3 = m2 + a + c
} else if m == c {
    m3 = m2 + a + b
}

print("\(m3)")


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 a=tnn(3)
  let k=tn()
  let m=a.indexOf(Math.max(null,...a))
  for(let i=0;i<k;i++){
    a[m]*=2
  }
  to(a.reduce((a,x) => a+=x,0))
}
main()


const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const [a, b, c] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const k = Number(stdin.split('\n')[1])

const ans = _ => {
  const nums = [a, b, c]

  nums.sort((a, b) => b - a)

  nums[0] *= 2 ** k

  return nums.reduce((p, c) => p + c)
}

console.log(ans())


import * as fs from 'fs';

namespace AtCoder.abc096 {
    export class Program {
        constructor(private readonly args: string[][]) {
        }

        main(this: Program) {
            const abc: number[] = this.args[0].map(Number);
            const [k]: number[] = this.args[1].map(Number);
            const max: number = Math.max(...abc);
            const shifted: number = (max << k) - max;
            const ans: number = abc.reduce((acc: number, cur: number) => acc + cur) + shifted;

            console.log(ans);
        }
    }
}

const args: string[][] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(x => x.split(' '));
const prg: AtCoder.abc096.Program = new AtCoder.abc096.Program(args);
prg.main();


import * as fs from 'fs';

namespace AtCoder.abc096 {
    export class Program {
        constructor(private readonly args: string[][]) {
        }

        main(this: Program) {
            const abc: number[] = this.args[0].map(Number);
            const [k]: number[] = this.args[1].map(Number);
            const max: number = Math.max(...abc);
            const shifted: number = max << k - 1;
            const ans: number = abc.reduce((acc: number, cur: number) => acc + cur) + shifted;

            console.log(ans);
        }
    }
}

const args: string[][] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(x => x.split(' '));
const prg: AtCoder.abc096.Program = new AtCoder.abc096.Program(args);
prg.main();


const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const [a, b, c] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const k = Number(stdin.split('\n')[1])

const ans = _ => {
  const nums = [a, b, c]

  nums.sort((a, b) => b - a)

  nums[0] *= 2 * k

  return nums.reduce((p, c) => p + c)
}

console.log(ans())


n=int(input())

table = [105,135,165,189,195]

print(sum([1 for x  in table if x <= n]))


n = int(input())
if n < 105:
    print(0)
elif n < 135:
    print(1)
elif n < 165:
    print(2)
elif n < 189:
    print(3)
elif n < 195:
    print(4)
else:
    print(5)


#! usr/bin/env python
# -*- coding: utf-8 -*-

def main():
    n = int(input())

    ans = 0
    for i in range(1, n+1):
        if i % 2 == 0:
            continue
        div = []
        j = 1
        while j * j <= i:
            if i % j == 0:
                if i // j != j:
                    div.append(j)
                    div.append(i//j)
                else:
                    div.append(j)
            j += 1

        if len(div) == 8:
            ans += 1

    print(ans)

if __name__ == '__main__':
    main()


n = int(input())
if n < 105:
  print(0)
elif n < 165:
  print(1)
elif n < 195:
  print(2)
else:
  print(3)


import sys
import sympy

ans = 0
for i in range(1, int(input())+1):
    ans += 1 if i%2==1 and len(sympy.divisors(i)) == 8 else 0
print(ans)


N = int(input())

def make_divisor(n):
    divisors = []
    for i in range(1, int(n**.5) + 1):
        if n%i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

for i in range(1, N+1):
    if len(make_divisor(i)) == 8 and  i%2 == 1:
        print(i)
        exit()
print(0)


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            int ans = 0;
            for (int i = 1; i <= n; i = i + 2) {
                int count = 0;
                for (int j = 1; j <= i; j++) {
                    if (i % j == 0) {
                        count++;
                    }
                }
                if (count == 8) {
                    ans++;
                }
            }
            System.out.println(ans);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}


import java.util.HashSet;
import java.util.Set;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n =  Integer.parseInt(br.readLine());
        int count = 0;
        int ans = 0;

        for (int i = 1; i <= n; i++) {
            if (i%2==0) continue;
            for (int j = 1; j <= i; j++) {
                if (i % j == 0) count++;
            }

            if (count == 8) ans++;
            count = 0;
        }
        System.out.println(ans);
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n=sc.nextInt();
		boolean[] aa = new boolean[201];
		for(int i=0;i<201;i++){
			aa[i]=printDivisors(i);
//			System.out.println(aa[i]+" "+i);
			}
		int cnt=0;
		for(int i=1;i<=n;i+=2)if(aa[i])cnt++;
		System.out.println(cnt);
	}
	static boolean printDivisors(int n)
    {
		int cnt=0;
        for (int i=1;i<=n;i++)
            if (n%i==0)
                cnt++;
        return cnt==8;
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        int res = 0;
        for (int i = 1; i <= n; i++) {
            if (divisors(i) == 8) {
                res++;
            }
        }
        System.out.println(res);
    }

    private static int divisors(int n) {
        int res = 0;
        for (int p = 1; p * p <= n; p++) {
            if (n % p == 0) {
                if (p * p == n) {
                    res++;
                } else {
                    res += 2;
                }
            }
        }
        return res;
    }

    static final class Util {
        public static void shuffleSort(int[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffleSort(long[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffle(int[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void shuffle(long[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void swap(int[] x, int i, int j) {
            final int t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        public static void swap(long[] x, int i, int j) {
            final long t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        private Util() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        System.out.println(divisors(n));
    }

    private static int divisors(int n) {
        int res = 2;
        for (int p = 2; p * p <= n; p++) {
            if (n % p == 0) {
                if (p * p == n) {
                    res++;
                } else {
                    res += 2;
                }
            }
        }
        return res;
    }

    static final class Util {
        public static void shuffleSort(int[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffleSort(long[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffle(int[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void shuffle(long[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void swap(int[] x, int i, int j) {
            final int t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        public static void swap(long[] x, int i, int j) {
            final long t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        private Util() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        //char[] S = sc.next().toCharArray();
        int count=0;
        int yakusuu=0;
        int n;
        for(int i=0; 2*i<N; i++){
            n = 2*i+1;
            for(int k=1; k<n+1; k++){
                if(n%k==0){
                    yakusuu++;
                }
            }
            if(yakusuu==8){
                count++;
            }

        }

          System.out.println(count);
        }
    }


#include <cstdio>

int main()
{
  int n;
  scanf("%d", &n);
  puts(n < 105 ? "0" : n < 135 ? "1" : n < 165 ? "2" : n < 189 ? "3" : n < 195 ? "4" : "5");
  return 0;
}


#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int solve(int n)
{
    int ans = 0;
    for(int i=1; i<=n; ++i){
        if(n % i == 0)
            ++ ans;
    }
    return ans;
}

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

    int ans = 0;
    for(int i=1; i<=n; i+=2){
        if(solve(i) == 8)
            ++ ans;
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  cin>>n;
  int ans = 0;
  FOR(i,1,n+1)if(i%2==1){
    int cnt = 0;
    FOR(j,1,i+1)if(i%j==0)cnt++;
    if(cnt==8)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int cnt = 0;
        for (int j = 1; j*j <= i; j++) {
            if (i%j == 0) cnt++;
        }
        cnt++;
        if (cnt == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int n, result = 0, counts = 0;

    cin >> n;

    if (n < 105)
    {
        cout << 0 << endl;
        return 0;
    }

    for (int i = 1; i * i <= n; i++)
    {
        if ((n % i) == 0)
        {
            counts++;
            if(n/i != i) counts++;
        }
    }
    if(counts == 8) result++;
    counts = 0;

    cout << result << endl;
    return 0;
}


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

int main()
{
    int n, result = 0, counts = 0;

    cin >> n;

    if (n < 105)
    {
        cout << 0 << endl;
        return 0;
    }

    for (int j = 105; j <= n; )
    {

        for (int i = 1; i * i <= j; i++)
        {
            if ((n % i) == 0)
            {
                counts++;
                if(j/i != i) counts++;
            }
        }
        if(counts == 8) result++;
        counts = 0;
        j += 2;

    }

    cout << result << endl;
    return 0;
}


#include <stdio.h>
int main() {

	int n;
	scanf("%d", &n);
	if (n < 105)printf("%d", 0);
	if (105 <= n && n < 135)printf("%d", 1);
	if (n >= 135 && n < 165)printf("%d", 2);
	if (165 <= n && n < 189)printf("%d", 3);
	if (n >= 189 && n < 195)printf("%d", 4);
	if (n >= 195)printf("%d", 5);
	return 0;
}


#include<stdio.h>

int main(void)

{
    int i,n;
    scanf("%d",&n);
    if(1<=n && n<105){
        i=0;
    }else{
        if(105<=n && n<135){
        i=1;
    }else{
        if(135<=n && n<165){
        i=2;
    }else{
        if(165<=n && n<189){
        i=3;
    }else{
        if(189<=n && n<195){
        i=4;
    }else{
        i=5;
    };
    };
    };
    };
    };
    printf("%d",i);
    return 0;
}


#include<stdio.h>

int main(void)
{
        int n,i,j,a,b,c;

        scanf("%d",&n);

        c=0;
        for(i=1;i<=n;i+=2){
                b = 0;
                for(j=1;j<=i;j++){
                        a = i % j;
                        if(a==0)
                                b++;
                }
                if(b==8)
                c++;
        }

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


#include<stdio.h>

int main(void){
    int n, i, j, x, a;

    scanf("%d", &n);

    a = 0;
    for(i=1; i<=n; i=i+2){
        x = 0;
        for(j=1; j<i; j++){
            if(i%j == 0){
                x++;
            }
        }
        if(x == 8){
            a++;
        }
    }
    printf("%d\n", a);
}


#include<stdio.h>

int main(void){
    int n, i, x;

    scanf("%d", &n);

    x = 0;
    for(i=1; i<=n; i=i+2){
        if(n%i == 0){
            x++;
        }
    }
    printf("%d\n", x);
}


#include <stdio.h>
#include <stdlib.h>

int main(){
	int n;
	if(scanf("%d", &n)==EOF){return 0;}
	int count = 0;
	int count_sub = 0;

	if(n<105){printf("0\n"); return 0;}
	for(int i = 105; i <= n; i++){
		if(i % 2 == 0){continue;}
		for(int j = 3; j < i; j++){
			if(i % j == 0){count_sub++;}
		}
		//その他j=1, i で割り切れる
		if(count_sub == 6){count++;}
	}

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

}


function Main(input){
	if(input<=104){
		console.log(0)
	}else if(input<=134){
		console.log(1)
	}else if(input<=164){
		console.log(2)
	}else if(input<=188){
		console.log(3)
	}else if(input<=194){
		console.log(4)
	}else{
		console.log(5)
	}
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


function Main(s){
  var n = +s;
  var ans = 0;
  for(var i = 1; i <= n; i += 2){
    var f = 0;
    for(var j = 1; j <= i; j++){
      if(i % j === 0)f++;
    }
    if(f === 8)ans++;
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));


function Main(input) {
  var n = [105,135,165,189,195];
  console.log(n.filter(x=>x<=input).length);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(lines) {
    const input = lines.split('\n').map(Number)[0]
    var count = 0
    for(var i=1; i<=input; i++){
        if(input%i === 0 && i%2 === 1){
            var tmpCount = 0;
            for(var k=1; k<=i; k++){
                if(i%k === 0){
                    tmpCount++
                }
            }
            if(tmpCount === 8){
                count++
            }
        }
    }
    console.log(count)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {
  var N = input[0]-0;
  var ans = 0;
  for(var i=105;i<=N;i++){
    var cnt = 0;
    for(var j=1;j<=i;j++){
      if(i%j==0) cnt++;
      if(cnt>8) break;
    }
    if(cnt == 8) ans++;
  }
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


"use strict"

function main(input) {
  input = ~~input

  let total = 0
  for (let i = input; i > 0; i -= 2) {
    let cnt = 0
    for (let j = 1; j <= i; j++) {
      cnt += i % j == 0 ? 1 : 0
    }
    total += cnt == 8 ? 1 : 0
  }
  console.log(total)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"))


package main

import (
  "fmt"
  "sort"
)
func biL(a []int, x int) int {return sort.SearchInts(a, x)}
func biR(a []int, x int) int {return sort.Search(len(a), func(i int) bool {return a[i] > x})}

func main() {
  var n int
  fmt.Scan(&n)
  cand := []int{105, 165, 195, 135, 189}
  sort.Ints(cand)
  fmt.Println(biR(cand, n))
}


package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var eightDivisorCount int
	for i := 1; i <= n; i += 2 {
		var count int
		for j := 1; j <= n; j++ {
			if i%j == 0 {
				count++
			}
		}
		if count == 8 {
			eightDivisorCount++
		}
	}
	fmt.Println(eightDivisorCount)
}


package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	var cnt int
	for i := 1; i <= n; i += 2 {
		d := 0
		for j := 1; j <= i; j += 2 {
			if i%j == 0 {
				d++
			}
		}
		if d == 8 {
			cnt++
		}
	}
	fmt.Println(cnt)
}


package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)

	if N == 105 {
		fmt.Println(1)
		return
	}
	fmt.Println(0)

}


package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	fmt.Printf("%d¥n", find(n))
}

func find(n int) int {
	var num int
	for i := 1; i <= n; i++ {
		if i%2 == 1 && divisorNumIs(i, 8) {
			num++
		}
	}
	return num
}

func divisorNumIs(n, divisor int) bool {
	life := divisor - 2
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			if n/i == i {
				life--
			} else {
				life -= 2
			}
		}
		if life < 0 {
			break
		}
	}
	return life == 0
}


package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)

	ans := 0
	for i := 1; i <= N; i += 2 {
		tmp := 0
		for j := 1; j <= i; j++ {
			if N%j == 0 {
				tmp++
			}
		}
		if tmp == 8 {
			ans++
		}
	}
	fmt.Println(ans)
}


def divisors_of(num)
  ans = []
  1.upto(Math.sqrt(num)) do |i|
    next unless num % i == 0

    ans << i
    ans << num / i
  end
  ans
end

n = gets.to_i

ans = 0
1.step(n, 2) do |i|
  ans += 1 if divisors_of(i).length == 8
end

puts ans


N = gets.to_i

puts 105.step(N, 2).select {|o|
  1.upto(o).select {|i| o % i == 0}.length == 8
}.length


n = gets.chomp.to_i

def divisor(num)
  result = []
  i = 1
  while i <= num do
    remainder = num % i
    if remainder == 0
      result << i
    end
    i += 1
  end
  return result
end

res = 0

1.upto(n) do |i|
  res += 1 if i.odd? && divisor(i).length == 8
end

puts res


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


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


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


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


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


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


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


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


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


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


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)


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)


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)


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


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)


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()


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


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'));


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


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)


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)


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)


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)


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)


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)


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


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


import java.io.*;
import java.util.*;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

class Main{

    static FastScanner scan = new FastScanner();
    static final int MOD = 1_000_000_007;
    static final int INF = 2147483647;
    static final long LINF = 9223372036854775807L;

    // Scanner
    int ni(){return scan.nextInt();}
    int[] ni(int n){int[] a = new int[n]; for(int i = 0; i < n; i++){a[i] = ni();} return a;}
    int[][] ni(int y, int x){int[][] a = new int[y][x];
        for(int i = 0; i < y; i++){for(int j = 0; j < x; j++){a[i][j] = ni();}} return a;}
    long nl(){return scan.nextLong();}
    long[] nl(int n){long[] a = new long[n]; for(int i = 0; i < n; i++){a[i] = nl();} return a;}
    long[][] nl(int y, int x){long[][] a = new long[y][x];
        for(int i = 0; i < y; i++){for(int j = 0; j < x; j++){a[i][j] = nl();}} return a;}
    String ns(){return scan.next();}
    String[] ns(int n){String[] a = new String[n]; for(int i = 0; i < n; i++){a[i] = ns();} return a;}
    String[][] ns(int y, int x){String[][] a = new String[y][x];
        for(int i = 0; i < y; i++){for(int j = 0; j < x; j++){a[i][j] = ns();}} return a;}

    // Math
    int max(int a, int b){return Math.max(a, b);}
    long max(long a, long b){return Math.max(a, b);}
    double max(double a, double b){return Math.max(a, b);}
    int max(int[] a){int max = a[0]; for(int value:a){max = max(max,value);} return max;}
    long max(long[] a){long max = a[0]; for(long value:a){max = max(max,value);} return max;}
    double max(double[] a){double max = a[0]; for(double value:a){max = max(max,value);} return max;}
    int min(int a, int b){return Math.min(a, b);}
    long min(long a, long b){return Math.min(a, b);}
    double min(double a, double b){return Math.min(a, b);}
    int min(int[] a){int min = a[0]; for(int value:a){min = min(min,value);} return min;}
    long min(long[] a){long min = a[0]; for(long value:a){min = min(min,value);} return min;}
    double min(double[] a){double min = a[0]; for(double value:a){min = min(min,value);} return min;}
    long sum(int[] a){long sum = 0; for(int value:a){sum += value;} return sum;}
    long sum(long[] a){long sum = 0; for(long value:a){sum += value;} return sum;}
    double sum(double[] a){double sum = 0; for(double value:a){sum += value;} return sum;}
    int gcd(int a, int b){return b == 0 ? a : gcd(b, a % b);}
    long gcd(long a, long b){return b == 0 ? a : gcd(b, a % b);}
    int lcm(int a, int b){return a / gcd(a, b) * b;}
    long lcm(long a, long b){return a / gcd(a, b) * b;}
    long fact(int n){ if(n == 0){ return 1; } long a = n; for(long i = n - 1; i >= 2; i--){ a *= i; } return a; }
    long fact(long n){ if(n == 0){ return 1; } long a = n; for(long i = n - 1; i >= 2; i--){ a *= i; } return a; }
    long ncr(int n, int r){
        long a = 1;
        for(int i = n; i > n - r; i--){
            a *= i;
        }
        long b = fact(r);
        return a / b;
    }
    long ncr(long n, long r){
        long a = 1;
        for(long i = n; i > n - r; i--){
            a *= i;
        }
        long b = fact(r);
        return a / b;
    }
    long npr(int n, int r){
        long a = 1;
        for(int i = n; i > n - r; i--){
            a *= i;
        }
        return a;
    }
    long npr(long n, long r){
        long a = 1;
        for(long i = n; i > n - r; i--){
            a *= i;
        }
        return a;
    }

    // Array
    void sort(int[] a){ Arrays.sort(a);}
    void sort(long[] a){ Arrays.sort(a);}
    void sort(double[] a){ Arrays.sort(a);}
    void sort(String[] a){ Arrays.sort(a);}
    int[] reverse(int[] a){
        int[] reversed = new int[a.length];
        for(int i = 0; i < a.length; i++){
            reversed[a.length - i - 1] = a[i];
        }
        return reversed;
    }
    long[] reverse(long[] a){
        long[] reversed = new long[a.length];
        for(int i = 0; i < a.length; i++){
            reversed[a.length - i - 1] = a[i];
        }
        return reversed;
    }
    double[] reverse(double[] a){
        double[] reversed = new double[a.length];
        for(int i = 0; i < a.length; i++){
            reversed[a.length - i - 1] = a[i];
        }
        return reversed;
    }
    char[] reverse(char[] a){
        char[] reversed = new char[a.length];
        for(int i = 0; i < a.length; i++){
            reversed[a.length - i - 1] = a[i];
        }
        return reversed;
    }
    String[] reverse(String[] a){
        String[] reversed = new String[a.length];
        for(int i = 0; i < a.length; i++){
            reversed[a.length - i - 1] = a[i];
        }
        return reversed;
    }
    boolean[] reverse(boolean[] a){
        boolean[] reversed = new boolean[a.length];
        for(int i = 0; i < a.length; i++){
            reversed[a.length - i - 1] = a[i];
        }
        return reversed;
    }
    void fill(int[] array, int x) { Arrays.fill(array, x); }
    void fill(long[] array, long x) { Arrays.fill(array, x); }
    void fill(double[] array, double x) { Arrays.fill(array, x); }
    void fill(boolean[] array, boolean x) { Arrays.fill(array, x); }
    void fill(int[][] array, int x) { for(int a[] : array) { fill(a, x); } }
    void fill(long[][] array, long x) { for(long a[] : array) { fill(a, x); } }
    void fill(double[][] array, double x) { for(double a[] : array) { fill(a, x); } }
    void fill(boolean[][] array, boolean x) { for(boolean a[] : array) { fill(a, x); } }

    // Collection
    void sort(){}
    void sortrev(){}
    // Scanner
    // StringBuilder
    // ArrayList<> nial(int n)
    // LinkedList<> nill(int n)
    // Deque<> nidq(int n)
    // PriorityQueue<> nipq(int n)
    // PriorityQueue<> nipqrev(int n) reverseOrder
    // ex) PriorityQueue<Integer> a = nipq(n);

    public void solve(){
        int k = ni();
        int s = ni();

        int count = 0;
        for(int a = 0; a <= k; a++){
            for(int b = 0; b <= k; b++){
                int c = s - a - b;
                if(c >= 0 && c <= k){
                    count++;
                }
            }
        }

        System.out.println(count);

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


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

	}

}


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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"));


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"));


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"));


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'));


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'));


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'));


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


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


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


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


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


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()
}


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


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


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


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


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


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


#[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()
    }
}


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


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


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


#![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);
}


#![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);
}


// 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()


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)


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)


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)


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)


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)


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


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()));


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


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


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


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


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()


#  --*-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()


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()


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)


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)


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)


import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.stream.IntStream;

public class Main {

	class Container {
		String cityName;
		int score;
		int i;

		Container(String cityName, int score, int i) {
			this.cityName = cityName;
			this.score = score;
			this.i = i;
		}
	}

	// invoked from main
	private void solve() throws Exception {
		int N = in.i(), M = in.i();
		int[] pow2 = new int[N+1];
		pow2[0] = 1;
		for (int i = 1; i <= N; i++)
			pow2[i] = 2*pow2[i-1];

		// 電球M個のon条件をbitで表す
		int[] s = new int[M];
		for (int i = 0; i < M; i++) {
			s[i] = 0;
			int k_i = in.i();
			for (int j = 0; j < k_i; j++)
				s[i] += pow2[in.i()-1];
		}

		int[] p = new int[M];
		for (int i = 0; i < M; i++)
			p[i] = in.i();

		int count = 0;
		label: for (int i = 0; i < pow2[N]; i++) {
			for (int j = 0; j < M ; j++)
				if (Integer.bitCount(i & s[j]) % 2 != p[j])
					continue label;
			count++;
		}

		out.println(count);
	}

	public static void main(String[] args) throws Exception {
		instance.solve();
	}

	static PrintStream out = System.out;
	static FastReader in = new FastReader();
	static Main instance = new Main();
}

class FastReader {
	final private int BUF_SIZE = 1 << 16;
	private DataInputStream din = new DataInputStream(System.in);
	private byte[] buffer = new byte[BUF_SIZE];
	private int bufferPointer, bytesRead;

	String s() throws IOException {
		return s(64);
	}

	// make for line
	String s(int capacity) throws IOException {
		byte[] buf = new byte[capacity];
		int cnt = 0, c;
		while ((c = c()) != -1) {
			if (Character.isSpaceChar(c)) break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	int i() throws IOException {
		int ret = 0;
		byte c = c();
		while (c <= ' ') c = c();
		boolean neg = (c == '-');
		if (neg) c = c();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = c()) >= '0' && c <= '9');
		return neg ? -ret : ret;
	}

	long l() throws IOException {
		long ret = 0;
		byte c = c();
		while (c <= ' ') c = c();
		boolean neg = (c == '-');
		if (neg) c = c();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = c()) >= '0' && c <= '9');
		return neg ? -ret : ret;
	}

	double d() throws IOException {
		double ret = 0, div = 1;
		byte c = c();
		while (c <= ' ') c = c();
		boolean neg = (c == '-');
		if (neg) c = c();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = c()) >= '0' && c <= '9');
		if (c == '.')
			while ((c = c()) >= '0' && c <= '9')
				ret += (c - '0') / (div *= 10);
		return neg ? -ret : ret;
	}

	private void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUF_SIZE);
		if (bytesRead == -1) buffer[0] = -1;
	}

	byte c() throws IOException {
		if (bufferPointer == bytesRead) fillBuffer();
		return buffer[bufferPointer++];
	}
}