PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BF0000051. Kinh doanh chênh lệch tỷ giá (Arbitrage)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Kinh doanh chênh lệch tỷ giá (Arbitrage)

Arbitrage

Source: POJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn named currencies and mm directed exchange rates, decide whether any cyclic sequence of exchanges yields more than the initial amount of currency.

Input

Read nn currency names, then mm directed rates source rate target.

Output

Print Yes or No.

Subtasks

  • Subtask 1 (20 points): 1≤n≤51\le n\le5, 0≤m≤150\le m\le15; Each name has no spaces; all rates are positive real numbers.
  • Subtask 2 (30 points): 1≤n≤151\le n\le15, 0≤m≤1200\le m\le120; Each name has no spaces; all rates are positive real numbers.
  • Subtask 3 (50 points): 1≤n≤301\le n\le30, 0≤m≤9000\le m\le900; Each name has no spaces; all rates are positive real numbers.

Examples

Input

2
USD
EUR
2
USD 0.90 EUR
EUR 1.20 USD

Output

Yes

Explanation

One USD becomes 0.90.9 EUR, then 0.9×1.2=1.080.9\times1.2=1.08 USD. Since the product 1.08>11.08>1, profitable arbitrage exists, giving Yes.