This page is still under construction.

Parts of this page are still being built. What you see may change.

Tree and paths of length two

Time limit2sMemory limit512 MB

Summary
Decide whether some tree on N nodes has exactly S simple paths of length 2.
Level

Medium4 of 10

Topics
Tree, Combinatorics, Greedy
Solved
No attempts yet

Problem

Given NN and SS, write a program that decides whether a tree satisfying both of the following conditions exists.

  • The tree has NN nodes.
  • The number of simple paths of length 2 is SS.

A simple path is a path that does not pass through the same vertex more than once. The length of a path is the number of edges on it, so a simple path of length 2 joins three distinct vertices.

Direction does not matter in a path. A-B-C and C-B-A count as the same path.

Input

The first line contains NN and SS separated by a space. (1≤N≤501 \le N \le 50, 1≤S≤10001 \le S \le 1000)

Output

Print 1 if such a tree can be built, and 0 if it cannot.

Examples4

  1. Example 1

    Input
    4 3
    
    Expected output
    1
    
  2. Example 2

    Input
    4 2
    
    Expected output
    1
    
  3. Example 3

    Input
    3 2
    
    Expected output
    0
    
  4. Example 4

    Input
    5 4
    
    Expected output
    1