1203B.md (1609B)
1 Source: https://codeforces.com/problemset/problem/1203/B 2 3 B. Equal Rectangles 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are given $4n$ sticks, the length of the $i$-th stick is $a_i$. 22 23 You have to create $n$ rectangles, each rectangle will consist of exactly $4$ sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length. 24 25 You want to all rectangles to have equal area. The area of the rectangle with sides $a$ and $b$ is $a \cdot b$. 26 27 Your task is to say if it is possible to create exactly $n$ rectangles of equal area or not. 28 29 You have to answer $q$ independent queries. 30 31 Input 32 33 The first line of the input contains one integer $q$ ($1 \le q \le 500$) — the number of queries. Then $q$ queries follow. 34 35 The first line of the query contains one integer $n$ ($1 \le n \le 100$) — the number of rectangles. 36 37 The second line of the query contains $4n$ integers $a_1, a_2, \dots, a_{4n}$ ($1 \le a_i \le 10^4$), where $a_i$ is the length of the $i$-th stick. 38 39 Output 40 41 For each query print the answer to it. If it is impossible to create exactly $n$ rectangles of equal area using given sticks, print "NO". Otherwise print "YES". 42 43 Example 44 45 Input 46 47 ``` 48 5 49 1 50 1 1 10 10 51 2 52 10 5 2 10 1 1 2 5 53 2 54 10 5 1 10 5 1 1 1 55 2 56 1 1 1 1 1 1 1 1 57 1 58 10000 10000 10000 10000 59 ``` 60 61 Output 62 63 ``` 64 YES 65 YES 66 NO 67 YES 68 YES 69 ```