Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- void cvp(vector <pii> a){
- for (auto p: a){
- cout<<p.first<<' '<<p.second<<"\n";
- }
- cout<<"\n";
- }
- bool sh=0;
- int n;
- vector <int> a;
- void slv(){
- sort(a.begin(), a.end());
- reverse(a.begin(), a.end());
- //утв 0 - все уже равны
- if (a[0] == a[n-1]){
- cout<<"YES\n";
- return;
- }
- bool r05=0, roth=0;
- for (int i: a){
- if (i%10 == 0 || i % 10 == 5){
- r05=1;
- }
- else{
- roth=1;
- }
- if (r05 && roth){
- cout<<"NO\n";
- return;
- }
- }
- if (r05){
- if (a[n-1] + a[n-1]%10 == a[0]){
- cout<<"YES\n";
- return;
- }
- else{
- cout<<"NO\n";
- return;
- }
- }
- //остальное
- int r = a[0] % 10;
- if (r == 3 || r == 7 || r == 9){
- cout<<"NO\n";
- return;
- }
- for (int i=0;i < n;++i){
- while (a[i] % 10 != 2){
- a[i] += a[i] % 10;
- }
- }
- sort(a.begin(), a.end());
- reverse(a.begin(), a.end());
- bool can=1;
- for (int i = 0; i < n;++i){
- int d = a[0] - a[i];
- if (d%20 != 0){
- cout<<"NO\n";
- return;
- }
- }
- cout<<"YES\n";
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int t;
- if (!sh) cin>>t;
- for (int go=0;go<t;++go){
- cin>>n;
- a.resize(n);
- for (int &i: a) cin>>i;
- slv();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement