Time limit
2s
Memory limit
128 MB
Artists who love art have gathered at a market to trade a painting. Every trade must satisfy both rules below.
A new painting has just arrived at the market. Artist 1 bought it from an outside merchant for price 0, and can now sell it to other artists. Assuming only trades that satisfy the rules are made, find the maximum number of people who can own the painting at least once. Count Artist 1 and the final owner as well.
The first line contains the number of artists, N. N is an integer with 2 <= N <= 15.
Each of the next N lines contains N digits. The j-th digit on the i-th line is the price that artist j pays to buy the painting from artist i. Price 0 is the lowest price, and price 9 is the highest.
Print the maximum number of people who can own the painting, including anyone who owns it only briefly.