exec_outcome stringclasses 1 value | code_uid stringlengths 32 32 | file_name stringclasses 111 values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18 values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1 value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27 values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k ⌀ | lang stringclasses 5 values | prob_desc_input_from stringclasses 3 values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k ⌀ | difficulty int64 -1 3.5k ⌀ | prob_desc_output_spec stringlengths 17 1.47k ⌀ | prob_desc_output_to stringclasses 3 values | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 5d912aabea5813b8b6e2218f79494194 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Solution {
static PrintWriter pw;
static FastScanner s;
public static void main(String[] args) throws Exception {
pw=new PrintWriter(System.out);
s=new FastScanner(System.in);
int t=s.nextInt();
while(t-->0) {
int n=s.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++) {
a[i]=s.nextInt();
}
boolean flag=true;
for(int i=1;i<n;i++) {
if(a[i]%a[0]!=0) {
flag=false;
break;
}
}
if(flag)
pw.println("YES");
else
pw.println("NO");
}
pw.flush();
}
}
class FastScanner{
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public FastScanner(String s) throws Exception {
br = new BufferedReader(new FileReader(new File(s)));
}
public String next() throws Exception {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 8 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 07e93ed846a8a07bc00c5a95138cc563 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | //package codeforcesProject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class DifferenceOperations {
private int count;
ArrayList<Element> elements = new ArrayList<>();
public static void main(String[] args) {
DifferenceOperations differenceOperations = new DifferenceOperations();
differenceOperations.inputData();
differenceOperations.callingEachContainer();
}
private void inputData() {
Scanner in = new Scanner(System.in);
String firstLine = in.nextLine();
count = Integer.parseInt(firstLine);
for (int i = 0; i < count; i++) {
String st1 = in.nextLine();
String st2 = in.nextLine();
elements.add(Element.createElement(st1, st2));
}
}
private void callingEachContainer() {
for (int i = 0; i < count; i++) {
logicsForAny(elements.get(i));
}
}
private void logicsForAny(Element element) {
String result = "YES";
int firstElement = element.combination[0];
for (int i = 1; i < element.count; i++) {
if (element.combination[i] % firstElement != 0) {
result = "NO";
}
}
System.out.println(result);
}
}
class Element {
Integer count;
int combination[];
public Element(int count, int[] combination) {
this.count = count;
this.combination = combination;
}
public static Element createElement(String st1, String st2) {
int count = Integer.parseInt(st1);
int[] numArr = Arrays.stream(st2.split(" ")).mapToInt(Integer::parseInt).toArray();
return new Element(count, numArr);
}
@Override
public String toString() {
return "Element{" +
"count=" + count +
", combination=" + Arrays.toString(combination) +
"}\n";
}
}
//https://codeforces.com/problemset/problem/1708/A
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 8 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | ed5797200f812eeb7b57d113c48c9f97 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import javax.naming.NamingEnumeration;
import javax.swing.plaf.IconUIResource;
import java.lang.reflect.Array;
import java.util.*;
import java.math.BigInteger;
public class ques {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n= sc.nextInt();
int[] arr = new int[n];
arr[0] = sc.nextInt();
String ans="Yes";
for (int j = 1; j < n; j++) {
arr[j] = sc.nextInt();
if (arr[j]%arr[0] !=0){
ans="No";
}
}
System.out.println(ans);
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 8 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 8e380f720a30087b3f2e02f4eb3c2f46 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
public class Solution {
public static void main(String[] args)
{
Scanner inMain = new Scanner(System.in);
int t = inMain.nextInt();
while (t > 0) {
differenceOperation(inMain);
t--;
}
}
public static void differenceOperation(Scanner input) {
int n = input.nextInt();
int start = input.nextInt();
int next;
String result = "YES";
for (int i=0; i < n-1; i++) {
next = input.nextInt();
if (!(next % start == 0)) {
result = "NO";
}
}
System.out.println(result);
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | fa82e23650bf0f5e5b78a576d1e6e1f4 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | // Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.lang.*;
import java.util.stream.*;
import java.util.stream.Collectors;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static int calcdiv2(int n) {
int counter = 0;
while( ( 1 & n) != 1) {
n = n>>1;
counter++;
}
return counter;
}
public static int highestPowerOfTwo(int n) {
if((n & (n-1)) == 0) return n;
return n & (n-1);
}
public static boolean isPowerOfTwo(int n) {
return (n & (n-1)) == 0;
}
public static int valueOfRightMostSetBit(int n) {
return (n & (-n));
}
// public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm)
// {
// HashMap<Integer, Integer> temp
// = hm.entrySet()
// .stream()
// .sorted((i1, i2)
// -> i1.getValue().compareTo(
// i2.getValue()))
// .collect(Collectors.toMap(
// Map.Entry::getKey,
// Map.Entry::getValue,
// (e1, e2) -> e1, LinkedHashMap::new));
// return temp;
// }
// static int[] sortint(int a[]) {
// ArrayList<Integer> al = new ArrayList<>();
// for (int i : a) {
// al.add(i);
// }
// Collections.sort(al);
// for (int i = 0; i < a.length; i++) {
// a[i] = al.get(i);
// }
// return a;
// }
// static long[] sortlong(long a[]) {
// ArrayList<Long> al = new ArrayList<>();
// for (long i : a) {
// al.add(i);
// }
// Collections.sort(al);
// for (int i = 0; i < al.size(); i++) {
// a[i] = al.get(i);
// }
// return a;
// }
// static ArrayList<Integer> primesTilN(int n) {
// boolean p[] = new boolean[n + 1];
// ArrayList<Integer> al = new ArrayList<>();
// Arrays.fill(p, true);
// int i = 0;
// for (i = 2; i * i <= n; i++) {
// if (p[i] == true) {
// al.add(i);
// for (int j = i * i; j <= n; j += i) {
// p[j] = false;
// }
// }
// }
// for (i = i; i <= n; i++) {
// if (p[i] == true) {
// al.add(i);
// }
// }
// return al;
// }
// static int gcd(int a, int b) {
// if (a == 0) {
// return b;
// }
// return gcd(b % a, a);
// }
// static long gcd(long a, long b) {
// if (a == 0) {
// return b;
// }
// return gcd(b % a, a);
// }
// static long pow(long x, long y) {
// long result = 1;
// while (y > 0) {
// if (y % 2 == 0) {
// x = x * x;
// y = y / 2;
// } else {
// result = result * x;
// y = y - 1;
// }
// }
// return result;
// }
// static boolean[] esieve(int n) {
// boolean p[] = new boolean[n + 1];
// Arrays.fill(p, true);
// for (int i = 2; i * i <= n; i++) {
// if (p[i] == true) {
// for (int j = i * i; j <= n; j += i) {
// p[j] = false;
// }
// }
// }
// return p;
// }
// static int[] readarr(int n) {
// int arr[] = new int[n];
// for (int i = 0; i < n; i++) {
// arr[i] = x.nextInt();
// }
// return arr;
// }
// static HashMap<Integer, Integer> mapCounter(int arr[]) {
// for(int i : arr) {
// if(map.containsKey(i)) map.put(arr[i], map.get(arr[i])+1);
// else map.put(arr[i], 1);
// }
// }
// static HashMap<Integer, Integer> mapCounter(int arr[]) {
// for(int i : arr) {
// if(map.containsKey(i)) map.put(arr[i], map.get(arr[i])+1);
// else map.put(arr[i], 1);
// }
// }
public static void main(String[] args)
{
FastReader sc = new FastReader();
int testcases = sc.nextInt();
int count = 0;
while (count < testcases) {
int n = sc.nextInt();
long arr[] = new long[n];
for(int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
if(arr[0] == 1) {
System.out.println("YES");
}
else {
boolean is = true;
for(int i = 1; i < n; i++) {
if((arr[i] % arr[i-1] != 0 && arr[i] % arr[0] != 0) && arr[i-1] != 0) {
is = false;
break;
}
}
if(is) System.out.println("YES");
else System.out.println("NO");
}
count++;
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | ef4153f861ce32214fde5b3b59d2f76e | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Substitute {
//Global Declarations
final static Random random = new Random();
final static FastReader in = new FastReader();
final static PrintWriter out = new PrintWriter(System.out);
public static String solve(int a[]) {
//Long range is -10^18 to 10^18 and is 64 bit (8 bytes)
//Integer range is ~~ -2 * 10^9(-2^31) to 2 * 10^9(2^31 - 1) and is 32 bit (4 bytes)
//out.println(Arrays.toString(a));
int i,n = a.length,temp=a[0];
if(a[0] == 1)
return "YES";
for(i=1;i<n;++i){
if(a[i]%temp == 0){
continue;
}
else return "NO";
}
return "YES";
}
public static int solve2(int l, int r, int pre[]){
return (l ==0) ? pre[r] : pre[r] - pre[l-1];
}
public static void reverseLong(long a[]) {
int i,n=a.length,j=n-1;
long temp;
for(i=0;i<n/2;++i){
temp = a[i];
a[i] = a[j];
a[j] = temp;
--j;
}
}
public static void reverseInt(int a[]) {
int i,n=a.length,j=n-1,temp;
for(i=0;i<n/2;++i){
temp = a[i];
a[i] = a[j];
a[j] = temp;
--j;
}
}
public static void ruffleLong(long a[]) {
//shuffle, then sort
int i,j,n=a.length;
long temp;
for (i=0; i<n; i++) {
j = random.nextInt(n);
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
Arrays.sort(a);
}
public static void ruffleInt(int a[]) {
//shuffle, then sort
int i,j,n=a.length,temp;
for (i=0; i<n; i++) {
j = random.nextInt(n);
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
Arrays.sort(a);
}
public static void main(String ... args) throws IOException {
// << --> multiply
// >> --> divide
//variable_name <<= 1 --> (variable)multiply by 2
//variable_name >>= 1 --> (variable)divide by 2
//2<<3 --> (multiply)2 * 2^3 --> 16;
//6>>1 --> (divide)6 / 2^1 --> 3;
//out.println(solve(1,20000));
//out.println(1/solve(0,Math.abs(-2)));
//out.println(solve(5,3));
//48782
//out.println(solve());
/*
int n = in.nextInt(),q = in.nextInt(),i,l=n-1;
//StringBuilder sb = new StringBuilder(in.next());
Pair pairs[] = new Pair[n];
String s = in.next();
for(i=0;i<n;++i)
pairs[i] = new Pair(i,s.charAt(i));
while(q-->0){
int t = in.nextInt();
int x = in.nextInt();
i=0;
int val = x-1,temp = l,temp2 = (l+1)%n;
if(temp2 >= n)
temp2 = 0;
if(t == 1){
while(i++ < x){
pairs[temp] = new Pair(val, pairs[temp].getChar());
--temp;
--val;
if(temp == -1)
temp = n-1;
}
i=0;
while(i++ < n-x){
int l2 = (pairs[temp2].getIndex() + x)%n;
pairs[temp2] = new Pair(l2, pairs[temp2].getChar());
if(i == n-x){
l = l2;
//out.println(l);
}
++temp2;
if(temp2 == n)
temp2 = 0;
}
}
else{
//out.println(pairs[x-1].getChar());
for(i=0;i<n;++i){
if(pairs[i].getIndex() == x-1){
out.println(pairs[i].getChar());
break;
}
}
}
for(i=0;i<n;++i){
out.println(pairs[i].getIndex() + " " + pairs[i].getChar());
}
}*/
int tt = in.nextInt();
while(tt-->0){
int n = in.nextInt();
int i;
LinkedHashSet<Integer> st = new LinkedHashSet<>();
for(i=0;i<n;++i){
st.add(in.nextInt());
}
if(st.size() == 1)
out.println("YES");
else{
i=0;
int a[] = new int[st.size()];
for(Integer val: st){
a[i++] = val;
}
out.println(solve(a));
}
}
out.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
class Pair{
private int in;
private char c;
public Pair(int in, char c){
this.in = in;
this.c = c;
}
public int getIndex(){
return this.in;
}
public char getChar(){
return this.c;
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | b36f660ee9b46a11195e161ebf3107af | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Substitute {
//Global Declarations
final static Random random = new Random();
final static FastReader in = new FastReader();
final static PrintWriter out = new PrintWriter(System.out);
public static String solve(int a[]) {
//Long range is -10^18 to 10^18 and is 64 bit (8 bytes)
//Integer range is ~~ -2 * 10^9(-2^31) to 2 * 10^9(2^31 - 1) and is 32 bit (4 bytes)
//out.println(Arrays.toString(a));
int i,n = a.length,temp=a[0];
if(a[0] == 1)
return "YES";
for(i=1;i<n;++i){
if(a[i]%temp == 0){
continue;
}
else return "NO";
}
return "YES";
}
public static int solve2(int l, int r, int pre[]){
return (l ==0) ? pre[r] : pre[r] - pre[l-1];
}
public static void reverseLong(long a[]) {
int i,n=a.length,j=n-1;
long temp;
for(i=0;i<n/2;++i){
temp = a[i];
a[i] = a[j];
a[j] = temp;
--j;
}
}
public static void reverseInt(int a[]) {
int i,n=a.length,j=n-1,temp;
for(i=0;i<n/2;++i){
temp = a[i];
a[i] = a[j];
a[j] = temp;
--j;
}
}
public static void ruffleLong(long a[]) {
//shuffle, then sort
int i,j,n=a.length;
long temp;
for (i=0; i<n; i++) {
j = random.nextInt(n);
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
Arrays.sort(a);
}
public static void ruffleInt(int a[]) {
//shuffle, then sort
int i,j,n=a.length,temp;
for (i=0; i<n; i++) {
j = random.nextInt(n);
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
Arrays.sort(a);
}
public static void main(String ... args) throws IOException {
// << --> multiply
// >> --> divide
//variable_name <<= 1 --> (variable)multiply by 2
//variable_name >>= 1 --> (variable)divide by 2
//2<<3 --> (multiply)2 * 2^3 --> 16;
//6>>1 --> (divide)6 / 2^1 --> 3;
//out.println(solve(1,20000));
//out.println(1/solve(0,Math.abs(-2)));
//out.println(solve(5,3));
//48782
//out.println(solve());
/*
int n = in.nextInt(),q = in.nextInt(),i,l=n-1;
//StringBuilder sb = new StringBuilder(in.next());
Pair pairs[] = new Pair[n];
String s = in.next();
for(i=0;i<n;++i)
pairs[i] = new Pair(i,s.charAt(i));
while(q-->0){
int t = in.nextInt();
int x = in.nextInt();
i=0;
int val = x-1,temp = l,temp2 = (l+1)%n;
if(temp2 >= n)
temp2 = 0;
if(t == 1){
while(i++ < x){
pairs[temp] = new Pair(val, pairs[temp].getChar());
--temp;
--val;
if(temp == -1)
temp = n-1;
}
i=0;
while(i++ < n-x){
int l2 = (pairs[temp2].getIndex() + x)%n;
pairs[temp2] = new Pair(l2, pairs[temp2].getChar());
if(i == n-x){
l = l2;
//out.println(l);
}
++temp2;
if(temp2 == n)
temp2 = 0;
}
}
else{
//out.println(pairs[x-1].getChar());
for(i=0;i<n;++i){
if(pairs[i].getIndex() == x-1){
out.println(pairs[i].getChar());
break;
}
}
}
for(i=0;i<n;++i){
out.println(pairs[i].getIndex() + " " + pairs[i].getChar());
}
}*/
int tt = in.nextInt();
while(tt-->0){
int n = in.nextInt();
int i;
LinkedHashSet<Integer> st = new LinkedHashSet<>();
for(i=0;i<n;++i){
st.add(in.nextInt());
}
if(st.size() == 1)
out.println("YES");
else{
i=0;
int a[] = new int[st.size()];
for(Integer val: st){
a[i++] = Integer.valueOf(val);
}
out.println(solve(a));
}
}
out.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
class Pair{
private int in;
private char c;
public Pair(int in, char c){
this.in = in;
this.c = c;
}
public int getIndex(){
return this.in;
}
public char getChar(){
return this.c;
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | c416ccc102011876c8bde7739e4cb0b4 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
import java.lang.Math;
public class CF1607{
static Scanner scan;
public static void main(String args[]){
scan = new Scanner(System.in);
int testCases = scan.nextInt();
while(testCases>0){
int arrayLength=scan.nextInt();
if(isPossible(arrayLength)){
System.out.println("YES");
}else{
System.out.println("NO");
}
testCases--;
}
}
public static boolean isPossible(int arrayLength){
int firstNumber= scan.nextInt();
for(int i=1; i<arrayLength; i++){
int num=scan.nextInt();
if(num%firstNumber!=0){
scan.nextLine();
return false;
}
}
return true;
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | b16589ce456a8753b96c87cd31a71cfd | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n=sc.nextInt();
int[] a=new int[n];
for (int j = 0; j < n; j++) {
a[j]=sc.nextInt();
}
boolean flag=true;
for (int j = 1; j < n; j++) {
if(a[j]%a[0]!=0){
flag=false;
break;
}
}
if(flag){
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | ee1f1d384dae5e69f797e118152f5ec1 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int k=sc.nextInt();
long arr[]=new long[k];
boolean a=true;
for(int i=0;i<k;i++){
arr[i]=sc.nextInt();
}
for(int i=1;i<k;i++){
if(arr[i]%arr[0]!=0){
a=false;
break;
}
}
if(a==true){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 0a0bf3bb8451ac213d7c3b92b3e7d60c | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
//DECD
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
for (int i = 0; i < t; i++) {
int n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
long[] arr = new long[n];
for (int j = 0; j < n; j++) {
arr[j]=Long.parseLong(st.nextToken());
}
long result=findGCD(arr);
boolean invalid=false;
if(!((arr[1]-result)%arr[0]==0)){
invalid=true;
}
if(arr[1]%arr[0]!=0){
invalid=true;
}
if(!invalid)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
//7 8 2 4 4 3 5 3
//7 1 2 4 4 3 5 3
//7 1 1 1 1 1 1 1
// 5 10 15
// 4 10 36 42
// 2 8 36 42
//result + (x)*a[0]=a[1]
//(a[1]-result)%a[0]==0
//2 4 12 30
//2 2 12 30
//2 2 2 2
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
// Function to find gcd of array of
// numbers
static long findGCD(long arr[])
{
long result = arr[0];
for (long element: arr){
result = gcd(result, element);
if(result == 1)
{
return 1;
}
}
return result;
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | b5c1c4530386c79074e1d37ccc391185 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
public class A {
public static void main(String[] args) throws java.lang.Exception {
Reader scan = new Reader();
int tc = scan.nextInt();
for (int i = 0; i < tc; i++) {
int n = scan.nextInt();
ArrayList <Long> arr = new ArrayList <Long>();
for (int j = 0; j < n; j++){
long l = scan.nextLong();
arr.add(l);
}
System.out.println(solve(arr));
}
}
public static String solve(ArrayList <Long> arr) {
long first = arr.get(0);
for (int i = 0; i < arr.size(); i++){
if (arr.get(i) % first != 0)
return "NO";
}
return "YES";
}
public static void printarr(ArrayList<Long> arr) {
for (int i = 0; i < arr.size(); i++) {
System.out.print(arr.get(i) + " ");
}
System.out.println();
}
static class Reader {
final private int BUFFER_SIZE = 1 << 64;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[1000000]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
} else {
continue;
}
}
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 7fbb5edb23c8fcf04066591e4ecfc3cb | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.*;
import java.util.*;
public class C2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int t = Integer.parseInt(br.readLine());
while (t > 0) {
int n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
long[] arr = new long[n];
boolean yes = true;
for (int i = 0; i < n; i++)
{
arr[i] = Long.parseLong(st.nextToken());
if (i != 0)
if (arr[i] % arr[0] != 0)
{
yes = false;
break;
}
}
if (yes)
pw.println("YES");
else pw.println("NO");
--t;
}
pw.close();
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 334714537fcdb42b2e7e871617b1cc1a | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class notAcheapString {
public static void main(String[] args)throws Exception {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t-->0)
{
boolean flag=true;
int n=Integer.parseInt(br.readLine());
String [] input=br.readLine().split(" ");
int [] arr=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=Integer.parseInt(input[i]);
}
for(int i=1;i<n;i++)
{
if(arr[i]%arr[0]!=0 )
flag=false;
}
if(flag)
System.out.println("YES");
else
{
System.out.println("NO");
}
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | ef6cb93bbe97bee4cb72cb87cba8829e | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.*;
public class weird_algrithm {
static BufferedWriter output = new BufferedWriter(
new OutputStreamWriter(System.out));
static BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
static int mod = 1000000007;
static String toReturn = "";
static int steps = Integer.MAX_VALUE;
static int maxlen = 1000005;
/*MATHEMATICS FUNCTIONS START HERE
MATHS
MATHS
MATHS
MATHS*/
static long gcd(long a, long b) {
if(b == 0) return a;
else return gcd(b, a % b);
}
static long powerMod(long x, long y, int mod) {
if(y == 0) return 1;
long temp = powerMod(x, y / 2, mod);
temp = ((temp % mod) * (temp % mod)) % mod;
if(y % 2 == 0) return temp;
else return ((x % mod) * (temp % mod)) % mod;
}
static long modInverse(long n, int p) {
return powerMod(n, p - 2, p);
}
static long nCr(int n, int r, int mod, long [] fact, long [] ifact) {
return ((fact[n] % mod) * ((ifact[r] * ifact[n - r]) % mod)) % mod;
}
static boolean isPrime(long a) {
if(a == 1) return false;
else if(a == 2 || a == 3 || a== 5) return true;
else if(a % 2 == 0 || a % 3 == 0) return false;
for(int i = 5; i * i <= a; i = i + 6) {
if(a % i == 0 || a % (i + 2) == 0) return false;
}
return true;
}
static int [] seive(int a) {
int [] toReturn = new int [a + 1];
for(int i = 0; i < a; i++) toReturn[i] = 1;
toReturn[0] = 0;
toReturn[1] = 0;
toReturn[2] = 1;
for(int i = 2; i * i <= a; i++) {
if(toReturn[i] == 0) continue;
for(int j = 2 * i; j <= a; j += i) toReturn[j] = 0;
}
return toReturn;
}
static long [] fact(int a) {
long [] arr = new long[a + 1];
arr[0] = 1;
for(int i = 1; i < a + 1; i++) {
arr[i] = (arr[i - 1] * i) % mod;
}
return arr;
}
/*MATHS
MATHS
MATHS
MATHS
MATHEMATICS FUNCTIONS END HERE */
/*SWAP FUNCTION START HERE
SWAP
SWAP
SWAP
SWAP
*/
static void swap(int i, int j, long[] arr) {
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static void swap(int i, int j, int[] arr) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static void swap(int i, int j, String [] arr) {
String temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static void swap(int i, int j, char [] arr) {
char temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
/*SWAP
SWAP
SWAP
SWAP
SWAP FUNCTION END HERE*/
/*BINARY SEARCH METHODS START HERE
* BINARY SEARCH
* BINARY SEARCH
* BINARY SEARCH
* BINARY SEARCH
*/
static boolean BinaryCheck(long test, long [] arr, long health) {
for(int i = 0; i <= arr.length - 1; i++) {
if(i == arr.length - 1) health -= test;
else if(arr[i + 1] - arr[i] > test) {
health = health - test;
}else {
health = health - (arr[i + 1] - arr[i]);
}
if(health <= 0) return true;
}
return false;
}
static long binarySearchModified(long start1, long n, ArrayList<Long> arr, int a, long r) {
long start = start1, end = n, ans = -1;
while(start < end) {
long mid = (start + end) / 2;
//System.out.println(mid);
if(arr.get((int)mid) + arr.get(a) <= r && mid != start1) {
ans = mid;
start = mid + 1;
}else{
end = mid;
}
}
//System.out.println();
return ans;
}
static int binarySearch(int start, int end, long [] arr, long val) {
while(start < end) {
int mid = (int)Math.ceil((start + end) / 2.0);
//System.out.println(mid);
if(arr[mid] > val) end = mid - 1;
else start = mid;
}
return start;
}
/*BINARY SEARCH
* BINARY SEARCH
* BINARY SEARCH
* BINARY SEARCH
* BINARY SEARCH
BINARY SEARCH METHODS END HERE*/
/*RECURSIVE FUNCTION START HERE
* RECURSIVE
* RECURSIVE
* RECURSIVE
* RECURSIVE
*/
static int recurse(int x, int y, int n, int steps1, Integer [][] dp) {
if(x > n || y > n) return 0;
if(dp[x][y] != null) {
return dp[x][y];
}
else if(x == n || y == n) {
return steps1;
}
return dp[x][y] = Math.max(recurse(x + y, y, n, steps1 + 1, dp), recurse(x, x + y, n, steps1 + 1, dp));
}
/*RECURSIVE
* RECURSIVE
* RECURSIVE
* RECURSIVE
* RECURSIVE
RECURSIVE FUNCTION END HERE*/
/*GRAPH FUNCTIONS START HERE
* GRAPH
* GRAPH
* GRAPH
* GRAPH
* */
static class edge{
int from, to;
long weight;
public edge(int x, int y, long weight2) {
this.from = x;
this.to = y;
this.weight = weight2;
}
}
static class sort implements Comparator<pair>{
@Override
public int compare(pair o1, pair o2) {
// TODO Auto-generated method stub
return (int)o1.a - (int)o2.a;
}
}
static void addEdge(ArrayList<ArrayList<edge>> graph, int from, int to, long weight) {
edge temp = new edge(from, to, weight);
edge temp1 = new edge(to, from, weight);
graph.get(from).add(temp);
//graph.get(to).add(temp1);
}
static int ans = 0;
static int dfs(ArrayList<ArrayList<Integer>> graph, int vertex, boolean [] visited, int [] childs) {
//System.out.println(graph.get(vertex).size());
if(visited[vertex]) return 0;
visited[vertex] = true;
int ans = 0;
for(int i = 0; i < graph.get(vertex).size(); i++) {
int temp = graph.get(vertex).get(i);
if(!visited[temp]) {
ans += dfs(graph, temp, visited, childs) + 1;
}
}
childs[vertex] = ans;
return ans;
}
static void topoSort(ArrayList<ArrayList<Integer>> graph, int vertex, boolean [] visited, ArrayList<Integer> toReturn) {
if(visited[vertex]) return;
visited[vertex] = true;
for(int i = 0; i < graph.get(vertex).size(); i++) {
if(!visited[graph.get(vertex).get(i)]) topoSort(graph, graph.get(vertex).get(i), visited, toReturn);
}
toReturn.add(vertex);
}
static boolean isCyclicDirected(ArrayList<ArrayList<Integer>> graph, int vertex, boolean [] visited, boolean [] reStack) {
if(reStack[vertex]) return true;
if(visited[vertex]) return false;
reStack[vertex] = true;
visited[vertex] = true;
for(int i = 0; i < graph.get(vertex).size(); i++) {
if(isCyclicDirected(graph, graph.get(vertex).get(i), visited, reStack)) return true;
}
reStack[vertex] = false;
return false;
}
static int e = 0;
static long mst(PriorityQueue<edge> pq, int nodes) {
long weight = 0;
while(!pq.isEmpty()) {
edge temp = pq.poll();
int x = parent(parent, temp.to);
int y = parent(parent, temp.from);
if(x != y) {
//System.out.println(temp.weight);
union(x, y, rank, parent);
weight += temp.weight;
e++;
}
}
return weight;
}
static void floyd(long [][] dist) { // to find min distance between two nodes
for(int k = 0; k < dist.length; k++) {
for(int i = 0; i < dist.length; i++) {
for(int j = 0; j < dist.length; j++) {
if(dist[i][j] > dist[i][k] + dist[k][j]) {
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
}
static void dijkstra(ArrayList<ArrayList<edge>> graph, long [] dist, int src) {
for(int i = 0; i < dist.length; i++) dist[i] = Long.MAX_VALUE / 2;
dist[src] = 0;
boolean visited[] = new boolean[dist.length];
PriorityQueue<pair> pq = new PriorityQueue<>(new sort());
pq.add(new pair(src, 0));
while(!pq.isEmpty()) {
pair temp = pq.poll();
int index = (int)temp.a;
for(int i = 0; i < graph.get(index).size(); i++) {
if(dist[graph.get(index).get(i).to] > dist[index] + graph.get(index).get(i).weight) {
dist[graph.get(index).get(i).to] = dist[index] + graph.get(index).get(i).weight;
pq.add(new pair(graph.get(index).get(i).to, graph.get(index).get(i).weight));
}
}
}
}
static int parent1 = -1;
static boolean ford(ArrayList<ArrayList<edge>> graph1, ArrayList<edge> graph, long [] dist, int src, int [] parent) {
for(int i = 0; i < dist.length; i++) dist[i] = Long.MIN_VALUE / 2;
dist[src] = 0;
boolean hasNeg = false;
for(int i = 0; i < dist.length - 1; i++) {
for(int j = 0; j < graph.size(); j++) {
int from = graph.get(j).from;
int to = graph.get(j).to;
long weight = graph.get(j).weight;
if(dist[to] < dist[from] + weight) {
dist[to] = dist[from] + weight;
parent[to] = from;
}
}
}
for(int i = 0; i < graph.size(); i++) {
int from = graph.get(i).from;
int to = graph.get(i).to;
long weight = graph.get(i).weight;
if(dist[to] < dist[from] + weight) {
parent1 = from;
hasNeg = true;
/*
* dfs(graph1, parent1, new boolean[dist.length], dist.length - 1);
* //System.out.println(ans); dfs(graph1, 0, new boolean[dist.length], parent1);
*/
//System.out.println(ans);
if(ans == 2) break;
else ans = 0;
}
}
return hasNeg;
}
/*GRAPH FUNCTIONS END HERE
* GRAPH
* GRAPH
* GRAPH
* GRAPH
*/
/*disjoint Set START HERE
* disjoint Set
* disjoint Set
* disjoint Set
* disjoint Set
*/
static int [] rank;
static int [] parent;
static int parent(int [] parent, int x) {
if(parent[x] == x) return x;
else return parent[x] = parent(parent, parent[x]);
}
static boolean union(int x, int y, int [] rank, int [] parent) {
if(parent(parent, x) == parent(parent, y)) {
return true;
}
if(rank[x] > rank[y]) {
swap(x, y, rank);
}
rank[x] += rank[y];
parent[y] = x;
return false;
}
/*disjoint Set END HERE
* disjoint Set
* disjoint Set
* disjoint Set
* disjoint Set
*/
/*INPUT START HERE
* INPUT
* INPUT
* INPUT
* INPUT
* INPUT
*/
static int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(sc.readLine());
}
static long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(sc.readLine());
}
static long [] inputLongArr() throws NumberFormatException, IOException{
String [] s = sc.readLine().split(" ");
long [] toReturn = new long[s.length];
for(int i = 0; i < s.length; i++) {
toReturn[i] = Long.parseLong(s[i]);
}
return toReturn;
}
static int max = 0;
static int [] inputIntArr() throws NumberFormatException, IOException{
String [] s = sc.readLine().split(" ");
//System.out.println(s.length);
int [] toReturn = new int[s.length];
for(int i = 0; i < s.length; i++) {
toReturn[i] = Integer.parseInt(s[i]);
}
return toReturn;
}
static void print(int n) throws IOException {
output.write(Integer.toString(n));
output.flush();
}
static void print(String s) throws IOException {
output.write(s);
output.flush();
}
static void print(long n) throws IOException {
output.write(Long.toString(n) + "\n");
output.flush();
}
static void print(char n) throws IOException {
output.write(n);
output.flush();
}
/*INPUT
* INPUT
* INPUT
* INPUT
* INPUT
* INPUT END HERE
*/
static long [] preCompute(int level) {
long [] toReturn = new long[level];
toReturn[0] = 1;
toReturn[1] = 16;
for(int i = 2; i < level; i++) {
toReturn[i] = ((toReturn[i - 1] % mod) * (toReturn[i - 1] % mod)) % mod;
}
return toReturn;
}
static class pair{
long a;
long b;
long d;
public pair(long in, long y) {
this.a = in;
this.b = y;
this.d = 0;
}
}
static long smallestFactor(long a) {
for(long i = 2; i * i <= a; i++) {
if(a % i == 0) {
return i;
}
}
return a;
}
static int recurseRow(int [][] mat, int i, int j, int prev, int ans) {
if(j >= mat[0].length) return ans;
if(mat[i][j] == prev) {
return recurseRow(mat, i, j + 1, prev, ans + 1);
}
else return ans;
}
static int recurseCol(int [][] mat, int i, int j, int prev, int ans) {
if(i >= mat.length) return ans;
if(mat[i][j] == prev) {
return recurseCol(mat, i + 1, j, prev, ans + 1);
}
else return ans;
}
static int diff(char [] a, char [] b) {
int sum = 0;
for(int i = 0; i < a.length; i++) {
sum += Math.abs((int)a[i] - (int)b[i]);
}
return sum;
}
static int [] nextGreaterBack(char [] s) {
Stack<Integer> stack = new Stack<>();
int [] toReturn = new int[s.length];
for(int i = 0; i < s.length; i++) {
if(!stack.isEmpty() && s[stack.peek()] >= s[i]) {
stack.pop();
}
if(stack.isEmpty()) {
stack.push(i);
toReturn[i] = -1;
}else {
toReturn[i] = stack.peek();
stack.push(i);
}
}
return toReturn;
}
static int [] nextGreaterFront(char [] s) {
Stack<Integer> stack = new Stack<>();
int [] toReturn = new int[s.length];
for(int i = s.length - 1; i >= 0; i--) {
if(!stack.isEmpty() && s[stack.peek()] >= s[i]) {
stack.pop();
}
if(stack.isEmpty()) {
stack.push(i);
toReturn[i] = -1;
}else {
toReturn[i] = stack.peek();
stack.push(i);
}
}
return toReturn;
}
static int lps(String s) {
int max = 0;
int [] lps = new int[s.length()];
lps[0] = 0;
int j = 0;
for(int i = 1; i < lps.length; i++) {
j = lps[i - 1];
while(j > 0 && s.charAt(i) != s.charAt(j)) j = lps[j - 1];
if(s.charAt(i) == s.charAt(j)) {
lps[i] = j + 1;
max = Math.max(max, lps[i]);
}
}
return max;
}
static int [][] vectors = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
static String dir = "DRUL";
static boolean check(int i, int j, boolean [][] visited) {
if(i >= visited.length || j >= visited[0].length) return false;
if(i < 0 || j < 0) return false;
return true;
}
static int count = 0;
static void recurse(boolean [][] visited, int i, int j, String p, int z, Integer [][][] dp) throws IOException {
if(p.length() == z) {
//System.out.println(i + " " + j);
if(i == visited.length - 1 && j == 0) {
count++;
return;
}else return;
}
if(i == visited.length - 1 && j == 0) {
return;
}
if(visited[i][j]) return;
visited[i][j] = true;
for(int k = 0; k < vectors.length; k++) {
int x = i + vectors[k][0], y = j + vectors[k][1];
char toAdd = dir.charAt(k);
if(p.charAt(z) == '?' || p.charAt(z) == toAdd) {
if(check(x, y, visited) && !visited[x][y]) {
//recurse(visited, x, y, p, z + 1);
}
}
}
visited[i][j] = false;
}
static boolean check1(int k, long [] arr, long minSum) {
int subArrays = 0;
long sum = 0;
for(int i = 0; i < arr.length; i++) {
if(sum + arr[i] > minSum) {
sum = arr[i];
subArrays++;
if(arr[i] > minSum) return false;
}else sum += arr[i];
}
if(subArrays < k) return true;
return false;
}
static long bin(long start, long end, long [] arr, int k) {
long ans = 0;
while(start < end) {
long mid = (start + end) / 2;
//System.out.println(mid);
if(check1(k, arr, mid)) {
ans = mid;
end = mid;
}else {
start = mid + 1;
}
}
return ans;
}
static void selectionSort(long arr[], long [] arr1, ArrayList<ArrayList<Integer>> ans)
{
int n = arr.length;
for (int i = 0; i < n-1; i++)
{
int min_idx = i;
for (int j = i+1; j < n; j++)
if (arr[j] < arr[min_idx])
min_idx = j;
else if(arr[j] == arr[min_idx]) {
if(arr1[j] < arr1[min_idx]) min_idx = j;
}
if(i == min_idx) {
continue;
}
ArrayList<Integer> p = new ArrayList<Integer>();
p.add(min_idx + 1);
p.add(i + 1);
ans.add(new ArrayList<Integer>(p));
swap(i, min_idx, arr);
swap(i, min_idx, arr1);
}
}
static void solve1() throws IOException {
/*
* for(int i = 0; i < dp.length; i++) { for(int j = 0; j < dp[0].length; j++) {
* System.out.print(dp[i][j] + " "); } System.out.println(); }
*/
//print(recurse1(n[0], n[1], new Long[Math.max(n[0], n[1]) + 1][Math.max(n[0], n[1]) + 1]));
}
static int saved = Integer.MAX_VALUE;
static String ans1 = "";
public static boolean isValid(int x, int y, String [] mat) {
if(x >= mat.length || x < 0) return false;
if(y >= mat[0].length() || y < 0) return false;
return true;
}
static boolean recurse1(int i, int j, int [][] arr, int sum, Boolean [][][] dp) {
if(i == arr.length - 1 && j == arr[0].length - 1) {
if(sum + arr[i][j] == 0) return true;
return false;
}
if(i == arr.length) return false;
else if(j == arr[0].length) return false;
if(sum < 0 && dp[i][j][arr.length + arr[0].length + 1 + sum] != null) return dp[i][j][arr.length + arr[0].length + 1 + sum];
if(sum > 0 && dp[i][j][sum] != null) return dp[i][j][sum];
if(sum < 0) dp[i][j][arr.length + arr[0].length + 1 + sum] = recurse1(i + 1, j, arr, sum + arr[i][j], dp) || recurse1(i, j + 1, arr, sum + arr[i][j], dp);
return dp[i][j][sum] = recurse1(i + 1, j, arr, sum + arr[i][j], dp) || recurse1(i, j + 1, arr, sum + arr[i][j], dp);
}
static void bfs(String [] grid, int [][] distance, Queue<pair> q) {
boolean [][] visited = new boolean[grid.length][grid[0].length()];
while(!q.isEmpty()) {
pair head = q.poll();
for(int i = 0; i < vectors.length; i++) {
int x = (int)head.a + vectors[i][0], y = (int)head.b + vectors[i][1];
if(isValid(x, y, grid) && grid[x].charAt(y) != '#' && distance[x][y] == -1) {
distance[x][y] = (int)head.d + 1;
pair toAdd = new pair(x, y);
toAdd.d = distance[x][y];
q.add(toAdd);
}
}
}
}
static pair bfs1(String [] grid, int [][] distance, Queue<pair> q, char [][] path) {
boolean [][] visited = new boolean[grid.length][grid[0].length()];
while(!q.isEmpty()) {
pair head = q.poll();
if(head.a == grid.length - 1 || head.b == grid[0].length() - 1 || head.a == 0 || head.b == 0) {
return head;
}
for(int i = 0; i < vectors.length; i++) {
int x = (int)head.a + vectors[i][0], y = (int)head.b + vectors[i][1];
int dist = (int)head.d + 1;
if(isValid(x, y, grid) && grid[x].charAt(y) != '#' && !visited[x][y] && (dist < distance[x][y] || distance[x][y] == -1)) {
path[x][y] = dir.charAt(i);
visited[x][y] = true;
pair toAdd = new pair(x, y);
toAdd.d = dist;
q.add(toAdd);
}
}
}
return null;
}
static int search(ArrayList<Integer> arr, int target) {
int start = 0; int end = arr.size() - 1;
while(start <= end) {
int mid = (start + end) / 2;
if(arr.get(mid) < target) start = mid + 1;
else if(arr.get(mid) > target) end = mid - 1;
else if(arr.get(mid) == target) {
if(mid + 1 < arr.size() && arr.get(mid + 1) == target) {
start = mid + 1;
}else return start;
}
}
return start;
}
static int end = -1;
static boolean dfs1(int src, ArrayList<ArrayList<Integer>> graph, boolean [] visited, int k, HashMap<Integer, Integer> map) {
visited[src] = true;
if(k == 0) return true;
//System.out.println(src + " " + k);
for(int x : graph.get(src)) {
if(!visited[x]) {
if(map.containsKey(x)) {
end = x;
if(dfs1(x, graph, visited, k - 1, map)) return true;
}else {
if(dfs1(x, graph, visited, k, map)) return true;
}
}
}
return false;
}
public static void recurse3(ArrayList<Character> arr, int index, String s, int max, ArrayList<String> toReturn) {
if(s.length() == max) {
toReturn.add(s);
return;
}
if(index == arr.size()) return;
recurse3(arr, index + 1, s + arr.get(index), max, toReturn);
recurse3(arr, index + 1, s, max, toReturn);
}
static void solve() throws IOException {
int n = nextInt();
int [] arr = inputIntArr();
if(arr[0] == 1) {
print("YES\n");
return;
}
int count = 0;
int same = 1;
for(int i = 1; i < arr.length; i++) {
if(arr[i] % arr[0] == 0) continue;
else {
print("NO\n");
return;
}
}
print("YES\n");
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
int t = Integer.parseInt(sc.readLine()); for(int i = 0; i < t; i++)
solve();
}
}
class TreeNode {
int val;
TreeNode next;
public TreeNode(int x, TreeNode y) {
this.val = x;
this.next = y;
}
}
/*
1
10
6 10 7 9 11 99 45 20 88 31
*/
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 9e22be138c79b2e7b3ea053a8e26665b | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes |
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import static java.lang.System.out;
import java.util.*;
import java.io.*;
import java.math.*;
public class CF808A {
public static void main(String[] args) {
FastScanner sc=new FastScanner();
int T=sc.nextInt();
StringBuilder sb = new StringBuilder();
for (int tt=0; tt<T; tt++) {
boolean ans = true;
int n = sc.nextInt();
int arr[] = sc.readArray(n);
for(int i=1;i<n;i++) {
if(arr[i]%arr[0]!=0) {
ans = false;
break;
}
}
if(ans) sb.append("YES");
else sb.append("NO");
sb.append('\n');
}
out.print(sb);
out.flush();
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 77379865cee86e56de172a296e83d6ed | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | //package Practise_problems;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class DifferenceOperations {
public static void main(String []args) {
FastScanner fs=new FastScanner();
int t=fs.nextInt();
while(t-->0) {
int n=fs.nextInt();
int []arr=new int[n];
arr=fs.readArray(n);
int gcd=arr[0];
//System.out.println(calc_gcd(3,4));
if(arr[0]==1) {
System.out.println("YES");
continue;
}
for(int i=1;i<n;i++) {
gcd=calc_gcd(gcd,arr[i]);
}
if(gcd==arr[0])
System.out.println("YES");
else System.out.println("NO");
}
}
public static int calc_gcd(int a,int b) {
if(b==0)
return a;
else return calc_gcd(b,a%b);
}
static final Random random=new Random();
static void ruffleSort(int[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 97b882448be98289c08676dcffd169c9 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
//import java.util.Arrays;
//import java.util.Collections;
//import java.util.ArrayList;
public class CodeForces
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.valueOf(br.readLine());
while(t-->0)
{
int n=Integer.valueOf(br.readLine());
StringTokenizer st=new StringTokenizer(br.readLine());
long arr[]=new long[n];
for(int i=0;i<n;i++)
arr[i]=Long.valueOf(st.nextToken());
//System.out.println((arr[1]%arr[0]==0)?"YES":"NO");
boolean flag=true;
for(int i=1;i<n;i++)
{
if(arr[i]%arr[0]!=0)
flag=false;
}
System.out.println(flag?"YES":"NO");
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 04ca38b4319e652bcdf1338da18966d1 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.io.*;
public class practice {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new PrintWriter(System.out)));
StringBuilder sb = new StringBuilder();
int t = Integer.parseInt(br.readLine());
while (t --> 0) {
int n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int arr[] = new int[n];
for (int i = 0; i < n; i++) arr[i] = Integer.parseInt(st.nextToken());
int num = arr[0];
boolean flag = true;
for (int i = 1; i < n && flag; i++) {
if (arr[i] % num != 0) flag = false;
}
sb.append(flag ? "Yes" : "No").append("\n");
}
pw.println(sb.toString().trim());
pw.close();
br.close();
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 7df0c873c55daf87876612df2a0a09b2 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class Main {
static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while (t-- > 0) {
int n = s.nextInt();
int arr[] = new int[n];
int gcd = 0;
for (int i = 0; i < n; i++) {
arr[i]=s.nextInt();
gcd = gcd(gcd, arr[i]);
}
if(gcd==arr[0])
System.out.println("Yes");
else
System.out.println("No");
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | b17d34dba2e2dce5f06874d5cad05ff5 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static void sort(int a[]){ // int -> long
ArrayList<Integer> arr=new ArrayList<>(); // Integer -> Long
for(int i=0;i<a.length;i++)
arr.add(a[i]);
Collections.sort(arr);
for(int i=0;i<a.length;i++)
a[i]=arr.get(i);
}
private static long gcd(long a, long b){
if(b==0)return a;
return gcd(b,a%b);
}
private static long pow(long x,long y){
if(y==0)return 1;
long temp = pow(x, y/2);
if(y%2==1) return x*temp*temp;
else return temp*temp;
}
static int log(long n){
if(n<=1)return 0;
long temp = n;
int res = 0;
while(n>1){
res++;
n/=2;
}
return (1<<res)==temp?res:res+1;
}
static int mod = (int)1e9+7;
static int INF = Integer.MAX_VALUE;
static PrintWriter out;
static FastReader sc ;
public static void main(String[] args) throws IOException {
sc = new FastReader();
out = new PrintWriter(System.out);
// primes();
// ================================ //
int test = sc.nextInt();
while (test-- > 0) {
int n=sc.nextInt();
boolean flag = false;
int k = sc.nextInt();
for(int i=0;i<n-1;i++){
int a = sc.nextInt();
if(a%k!=0){
flag = true;
}
}
out.println( flag?"NO":"YES");
}
out.flush();
}
public static void solver() {
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 93c186dc0f9482d0d7df9698c78f1141 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.io.*;
public class Practice {
static boolean multipleTC = true;
final static int mod = 1000000007;
final static int mod2 = 998244353;
final double E = 2.7182818284590452354;
final double PI = 3.14159265358979323846;
int MAX = 200005;
int N = 40000;
void pre() throws Exception {
// dp = new int[N + 1];
// dp[0] = 1;
// for (int a = 1; a <= N; a++)
// if (reverse(a, 0) == a) {
// for (int n = 0; n + a <= N; n++) {
// dp[n + a] = (dp[n + a] + dp[n]) % mod;
// }
// }
}
int reverse(int a, int b) {
return a == 0 ? b : reverse(a / 10, b * 10 + a % 10);
}
// All the best
void solve(int TC) throws Exception {
int n = ni(), arr[] = readArr(n);
for (int i = 1; i < n; i++) {
if(arr[i]%arr[0]!=0) {
pn("NO");
return;
}
}
pn("YES");
}
double dist(int x1, int y1, int x2, int y2) {
double a = x1 - x2, b = y1 - y2;
return Math.sqrt((a * a) + (b * b));
}
int[] readArr(int n) throws Exception {
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = ni();
}
return arr;
}
void sort(int arr[], int left, int right) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = left; i <= right; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = left; i <= right; i++)
arr[i] = list.get(i - left);
}
void sort(int arr[]) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < arr.length; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = 0; i < arr.length; i++)
arr[i] = list.get(i);
}
public long max(long... arr) {
long max = arr[0];
for (long itr : arr)
max = Math.max(max, itr);
return max;
}
public int max(int... arr) {
int max = arr[0];
for (int itr : arr)
max = Math.max(max, itr);
return max;
}
public long min(long... arr) {
long min = arr[0];
for (long itr : arr)
min = Math.min(min, itr);
return min;
}
public int min(int... arr) {
int min = arr[0];
for (int itr : arr)
min = Math.min(min, itr);
return min;
}
public long sum(long... arr) {
long sum = 0;
for (long itr : arr)
sum += itr;
return sum;
}
public long sum(int... arr) {
long sum = 0;
for (int itr : arr)
sum += itr;
return sum;
}
String bin(long n) {
return Long.toBinaryString(n);
}
String bin(int n) {
return Integer.toBinaryString(n);
}
static int bitCount(int x) {
return x == 0 ? 0 : (1 + bitCount(x & (x - 1)));
}
static void dbg(Object... o) {
System.err.println(Arrays.deepToString(o));
}
int bit(long n) {
return (n == 0) ? 0 : (1 + bit(n & (n - 1)));
}
int abs(int a) {
return (a < 0) ? -a : a;
}
long abs(long a) {
return (a < 0) ? -a : a;
}
void p(Object o) {
out.print(o);
}
void pn(Object o) {
out.println(o);
}
void pni(Object o) {
out.println(o);
out.flush();
}
void pn(int[] arr) {
int n = arr.length;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(arr[i] + " ");
}
pn(sb);
}
void pn(long[] arr) {
int n = arr.length;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(arr[i] + " ");
}
pn(sb);
}
String n() throws Exception {
return in.next();
}
String nln() throws Exception {
return in.nextLine();
}
int ni() throws Exception {
return Integer.parseInt(in.next());
}
long nl() throws Exception {
return Long.parseLong(in.next());
}
double nd() throws Exception {
return Double.parseDouble(in.next());
}
public static void main(String[] args) throws Exception {
new Practice().run();
}
FastReader in;
PrintWriter out;
void run() throws Exception {
in = new FastReader();
out = new PrintWriter(System.out);
int T = (multipleTC) ? ni() : 1;
pre();
for (int t = 1; t <= T; t++)
solve(t);
out.flush();
out.close();
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws Exception {
br = new BufferedReader(new FileReader(s));
}
String next() throws Exception {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new Exception(e.toString());
}
}
return st.nextToken();
}
String nextLine() throws Exception {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
throw new Exception(e.toString());
}
return str;
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 50ceb73325818f93bf6f13ff12c053d1 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.*;
import java.util.*;
import java.lang.*;
public class Main
{
static Scanner sc = new Scanner(System.in);
public static void main(String[] args)
{
int tc = sc.nextInt();
while(tc-->0)
{
int n = sc.nextInt();
int d = sc.nextInt();
boolean isPossible = true;
while(n-->1)
{
int val = sc.nextInt();
if(val % d != 0)
{
isPossible = false;
}
}
if(isPossible)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 94bd3ff9d38dcc52e08f14769d4f8ed6 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.*;
import java.util.*;
import java.lang.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int numC = sc.nextInt();
for (int c = 0; c < numC; c++)
{
int n = sc.nextInt();
int[] arr = new int[n];
boolean win = true;
for (int i = 0; i < n; i++)
{
arr[i] = sc.nextInt();
if (arr[i] % arr[0] != 0)
win = false;
}
System.out.println(win ? "YES" : "NO");
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 2816e404ed6c6e776bf589cd8b7aa1f6 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc= new Scanner(System.in);
int t = sc.nextInt();
po: while(t-->0){
int n = sc.nextInt();
int[] arr = new int[n];
int zeros = 0;
for(int i=0;i<n;i++){
arr[i] = sc.nextInt();
if(arr[i]==0)
zeros++;
}
if(zeros==n){
System.out.println("Yes");
continue po;
}
if(arr[0]==0){
System.out.println("No");
continue po;
}
for(int i=1;i<n;i++){
if(arr[i]%arr[0]!=0){
System.out.println("NO");
continue po;
}
}
System.out.println("Yes");
}
// your code goes here
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 5c011b2157d625e4dd0b9bc34f4869f6 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.stream.IntStream;
public class Codeforces extends PrintWriter {
Codeforces() { super(System.out); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
Codeforces o = new Codeforces(); o.main(); o.flush();
o.close();
}
final int mod = 998244353;
// static int maxRepeat(int arr[], int n)
// {
// Map<Integer,Integer> map = new HashMap<>();
// for(int v: arr){
// map.put(v,map.getOrDefault(v,0)+1);
// }
// int max=0;
// for(Integer val: map.values()){
// max=Math.max(max,val);
// }
// if(max>2)
// return getKey(map,max);
// else
// return -1;
// }
String solve(int n){
boolean flag = true;
int f = sc.nextInt();
for(int i=2;i<=n;i++){
if(sc.nextInt()%f!=0) flag = false;
}
if(flag) return "YES";
return "NO";
}
void main() {
int t = sc.nextInt();
while (t--> 0) {
int n = sc.nextInt();
//Arrays.sort(arr);
println(solve(n));
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 644b403eb9480a56fffd5a27cb372617 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while(t--!=0)
{
int n = in.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;i++)
arr[i]=in.nextInt();
boolean flag = true;
for(int i=1;i<n;i++)
{
if(arr[i]%arr[0]!=0)
{
flag = false;
break;
}
}
if(flag) System.out.println("YES");
else System.out.println("NO");
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | cf1f2d9a6b4fb72114f1f62f59a27b7f | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes |
// 20:18 ; 2'50" ; %%I02V2L4L //
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class A {
static class pair implements Comparable<pair> {
int a;
int b;
pair(int a, int b) {
this.a = a;
this.b = b;
}
public int compareTo(pair o) {
return this.a - o.a;
}
}
static ArrayList<Integer> g[];
static boolean vis[];
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int tt = sc.nextInt();
while (tt-- > 0) {
int n = sc.nextInt();
int a[] = sc.readArray(n);
int d = a[0];
boolean can = true;
for (int i = 1; i < n; i++) {
if (a[i] % d != 0 && a[i] % a[i - 1] != 0) {
can = false;
break;
}
}
System.out.println(can ? "YES" : "NO");
}
}
static void sort(int[] a) {
// ruffle
int n = a.length;
Random r = new Random();
for (int i = 0; i < a.length; i++) {
int oi = r.nextInt(n), temp = a[i];
a[i] = a[oi];
a[oi] = temp;
}
// then sort
Arrays.sort(a);
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String str = "";
String nextLine() {
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long[] readLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
static long gcd(long n, long l) {
if (l == 0)
return n;
return gcd(l, n % l);
}
static void sieveOfEratosthenes(int n, ArrayList<Integer> al) {
boolean prime[] = new boolean[n + 1];
for (int i = 0; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
for (int i = 2; i <= n; i++) {
if (prime[i] == true)
al.get(i);
}
}
static final int mod = 1_000_000_000 + 7;
static final int max_val = 2147483647;
static final int min_val = max_val + 1;
static long fastPow(long base, long exp) {
if (exp == 0)
return 1;
long half = fastPow(base, exp / 2);
if (exp % 2 == 0)
return mul(half, half);
return mul(half, mul(half, base));
}
static long mul(long a, long b) {
return a * b % mod;
}
static int nCr(int n, int r) {
return fact(n) / (fact(r) *
fact(n - r));
}
static int fact(int n) {
int res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
// a -> z == 97 -> 122
// String.format("%.9f", ans) ,--> to get upto 9 decimal places , (ans is
// double)
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | a43d5b07b60a16029e59d0122f85cd7a | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
static long mod = (int)1e9+7;
// static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
public static void main (String[] args) throws java.lang.Exception
{
FastReader sc =new FastReader();
int t=sc.nextInt();
// int t=1;
outer : while(t-->0)
{
int n = sc.nextInt();
int arr[] = sc.readArray(n);
for(int i=1;i<n;i++)
{
if(arr[i] % arr[0] != 0)
{
System.out.println("NO");
continue outer;
}
}
System.out.println("YES");
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
float nextFloat()
{
return Float.parseFloat(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] readArrayLong(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
}
static class FenwickTree
{
//Binary Indexed Tree
//1 indexed
public int[] tree;
public int size;
public FenwickTree(int size)
{
this.size = size;
tree = new int[size+5];
}
public void add(int i, int v)
{
while(i <= size)
{
tree[i] += v;
i += i&-i;
}
}
public int find(int i)
{
int res = 0;
while(i >= 1)
{
res += tree[i];
i -= i&-i;
}
return res;
}
public int find(int l, int r)
{
return find(r)-find(l-1);
}
}
public static int[] radixSort2(int[] a)
{
int n = a.length;
int[] c0 = new int[0x101];
int[] c1 = new int[0x101];
int[] c2 = new int[0x101];
int[] c3 = new int[0x101];
for(int v : a) {
c0[(v&0xff)+1]++;
c1[(v>>>8&0xff)+1]++;
c2[(v>>>16&0xff)+1]++;
c3[(v>>>24^0x80)+1]++;
}
for(int i = 0;i < 0xff;i++) {
c0[i+1] += c0[i];
c1[i+1] += c1[i];
c2[i+1] += c2[i];
c3[i+1] += c3[i];
}
int[] t = new int[n];
for(int v : a)t[c0[v&0xff]++] = v;
for(int v : t)a[c1[v>>>8&0xff]++] = v;
for(int v : a)t[c2[v>>>16&0xff]++] = v;
for(int v : t)a[c3[v>>>24^0x80]++] = v;
return a;
}
private static long mergeAndCount(int[] arr, int l,
int m, int r)
{
// Left subarray
int[] left = Arrays.copyOfRange(arr, l, m + 1);
// Right subarray
int[] right = Arrays.copyOfRange(arr, m + 1, r + 1);
int i = 0, j = 0, k = l;long swaps = 0;
while (i < left.length && j < right.length) {
if (left[i] < right[j])
arr[k++] = left[i++];
else {
arr[k++] = right[j++];
swaps += (m + 1) - (l + i);
}
}
while (i < left.length)
arr[k++] = left[i++];
while (j < right.length)
arr[k++] = right[j++];
return swaps;
}
// Merge sort function
private static long mergeSortAndCount(int[] arr, int l,
int r)
{
// Keeps track of the inversion count at a
// particular node of the recursion tree
long count = 0;
if (l < r) {
int m = (l + r) / 2;
// Total inversion count = left subarray count
// + right subarray count + merge count
// Left subarray count
count += mergeSortAndCount(arr, l, m);
// Right subarray count
count += mergeSortAndCount(arr, m + 1, r);
// Merge count
count += mergeAndCount(arr, l, m, r);
}
return count;
}
static void my_sort(long[] arr)
{
ArrayList<Long> list = new ArrayList<>();
for(int i=0;i<arr.length;i++)
{
list.add(arr[i]);
}
Collections.sort(list);
for(int i=0;i<arr.length;i++)
{
arr[i] = list.get(i);
}
}
static void reverse_sorted(int[] arr)
{
ArrayList<Integer> list = new ArrayList<>();
for(int i=0;i<arr.length;i++)
{
list.add(arr[i]);
}
Collections.sort(list , Collections.reverseOrder());
for(int i=0;i<arr.length;i++)
{
arr[i] = list.get(i);
}
}
static int LowerBound(int a[], int x) { // x is the target value or key
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]>=x) r=m;
else l=m;
}
return r;
}
static int UpperBound(ArrayList<Integer> list, int x) {// x is the key or target value
int l=-1,r=list.size();
while(l+1<r) {
int m=(l+r)>>>1;
if(list.get(m)<=x) l=m;
else r=m;
}
return l+1;
}
public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm)
{
// Create a list from elements of HashMap
List<Map.Entry<Integer, Integer> > list =
new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet());
// Sort the list
Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() {
public int compare(Map.Entry<Integer, Integer> o1,
Map.Entry<Integer, Integer> o2)
{
return (o1.getValue()).compareTo(o2.getValue());
}
});
// put data from sorted list to hashmap
HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> aa : list) {
temp.put(aa.getKey(), aa.getValue());
}
return temp;
}
static class Queue_Pair implements Comparable<Queue_Pair> {
int first , second;
public Queue_Pair(int first, int second) {
this.first=first;
this.second=second;
}
public int compareTo(Queue_Pair o) {
return Integer.compare(o.first, first);
}
}
static void leftRotate(int arr[], int d, int n)
{
for (int i = 0; i < d; i++)
leftRotatebyOne(arr, n);
}
static void leftRotatebyOne(int arr[], int n)
{
int i, temp;
temp = arr[0];
for (i = 0; i < n - 1; i++)
arr[i] = arr[i + 1];
arr[n-1] = temp;
}
static boolean isPalindrome(String str)
{
// Pointers pointing to the beginning
// and the end of the string
int i = 0, j = str.length() - 1;
// While there are characters to compare
while (i < j) {
// If there is a mismatch
if (str.charAt(i) != str.charAt(j))
return false;
// Increment first pointer and
// decrement the other
i++;
j--;
}
// Given string is a palindrome
return true;
}
static boolean palindrome_array(char arr[], int n)
{
// Initialise flag to zero.
int flag = 0;
// Loop till array size n/2.
for (int i = 0; i <= n / 2 && n != 0; i++) {
// Check if first and last element are different
// Then set flag to 1.
if (arr[i] != arr[n - i - 1]) {
flag = 1;
break;
}
}
// If flag is set then print Not Palindrome
// else print Palindrome.
if (flag == 1)
return false;
else
return true;
}
static boolean allElementsEqual(int[] arr,int n)
{
int z=0;
for(int i=0;i<n-1;i++)
{
if(arr[i]==arr[i+1])
{
z++;
}
}
if(z==n-1)
{
return true;
}
else
{
return false;
}
}
static boolean allElementsDistinct(int[] arr,int n)
{
int z=0;
for(int i=0;i<n-1;i++)
{
if(arr[i]!=arr[i+1])
{
z++;
}
}
if(z==n-1)
{
return true;
}
else
{
return false;
}
}
public static void reverse(int[] array)
{
// Length of the array
int n = array.length;
// Swaping the first half elements with last half
// elements
for (int i = 0; i < n / 2; i++) {
// Storing the first half elements temporarily
int temp = array[i];
// Assigning the first half to the last half
array[i] = array[n - i - 1];
// Assigning the last half to the first half
array[n - i - 1] = temp;
}
}
public static void reverse_Long(long[] array)
{
// Length of the array
int n = array.length;
// Swaping the first half elements with last half
// elements
for (int i = 0; i < n / 2; i++) {
// Storing the first half elements temporarily
long temp = array[i];
// Assigning the first half to the last half
array[i] = array[n - i - 1];
// Assigning the last half to the first half
array[n - i - 1] = temp;
}
}
static boolean isSorted(int[] a)
{
for (int i = 0; i < a.length - 1; i++)
{
if (a[i] > a[i + 1]) {
return false;
}
}
return true;
}
static boolean isReverseSorted(int[] a)
{
for (int i = 0; i < a.length - 1; i++)
{
if (a[i] < a[i + 1]) {
return false;
}
}
return true;
}
static int[] rearrangeEvenAndOdd(int arr[], int n)
{
ArrayList<Integer> list = new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
{
list.add(arr[i]);
}
}
for(int i=0;i<n;i++)
{
if(arr[i]%2!=0)
{
list.add(arr[i]);
}
}
int len = list.size();
int[] array = list.stream().mapToInt(i->i).toArray();
return array;
}
static long[] rearrangeEvenAndOddLong(long arr[], int n)
{
ArrayList<Long> list = new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
{
list.add(arr[i]);
}
}
for(int i=0;i<n;i++)
{
if(arr[i]%2!=0)
{
list.add(arr[i]);
}
}
int len = list.size();
long[] array = list.stream().mapToLong(i->i).toArray();
return array;
}
static boolean isPrime(long n)
{
// Check if number is less than
// equal to 1
if (n <= 1)
return false;
// Check if number is 2
else if (n == 2)
return true;
// Check if n is a multiple of 2
else if (n % 2 == 0)
return false;
// If not, then just check the odds
for (long i = 3; i <= Math.sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
static long getSum(long n)
{
long sum = 0;
while (n != 0)
{
sum = sum + n % 10;
n = n/10;
}
return sum;
}
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static long gcdLong(long a, long b)
{
if (b == 0)
return a;
return gcdLong(b, a % b);
}
static void swap(int i, int j)
{
int temp = i;
i = j;
j = temp;
}
static int countDigit(int n)
{
return (int)Math.floor(Math.log10(n) + 1);
}
}
class Pair
{
int first;
int second;
Pair(int first , int second)
{
this.first = first;
this.second = second;
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | da30b5478d1470da5146038ca1095893 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main extends PrintWriter {
Main() { super(System.out); }
static boolean cases = true;
// Solution
void solve(int t) {
int n = sc.nextInt();
int a[] = sc.readIntArray(n);
for (int i = 1; i < n; i++) {
if (a[i] % a[0] != 0) {
System.out.println("NO");
return;
}
}
System.out.println("YES");
}
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a) l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++) a[i] = l.get(i);
}
public static void main(String[] args) {
Main obj = new Main();
int c = 1;
for (int t = (cases ? sc.nextInt() : 0); t > 1; t--, c++) obj.solve(c);
obj.solve(c);
obj.flush();
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
int[] readIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
char[] readCharArray(int n) {
char a[] = new char[n];
String s = sc.next();
for (int i = 0; i < n; i++) { a[i] = s.charAt(i); }
return a;
}
long[] readLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
long nextLong() { return Long.parseLong(next()); }
}
final int ima = Integer.MAX_VALUE;
final int imi = Integer.MIN_VALUE;
final long lma = Long.MAX_VALUE;
final long lmi = Long.MIN_VALUE;
static final long mod = (long) 1e9 + 7;
private static final FastScanner sc = new FastScanner();
private PrintWriter out = new PrintWriter(System.out);
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 88bb3c57b58c2b9056631aaa7cc829e2 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class cf {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int testcase = scan.nextInt();
// int testcase = 1;
for(int v = 0; v < testcase; v++){
int n = scan.nextInt();
int []arr = new int[n];
arr[0] = scan.nextInt();
boolean bool = true;
for(int i = 1; i < n; i++){
arr[i] = scan.nextInt();
if(arr[i] % arr[0] != 0){
bool = false;
}
}
if(bool){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | ca2a2d9dd80622693e5e4e25f0460eff | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
public class DifferencesOp {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t--!=0){
int n =sc.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;i++){
arr[i] = sc.nextInt();
}
boolean check=false;
for(int i=1;i<n;i++){
if(arr[i]%arr[0]!=0){
check=true;
break;
}
}
if(check)
System.out.println("NO");
else
System.out.println("YES");
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | bcb1cc083fe10dc6cd450d87222a3a5d | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
int m=0;
for(int i=1;i<n;i++)
{
if(arr[i]%arr[0]!=0)
m=1;
}
System.out.println(m==1?"NO":"YES");
}
// your code goes here
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 55cf20bb723e4330f9c3a26d66e127b4 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
int m=0;
for(int i=1;i<n;i++){
if(a[i]%a[0]!=0||(a[i]==0&&i!=n-1))
m=1;
}
if(m==1)
System.out.println("NO");
else
System.out.println("YES");
}
// your code goes here
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | fffc18a823423e74f3763bd65804ac6a | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.lang.*;
public class jin {
public static int n;
static Scanner source = new Scanner(System.in);
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
public static void make(int n) {
while (n > 0) {
int x = source.nextInt();
int[] arr = new int[x];
boolean b = true;
for(int i=0;i<x;i++){
arr[i] = source.nextInt();
if(i>0 && b && arr[i]%arr[0]!=0){
b = false;
}
}
if(b){
System.out.println("yes");
}
else{
System.out.println("no");
}
n--;
}
}
public static void main(String[] args) {
n = source.nextInt();
make(n);
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | abb42009cdfac1e38e96fc407c820e1b | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
public class A {
static FastScanner fs=new FastScanner();
public static void main(String[] args) {
int tc= fs.nextInt();
for (int i=0;i<tc;i++){
int n= fs.nextInt();
long[] arr= fs.readArray(n);
boolean isPoss=true;
for (int j=1;j<n;j++){
if (arr[j]%arr[0]!=0) {
isPoss=false;
break;
}
}
System.out.println(isPoss?"YES":"NO");
}
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
public BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long[] readArray(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 3bd61b32577e618698994bea8550153e | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class main {
public static void main(String[] strgs) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-- >0) {
int n=sc.nextInt();
ArrayList<Long> list=new ArrayList<>();
//gcd
for(int i=0;i<n;i++) {
list.add(sc.nextLong());
}
long gcdsum=list.get(0);
for(int i=1;i<n;i++) {
gcdsum=gcd(gcdsum,list.get(i));
}
if(list.indexOf(gcdsum)!=-1 && list.indexOf(gcdsum)==0) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
public static long gcd(long x,long y) {
long a=(x>y)?x:y;
long b=(x<y)?x:y;
long r=b;
while(a%b!=0) {
r=a%b;
a=b;
b=r;
}
return r;
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 7643590caf370b9988649a7336b7d8c0 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | // import static java.lang.System.out;
import static java.lang.Math.*;
import java.util.*;
import javax.naming.ContextNotEmptyException;
import javax.swing.ImageIcon;
import javax.swing.table.TableStringConverter;
import java.io.*;
import java.math.*;
import java.rmi.ConnectIOException;
public class Main {
static FastReader sc;
static long mod = ((long) 1e9) + 7;
static Tree tree;
static PrintWriter out, err;
static int imax = Integer.MAX_VALUE;
static int imin = Integer.MIN_VALUE;
static boolean testcaseBool = false;
static long lmax = Long.MAX_VALUE;
static long lmin = Long.MIN_VALUE;
static double dmax = Double.MAX_VALUE;
static double dmin = Double.MIN_VALUE;
static int max = 0;
private static void solve() throws IOException{
int n=sc.nextInt();
int[] arr=readIntArray(n);
boolean done=true;
boolean equal=true;
boolean z=true;
boolean modequal=true;
int prev=arr[1]%arr[0];
for(int i=1;i<n;i++){
if(arr[i]%arr[0]!=0){
done=false;
}
}
if(done)print("yes");
else print("No");
}
public static void main(String hi[]) throws IOException {
initializeIO();
out = new PrintWriter(System.out);
err = new PrintWriter(System.err);
sc = new FastReader();
long startTimeProg = System.currentTimeMillis();
long endTimeProg;
int testCase = 1;
// Collections.sort(li);
// debug(li+"");
// debug(li+"");
testCase = sc.nextInt();
while (testCase-- != 0) {
solve();
}
endTimeProg = System.currentTimeMillis();
debug("[finished : " + (endTimeProg - startTimeProg) + ".ms ]");
out.flush();
err.flush();
// System.out.println(String.format("%.9f", max));
}
private static class Pair {
int first = 0;
int sec = 0;
int[] arr;
char ch;
String s;
Map<Integer, Integer> map;
Pair(int first, int sec) {
this.first = first;
this.sec = sec;
}
Pair(int[] arr) {
this.map = new HashMap<>();
for (int x : arr)
this.map.put(x, map.getOrDefault(x, 0) + 1);
this.arr = arr;
}
Pair(char ch, int first) {
this.ch = ch;
this.first = first;
}
Pair(String s, int first) {
this.s = s;
this.first = first;
}
}
private static Set<Long> factors(long n) {
Set<Long> res = new HashSet<>();
// res.add(n);
for (long i = 1; i * i <= (n); i++) {
if (n % i == 0) {
res.add(i);
if (n / i != i) {
res.add(n / i);
}
}
}
return res;
}
// geometrics
private static double areaOftriangle(double x1, double y1, double x2, double y2, double x3, double y3) {
double[] mid_point = midOfaLine(x1, y1, x2, y2);
// debug(Arrays.toString(mid_point)+" "+x1+" "+y1+" "+x2+" "+y2+" "+x3+" "+"
// "+y3);
double height = distanceBetweenPoints(mid_point[0], mid_point[1], x3, y3);
double wight = distanceBetweenPoints(x1, y1, x2, y2);
// debug(height+" "+wight);
return (height * wight) / 2;
}
private static double distanceBetweenPoints(double x1, double y1, double x2, double y2) {
double x = x2 - x1;
double y = y2 - y1;
return (Math.pow(x, 2) + Math.pow(y, 2));
}
private static double[] midOfaLine(double x1, double y1, double x2, double y2) {
double[] mid = new double[2];
mid[0] = (x1 + x2) / 2;
mid[1] = (y1 + y2) / 2;
return mid;
}
/* Function to calculate x raised to the power y in O(logn) */
static long power(long x, long y) {
long temp;
if (y == 0)
return 1l;
temp = power(x, y / 2);
if (y % 2 == 0)
return (temp * temp);
else
return (x * temp * temp);
}
private static StringBuilder reverseString(String s) {
StringBuilder sb = new StringBuilder(s);
int l = 0, r = sb.length() - 1;
while (l <= r) {
char ch = sb.charAt(l);
sb.setCharAt(l, sb.charAt(r));
sb.setCharAt(r, ch);
l++;
r--;
}
return sb;
}
private static void swap(List<Integer> li, int i, int j) {
int t = li.get(i);
li.set(i, li.get(j));
li.set(j, t);
}
private static void swap(int[] arr, int i, int j) {
int t = arr[i];
arr[i] = arr[j];
arr[j] = t;
}
static int lcm(int a, int b) {
return (a / gcd(a, b)) * b;
}
static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
private static boolean isPallindrome(String s, int l, int r) {
while (l < r) {
if (s.charAt(l) != s.charAt(r))
return false;
l++;
r--;
}
return true;
}
private static StringBuilder removeLeadingZero(StringBuilder sb) {
int i = 0;
while (i < sb.length() && sb.charAt(i) == '0')
i++;
// debug("remove "+i);
if (i == sb.length())
return new StringBuilder();
return new StringBuilder(sb.substring(i, sb.length()));
}
private static void print(int[][] arr) {
int n = arr.length;
int m = arr[0].length;
int i, j;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
out.print(arr[i][j] + " ");
}
out.println();
}
}
private static StringBuilder removeEndingZero(StringBuilder sb) {
int i = sb.length() - 1;
while (i >= 0 && sb.charAt(i) == '0')
i--;
if (i < 0)
return new StringBuilder();
return new StringBuilder(sb.substring(0, i + 1));
}
private static void debug(int[][] arr) {
for (int i = 0; i < arr.length; i++) {
err.println(Arrays.toString(arr[i]));
}
}
private static void debug(long[][] arr) {
for (int i = 0; i < arr.length; i++) {
err.println(Arrays.toString(arr[i]));
}
}
private static void debug(List<int[]> arr) {
for (int[] a : arr) {
err.println(Arrays.toString(a));
}
}
private static void debug(float[][] arr) {
for (int i = 0; i < arr.length; i++) {
err.println(Arrays.toString(arr[i]));
}
}
private static void debug(double[][] arr) {
for (int i = 0; i < arr.length; i++) {
err.println(Arrays.toString(arr[i]));
}
}
private static void debug(boolean[][] arr) {
for (int i = 0; i < arr.length; i++) {
err.println(Arrays.toString(arr[i]));
}
}
// private static void print() throws IOException {
// out.println(s);
// }
private static void debug(String s) throws IOException {
err.println(s);
}
private static void print(double s) throws IOException {
out.println(s);
}
private static void print(float s) throws IOException {
out.println(s);
}
private static void print(long s) throws IOException {
out.println(s);
}
private static void print(int s) throws IOException {
out.println(s);
}
private static void debug(double s) throws IOException {
err.println(s);
}
private static void debug(float s) throws IOException {
err.println(s);
}
private static void debug(long s) {
err.println(s);
}
private static void debug(int s) {
err.println(s);
}
private static boolean isPrime(long n) {
// Check if number is less than
// equal to 1
if (n <= 1)
return false;
// Check if number is 2
else if (n == 2)
return true;
// Check if n is a multiple of 2
else if (n % 2 == 0)
return false;
// If not, then just check the odds
for (int i = 3; i * i <= n; i += 2) {
if (n % i == 0)
return false;
}
return true;
}
private static List<List<Integer>> readUndirectedGraph(int n) {
List<List<Integer>> graph = new ArrayList<>();
for (int i = 0; i <= n; i++) {
graph.add(new ArrayList<>());
}
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
graph.get(x).add(y);
graph.get(y).add(x);
}
return graph;
}
private static List<List<Integer>> readUndirectedGraph(int[][] intervals, int n) {
List<List<Integer>> graph = new ArrayList<>();
for (int i = 0; i <= n; i++) {
graph.add(new ArrayList<>());
}
for (int i = 0; i < intervals.length; i++) {
int x = intervals[i][0];
int y = intervals[i][1];
graph.get(x).add(y);
graph.get(y).add(x);
}
return graph;
}
private static List<List<Integer>> readDirectedGraph(int[][] intervals, int n) {
List<List<Integer>> graph = new ArrayList<>();
for (int i = 0; i <= n; i++) {
graph.add(new ArrayList<>());
}
for (int i = 0; i < intervals.length; i++) {
int x = intervals[i][0];
int y = intervals[i][1];
graph.get(x).add(y);
// graph.get(y).add(x);
}
return graph;
}
private static List<List<Integer>> readDirectedGraph(int n) {
List<List<Integer>> graph = new ArrayList<>();
for (int i = 0; i <= n; i++) {
graph.add(new ArrayList<>());
}
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
graph.get(x).add(y);
// graph.get(y).add(x);
}
return graph;
}
static String[] readStringArray(int n) {
String[] arr = new String[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.next();
}
return arr;
}
private static Map<Character, Integer> freq(String s) {
Map<Character, Integer> map = new HashMap<>();
for (char c : s.toCharArray()) {
map.put(c, map.getOrDefault(c, 0) + 1);
}
return map;
}
private static Map<Long, Integer> freq(long[] arr) {
Map<Long, Integer> map = new HashMap<>();
for (long x : arr) {
map.put(x, map.getOrDefault(x, 0) + 1);
}
return map;
}
private static Map<Integer, Integer> freq(int[] arr) {
Map<Integer, Integer> map = new HashMap<>();
for (int x : arr) {
map.put(x, map.getOrDefault(x, 0) + 1);
}
return map;
}
static boolean[] sieveOfEratosthenes(long n) {
boolean prime[] = new boolean[(int) n + 1];
for (int i = 2; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++) {
// If prime[p] is not changed, then it is a
// prime
if (prime[p] == true) {
// Update all multiples of p
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
return prime;
}
static int[] sieveOfEratosthenesInt(long n) {
boolean prime[] = new boolean[(int) n + 1];
Set<Integer> li = new HashSet<>();
for (int i = 2; i <= n; i++) {
prime[i] = true;
}
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= n; i += p) {
prime[i] = false;
}
}
}
for (int i = 0; i <= n; i++) {
if (prime[i])
li.add(i);
}
int[] arr = new int[li.size()];
int i = 0;
for (int x : li) {
arr[i++] = x;
}
return arr;
}
static boolean isMemberAC(int a, int d, int x) {
// If difference is 0, then x must
// be same as a.
if (d == 0)
return (x == a);
// Else difference between x and a
// must be divisible by d.
return ((x - a) % d == 0 && (x - a) / d >= 0);
}
static boolean isMemberAC(long a, long d, long x) {
// If difference is 0, then x must
// be same as a.
if (d == 0)
return (x == a);
// Else difference between x and a
// must be divisible by d.
return ((x - a) % d == 0 && (x - a) / d >= 0);
}
private static void sort(int[] arr) {
int n = arr.length;
List<Integer> li = new ArrayList<>();
for (int x : arr) {
li.add(x);
}
Collections.sort(li);
for (int i = 0; i < n; i++) {
arr[i] = li.get(i);
}
}
private static void sortReverse(int[] arr) {
int n = arr.length;
List<Integer> li = new ArrayList<>();
for (int x : arr) {
li.add(x);
}
Collections.sort(li, Collections.reverseOrder());
for (int i = 0; i < n; i++) {
arr[i] = li.get(i);
}
}
private static void sort(double[] arr) {
int n = arr.length;
List<Double> li = new ArrayList<>();
for (double x : arr) {
li.add(x);
}
Collections.sort(li);
for (int i = 0; i < n; i++) {
arr[i] = li.get(i);
}
}
private static void sortReverse(double[] arr) {
int n = arr.length;
List<Double> li = new ArrayList<>();
for (double x : arr) {
li.add(x);
}
Collections.sort(li, Collections.reverseOrder());
for (int i = 0; i < n; i++) {
arr[i] = li.get(i);
}
}
private static void sortReverse(long[] arr) {
int n = arr.length;
List<Long> li = new ArrayList<>();
for (long x : arr) {
li.add(x);
}
Collections.sort(li, Collections.reverseOrder());
for (int i = 0; i < n; i++) {
arr[i] = li.get(i);
}
}
private static void sort(long[] arr) {
int n = arr.length;
List<Long> li = new ArrayList<>();
for (long x : arr) {
li.add(x);
}
Collections.sort(li);
for (int i = 0; i < n; i++) {
arr[i] = li.get(i);
}
}
private static long sum(int[] arr) {
long sum = 0;
for (int x : arr) {
sum += x;
}
return sum;
}
private static long sum(long[] arr) {
long sum = 0;
for (long x : arr) {
sum += x;
}
return sum;
}
private static void initializeIO() {
try {
System.setIn(new FileInputStream("input.txt"));
System.setOut(new PrintStream(new FileOutputStream("output.txt")));
System.setErr(new PrintStream(new FileOutputStream("error.txt")));
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
private static int maxOfArray(int[] arr) {
int max = Integer.MIN_VALUE;
for (int x : arr) {
max = Math.max(max, x);
}
return max;
}
private static long maxOfArray(long[] arr) {
long max = Long.MIN_VALUE;
for (long x : arr) {
max = Math.max(max, x);
}
return max;
}
private static int[][] readIntIntervals(int n, int m) {
int[][] arr = new int[n][m];
for (int j = 0; j < n; j++) {
for (int i = 0; i < m; i++) {
arr[j][i] = sc.nextInt();
}
}
return arr;
}
private static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private static int[] readIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
return arr;
}
private static double[] readDoubleArray(int n) {
double[] arr = new double[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextDouble();
}
return arr;
}
private static long[] readLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextLong();
}
return arr;
}
private static void print(int[] arr) throws IOException {
out.println(Arrays.toString(arr));
}
private static void print(long[] arr) throws IOException {
out.println(Arrays.toString(arr));
}
private static void print(String[] arr) throws IOException {
out.println(Arrays.toString(arr));
}
private static void print(double[] arr) throws IOException {
out.println(Arrays.toString(arr));
}
private static void debug(String[] arr) {
err.println(Arrays.toString(arr));
}
private static void debug(Boolean[][] arr) {
for (int i = 0; i < arr.length; i++)
err.println(Arrays.toString(arr[i]));
}
private static void debug(int[] arr) {
err.println(Arrays.toString(arr));
}
private static void debug(long[] arr) {
err.println(Arrays.toString(arr));
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
static class Tree {
List<List<Integer>> adj = new ArrayList<>();
int parent = 1;
int[] arr;
int n;
Map<Integer, Integer> node_parent;
List<Integer> leaf;
public Tree(int n) {
this.n = n;
leaf = new ArrayList<>();
node_parent = new HashMap<>();
arr = new int[n + 2];
for (int i = 0; i <= n + 1; i++) {
adj.add(new ArrayList<>());
}
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
node_parent.put(i + 1, arr[i]);
if ((i + 1) == arr[i])
parent = arr[i];
else
adj.get(arr[i]).add(i + 1);
}
}
private List<List<Integer>> getTree() {
return adj;
}
private void formLeaf(int v) {
boolean leaf = true;
for (int x : adj.get(v)) {
formLeaf(x);
leaf = false;
}
if (leaf)
this.leaf.add(v);
}
private List<Integer> getLeaf() {
return leaf;
}
private Map<Integer, Integer> getParents() {
return node_parent;
}
int[] getArr() {
return arr;
}
}
static class Dsu {
int[] parent, size;
Dsu(int n) {
parent = new int[n + 1];
size = new int[n + 1];
for (int i = 0; i <= n; i++) {
parent[i] = i;
size[i] = 1;
}
}
private int findParent(int u) {
if (parent[u] == u)
return u;
return parent[u] = findParent(parent[u]);
}
private boolean union(int u, int v) {
// System.out.println("uf "+u+" "+v);
int pu = findParent(u);
// System.out.println("uf2 "+pu+" "+v);
int pv = findParent(v);
// System.out.println("uf3 " + u + " " + pv);
if (pu == pv)
return false;
if (size[pu] <= size[pv]) {
parent[pu] = pv;
size[pv] += size[pu];
} else {
parent[pv] = pu;
size[pu] += size[pv];
}
return true;
}
}
// ===================================================================================
public static int log2(int N) {
return (int) (Math.log(N) / Math.log(2));
}
private static long fact(long n) {
if (n <= 2)
return n;
return n * fact(n - 1);
}
private static void print(String s) throws IOException {
out.println(s);
}
public static boolean isNumeric(String strNum) {
if (strNum == null) {
return false;
}
try {
double d = Double.parseDouble(strNum);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
private static boolean isSorted(List<Integer> li) {
int n = li.size();
if (n <= 1)
return true;
for (int i = 0; i < n - 1; i++) {
if (li.get(i) > li.get(i + 1))
return false;
}
return true;
}
private static boolean isSorted(int[] arr) {
int n = arr.length;
if (n <= 1)
return true;
for (int i = 0; i < n - 1; i++) {
if (arr[i] > arr[i + 1])
return false;
}
return true;
}
private static boolean ispallindromeList(List<Integer> res) {
int l = 0, r = res.size() - 1;
while (l < r) {
if (res.get(l) != res.get(r))
return false;
l++;
r--;
}
return true;
}
private static long ncr(long n, long r) {
return fact(n) / (fact(r) * fact(n - r));
}
private static void swap(char[] s, int i, int j) {
char t = s[i];
s[i] = s[j];
s[j] = t;
}
static boolean isPowerOfTwo(long x) {
return x != 0 && ((x & (x - 1)) == 0);
}
private static long gcd(long[] arr) {
long ans = 0;
for (long x : arr) {
ans = gcd(x, ans);
}
return ans;
}
private static int gcd(int[] arr) {
int ans = 0;
for (int x : arr) {
ans = gcd(x, ans);
}
return ans;
}
private static long power(long x, long y, long p) {
long res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0) {
if ((y & 1) != 0)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | dbfb43b9c16e2e62e9831038eadaa446 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | /*
_oo0oo_
o8888888o
88" . "88
(| -_- |)
0\ = /0
___/`---'\___
.' \\| |// '.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' |_/ |
\ .-\__ '-' ___/-. /
___'. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' >' "".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `_. \_ __\ /__ _/ .-` / /
=====`-.____`.___ \_____/___.-`___.-'=====
`=---='
*/
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.Math.*;
public class KickStart2020 {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
float nextFloat() {
return Float.parseFloat(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static long lcm(long a, long b) {
return a / gcd(a, b) * b;
}
public static class Pair implements Comparable<Pair> {
public int index;
public long value;
public Pair(int index, long value) {
this.index = index;
this.value = value;
}
@Override
public int compareTo(Pair other) {
// multiplied to -1 as the author need descending sort order
if(other.index < this.index) return 1;
if(other.index > this.index) return -1;
return 0;
}
@Override
public String toString() {
return this.index + " " + this.value;
}
}
static boolean isPrime(long d) {
if(d == 0) return true;
if (d == 1)
return false;
for (int i = 2; i <= (long) Math.sqrt(d); i++) {
if (d % i == 0)
return false;
}
return true;
}
static boolean isPali(String n) {
String s = n;
int l = 0;
int r = s.length() - 1;
while(l < r) if(s.charAt(l++) != s.charAt(r--)) return false;
return true;
}
static void decimalTob(long n, int k , int arr[], int i) {
arr[i] += (n % k);
n /= k;
if(n > 0) {
decimalTob(n, k, arr, i + 1);
}
}
static long powermod(long x, long y, long mod) {
if(y == 0) return 1;
long value = powermod(x, y / 2, mod);
if(y % 2 == 0) return (value * value) % mod;
return (value * (value * x) % mod) % mod;
}
static long power(long x, long y) {
if(y == 0) return 1;
long value = power(x, y / 2);
if(y % 2 == 0) return (value * value);
return value * value * x;
}
static int bS(int l, int r, int find, Integer arr[]) {
int ans = -1;
while(l <= r) {
int mid = (l + r) / 2;
if(arr[mid] >= find) {
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
return ans;
}
static void build(int index, int l, int r, int seqtree[][], int i, int arr[][]) {
if(l == r) {
seqtree[i][index] = arr[i][l];
return;
}
int mid = (l + r) / 2;
build(2 * index + 1, l, mid, seqtree, i, arr);
build(2 * index + 2, mid + 1, r, seqtree, i, arr);
seqtree[i][index] = Math.max(seqtree[i][2 * index + 1], seqtree[i][2 * index + 2]);
}
static int query(int index, int low, int high, int l, int r, int seqtree[][], int i) {
if(high < l || low > r) return Integer.MIN_VALUE;
if(l <= low && r >= high) {
return seqtree[i][index];
}
int mid = (low + high) / 2;
int left = query(2 * index + 1, low , mid, l, r, seqtree, i);
int right = query(2 * index + 2, mid + 1, high, l, r, seqtree,i);
return Math.max(left, right);
}
static int brr[] = new int[100000 + 1];
static int dp(int i, int j, int arr[], int dp[][], int n) {
if(i == n) return 0;
if(j == 0) return 0;
if(dp[i][j] != -1) return dp[i][j];
if(arr[i] <= j) {
return dp[i][j] = 1 + dp(i + 1, j, arr, dp, n);
}
else {
int max = 1 + dp(i + 1, j - 1, arr, dp, n);
max = Math.max(max, dp(i + 2, j , arr, dp, n));
return dp[i][j] = max;
}
}
public static void main(String[] args) throws Exception {
FastReader sc = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
outerloop:
while(t-- > 0) {
int n = sc.nextInt();
int arr[] = new int[n];
for(int i = 0; i < n; i++) arr[i] = sc.nextInt();
for(int i = 1; i < n; i++) {
arr[i] = arr[i] % arr[i - 1];
if(arr[i] == 0) arr[i] = arr[i - 1];
}
for(int i = 1; i < n; i++) {
if(arr[i] % arr[i - 1] != 0) {
out.println("NO");
continue outerloop;
}
}
out.println("YES");
}
out.close();
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 6014c187c285ef58bc26596d196d9815 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.BigInteger;
import java.util.stream.Collectors;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
void run() throws Exception {
boolean oj = false;
if(System.getProperty("ONLINE_JUDGE") == null) oj = true;
if(!oj) {
is = System.in; out = new PrintWriter(System.out);
solve(); out.flush(); out.close();
} else {
PrintStream ps = new PrintStream(new File("output2.txt"));
InputStream iss = new FileInputStream("input.txt");
System.setIn(iss); System.setOut(ps);
is = System.in; out = new PrintWriter(System.out);
solve(); out.flush(); out.close();
}
}
public static void main(String[] args) throws Exception {
new Main().run();
}
public byte[] inbuf = new byte[1 << 16];
public int lenbuf = 0, ptrbuf = 0;
public int readByte() {
if (lenbuf == -1) {
throw new InputMismatchException();
}
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return -1;
}
return inbuf[ptrbuf++];
}
public boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
public int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b))
;
return b;
}
public double nd() {
return Double.parseDouble(ns());
}
public char nc() {
return (char) skip();
}
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private int ni() {
return (int) nl();
}
private long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
class Pair {
int first;
int second;
Pair(int a, int b) {
first = a;
second = b;
}
}
long[] nal(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nl();
}
return arr;
}
// Sorting an array (O(nlogn)):-
int partition(long[] array, int begin, int end) {
int pivot = end;
int counter = begin;
for (int i = begin; i < end; i++) {
if (array[i] < array[pivot]) {
long temp = array[counter];
array[counter] = array[i];
array[i] = temp;
counter++;
}
}
long temp = array[pivot];
array[pivot] = array[counter];
array[counter] = temp;
return counter;
}
void sort(long[] array, int begin, int end) {
if (end <= begin) return;
int pivot = partition(array, begin, end);
sort(array, begin, pivot-1);
sort(array, pivot+1, end);
}
void printArr(long[] arr) {
for(int i=0; i<arr.length; i++) {
out.print(arr[i] + " ");
}
out.println();
}
long[] arr;
// **********************************************************************************
class Segment_Tree {
long[] t = new long[4 * arr.length];
void build(int index, int left, int right) {
if(left == right) {
t[index] = arr[left];
return;
}
int mid = (left + right) / 2;
build(index * 2, left, mid);
build(index * 2 + 1, mid + 1, right);
t[index] = t[2 * index] + t[2 * index + 1];
}
// indexPos -> For what index we have to update the value of an array.
void update(int index, int left, int right, int indexPos, int value) {
if(indexPos < left || indexPos > right) return;
if(left == right) {
t[index] = value;
arr[left] = value;
return;
}
int mid = (left + right) / 2;
update(2 * index, left, mid, indexPos, value);
update(2 * index + 1, mid + 1, right, indexPos, value);
t[index] = t[2 * index] + t[2 * index + 1];
}
long query(int index, int left, int right, int leftRange, int rightRange) {
if(left > rightRange || leftRange > right) return 0;
if(leftRange <= left && right <= rightRange) {
return t[index];
}
int mid = (left + right) / 2;
long a = query(index * 2, left, mid, leftRange, rightRange);
long b = query(index * 2 + 1, mid + 1, right, leftRange, rightRange);
return a + b;
}
}
// **********************************************************************************
void solve() {
int test_case = 1;
test_case = ni();
while (test_case-- > 0) {
go();
}
}
// WRITE CODE FROM HERE :-
void go() {
int n = ni();
arr = nal(n);
long p = arr[0];
for(int i=0; i<n; i++) {
if(arr[i] % p != 0) {
out.println("NO");
return;
}
}
out.println("YES");
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 5c71ef566331c08de762c4019ab52eb3 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class cp {
//start
public static void main(String[] args) {
int t = in();
while(t-->0) {
int n = in();
var a = in(n);
var ans = true;
if(a[1]%a[0]!=0) ans=false;
if(ans) {
a[1]=a[0];
for(int i = 2; i < n; ++i) {
if(a[i]%a[i-1]!=0) ans=false;
a[i]=a[i-1];
}
}
System.out.println(ans?"YES":"NO");
}
}
//end
public static int m=(int)1e9+7;
public static Scanner sc = new Scanner(System.in);
public static int in() {
int n = sc.hasNextInt()?sc.nextInt():0; sc.nextLine();
return n;
}
public static int[] in(int n) {
int[] a = new int[n];
for(int i=0;i<n;++i)
a[i]=sc.hasNextInt()?sc.nextInt():0;
sc.nextLine();
return a;
}
public static String in(boolean s) {
return sc.hasNextLine()?sc.nextLine():"";
}
public static void out(String s) {
System.out.println(s);
}
public static void out(int[] a) {
for(int i=0;i<a.length;++i) System.out.print(a[i]+" ");
System.out.print("\n");
}
public static void out(long[] a) {
for(int i=0;i<a.length;++i) System.out.print(a[i]+" ");
System.out.print("\n");
}
public static void out(int n) {
System.out.println(n);
}
public static void out(long n) {
System.out.println(n);
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | a96ed60563b9f694b7a04d0f6ab4224f | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
ADifferenceOperations solver = new ADifferenceOperations();
int testCount = Integer.parseInt(in.next());
for (int i = 1; i <= testCount; i++)
solver.solve(i, in, out);
out.close();
}
static class ADifferenceOperations {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt();
int[] arr = in.nextIntArray(n);
for (int i = 1; i < n; i++) {
if (arr[i] % arr[0] != 0) {
out.println("NO");
return;
}
}
out.println("YES");
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; ++i) array[i] = nextInt();
return array;
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 02ae9ab8f7436bc5db43d01a994c09b3 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/* Name of the class has to be "Main" only if the class is public. */
public class C
{
static short m_short = Short.MAX_VALUE;
static Scanner sc= new Scanner(System.in);
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
int t=sc.nextInt();
while(t-->0)
solve();
}
static final long modulo = 1000000007;
static int res=0;
static int mod = (int)Math.pow(10,9)+7;
// static int c[];
public static void solve() {
// DataInputStream ds= new DataInputStream(System.in);
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// long supreme = 100000;
int n=sc.nextInt();
int[] a = new int[n];
//String a =sc.next();
//String b=sc.next();
// char [][] a = new char[n][n];
// int[] b = new int[n+1];
// int[] b = new int[n+11];
HashMap<String,Integer> map = new HashMap<>();
int ans=-1;
for(int i=0;i<10;i++)
ans&=i;
int rs=1;
// List<Long> nn = new AanswertaskayList<>(n);
for(int x=-1;x>10;x+=5)
ans++;
// int ptr=n-1;
int z=3;
int sum=0;
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
sum+=a[i];
}
// Arrays.sort(a);
int currops=0;
boolean f=false;
for(int i=1;i<n;i++){
if(a[i]%a[0]!=0){
f=true;
break;
}
}
System.out.println((f)?"NO":"YES");
}
public static void swap(int[] a , int i ,int j){
int temp = a[i];
a[i]=a[j];
a[j]=temp;
}
public static int reverseN(int n){
int rev=0;
while(n>0){
rev = rev*10+n%10;
n/=10;
}
return rev;
}
public static boolean palin(char[] ch , int i ,int j){
while(i<=j){
if(ch[i]!=ch[j])
return false;
}
return true;
}
// public static void dfs(StringBuilder s,int[][] que,int i){
// if(i==que.length) return;
// s.append(s.substring(que[i][0]-1,que[i][1]));
// dfs(s,que,i+1);
// }
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 068e2fd99131f9e18d974ad21f5266c9 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class Tworivalstudents{
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
int t =sc.nextInt();
while(t>0){
int n=sc.nextInt();
int flag=0;
int[] a= new int[n];
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
for(int i=1;i<n;i++){
if(a[i]%a[0]!=0){
flag=1;
break;
}
}
if(flag==1)
System.out.println("NO");
else
System.out.println("YES");
t--;
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 732f0e394320a9df4e21720ff6486040 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class Codeforces {
public static void main(String[] args) {
try {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int[] a = new int[n];
for(int i = 0;i<n;i++){
a[i] = sc.nextInt();
}
int flag=0,init=a[0];
for(int i = 1;i<n;i++){
if(a[i]%init!=0){
flag=1;
break;
}
}
System.out.println(flag==1? "NO":"YES");
}
} catch (Exception e) {
System.out.println(e);
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 1352d275e72b99faa88c9f5ca1e3439a | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class Codeforces {
public static void main(String[] args) {
try {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int[] a = new int[n];
for(int i = 0;i<n;i++){
a[i] = sc.nextInt();
}
int flag=0;
for(int i = 1;i<n;i++){
if(a[i]%a[0]!=0){
flag=1;
break;
}
}
System.out.println(flag==0? "YES":"NO");
}
} catch (Exception e) {
System.out.println(e);
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 446b80cc34f5ef05f6bbf3327bb2c967 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | /******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int i,j,k;
for(j=0;j<n;j++)
{
int len = in.nextInt();
int[] arr = new int[len+1];
for(i=1;i<=len;i++)
{
arr[i] = in.nextInt();
}
for(i=2;i<=len;i++)
{
if(arr[i]%arr[1]!=0)
{
System.out.println("NO");
break;
}
}
if(i==len+1)
System.out.println("YES");
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | f0d9fe1e01985c42fae870a64e70559d | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class DifferenceOperations {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
if (st.hasMoreTokens()) {
str = st.nextToken("\n");
} else {
str = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader scanner = new FastReader();
int t = scanner.nextInt();
while(t-- > 0){
int n = scanner.nextInt();
int[] arr = new int[n];
boolean flag = true;
for(int i = 0; i < n; i++){
arr[i] = scanner.nextInt();
}
for(int i = 1; i < n; i++){
if(arr[i]%arr[0] != 0){
flag = false;
break;
}
}
if(flag) System.out.println("YES");
else System.out.println("NO");
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 1ce68241000f80445b6cbd66fe38389a | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | /* package codeforces; // don't place package name! */
// algo_messiah23 , NIT RKL ...
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import static java.lang.System.*;
import java.util.stream.IntStream;
import java.util.Map.Entry;
/* Name of the class has to be "Main" only if the class is public. */
public class CodeForces {
static PrintWriter out = new PrintWriter((System.out));
static FastReader in = new FastReader();
static int INF = Integer.MAX_VALUE;
static int NINF = Integer.MIN_VALUE;
public static void main(String[] args) throws java.lang.Exception {
// your code goes here
int t = i();
while (t-- > 0) {
solve();
}
out.close();
}
public static void solve() {
int n = i();
int a[] = input(n);
if (n == 2) {
if (a[1] % a[0] == 0)
out.println("YES");
else
out.println("NO");
} else {
int f = 0;
for (int i = 1; i < n; i++) {
if (a[i] % a[0] == 0)
continue;
else {
f = 1;
break;
}
}
if (f == 0)
out.println("YES");
else
out.println("NO");
}
}
static int[] input(int N) {
int[] A = new int[N];
for (int i = 0; i < N; i++)
A[i] = in.nextInt();
return A;
}
public static void print(int[] arr) {
int n = arr.length;
for (int i = 0; i < n; i++) {
out.print(arr[i] + " ");
}
out.println();
}
public static void sort(int[] arr) {
ArrayList<Integer> ls = new ArrayList<>();
for (int x : arr) {
ls.add(x);
}
Collections.sort(ls);
for (int i = 0; i < arr.length; i++) {
arr[i] = ls.get(i);
}
}
public static void reverse(int[] arr) {
int n = arr.length;
for (int i = 0; i < n / 2; i++) {
int temp = arr[i];
arr[i] = arr[n - 1 - i];
arr[n - 1 - i] = temp;
}
}
public static void reverse(long[] arr) {
int n = arr.length;
for (int i = 0; i < n / 2; i++) {
long temp = arr[i];
arr[i] = arr[n - 1 - i];
arr[n - 1 - i] = temp;
}
}
public static void print(ArrayList<Integer> arr) {
int n = arr.size();
for (int i = 0; i < n; i++) {
out.print(arr.get(i) + " ");
}
out.println();
}
static int i() {
return in.nextInt();
}
static long l() {
return in.nextLong();
}
static char ich() {
return in.next().charAt(0);
}
static String is() {
return in.next();
}
static String isl() {
return in.nextLine();
}
public static int max(int[] arr) {
int max = -1;
int n = arr.length;
for (int i = 0; i < n; i++)
max = Math.max(max, arr[i]);
return max;
}
public static int min(int[] arr) {
int min = INF;
int n = arr.length;
for (int i = 0; i < n; i++)
min = Math.min(min, arr[i]);
return min;
}
public static int gcd(int x, int y) {
if (y == 0) {
return x;
}
return gcd(y, x % y);
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 71a08bd125dfd435a43ff3348a3fc8ce | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc. nextInt();
while(t-->0){
int n = sc.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;i++){
arr[i]= sc.nextInt();
}
int flag =1;
int fir=arr[0];
for(int i=1;i<n;i++){
if((arr[i]%fir)!=0){
flag=0;
break;
}
}
if(flag==1)
System.out.println("YES");
else
System.out.println("NO");
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 56b497b0d5361c6204983aed4ab12bfb | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.*;
public class Competitive {
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-- > 0) {
int n = Integer.parseInt(br.readLine());
String[] in = br.readLine().split(" ");
boolean flag = true;
for(int i = 1; i < n; i++) {
if(Integer.parseInt(in[i])%Integer.parseInt(in[0]) != 0) {
flag = false;
break;
}
}
if(flag) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 8955d57d2b526d3387f0f93cbf5c18cd | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
public class DifferenceOperations {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- >0){
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int flag = 0;
for(int i = 1;i<=n-1;i++){
if(arr[i]%arr[0]!=0){
flag = 1;
break;
}
}
if(flag == 0){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 4f76e175b0eec76eb302bb21b8c6c738 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
public class A_Difference_Operations {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
for(int i = 0; i < t; i++){
boolean flag = true;
int n = s.nextInt();
long[] arr = new long[n];
for(int j = 0; j < n; j++){
arr[j] = s.nextLong();
}
for(int j = 1; j < n; j++){
if((arr[j])%(arr[0]) != 0){
flag = false;
}
}
if(flag){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
s.close();
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | cad017fe3545bb4d128634f2adf218aa | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
/*
* 11223456
*
*
*/
public class Codeforces {
public static void main(String[] args) {
FastReader fastReader = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = fastReader.nextInt();
while (t-- > 0) {
int n = fastReader.nextInt();
int a[] = fastReader.ria(n);
boolean ans = true;
for (int i = 1; i < n; i++) {
if (a[i] % a[0] != 0) {
ans = false;
break;
}
}
out.println(ans ? "YES" : "NO");
}
out.close();
}
// constants
static final int IBIG = 1000000007;
static final int IMAX = 2147483647;
static final long LMAX = 9223372036854775807L;
static Random __r = new Random();
// math util
static int minof(int a, int b, int c) {
return min(a, min(b, c));
}
static int minof(int... x) {
if (x.length == 1)
return x[0];
if (x.length == 2)
return min(x[0], x[1]);
if (x.length == 3)
return min(x[0], min(x[1], x[2]));
int min = x[0];
for (int i = 1; i < x.length; ++i)
if (x[i] < min)
min = x[i];
return min;
}
static long minof(long a, long b, long c) {
return min(a, min(b, c));
}
static long minof(long... x) {
if (x.length == 1)
return x[0];
if (x.length == 2)
return min(x[0], x[1]);
if (x.length == 3)
return min(x[0], min(x[1], x[2]));
long min = x[0];
for (int i = 1; i < x.length; ++i)
if (x[i] < min)
min = x[i];
return min;
}
static int maxof(int a, int b, int c) {
return max(a, max(b, c));
}
static int maxof(int... x) {
if (x.length == 1)
return x[0];
if (x.length == 2)
return max(x[0], x[1]);
if (x.length == 3)
return max(x[0], max(x[1], x[2]));
int max = x[0];
for (int i = 1; i < x.length; ++i)
if (x[i] > max)
max = x[i];
return max;
}
static long maxof(long a, long b, long c) {
return max(a, max(b, c));
}
static long maxof(long... x) {
if (x.length == 1)
return x[0];
if (x.length == 2)
return max(x[0], x[1]);
if (x.length == 3)
return max(x[0], max(x[1], x[2]));
long max = x[0];
for (int i = 1; i < x.length; ++i)
if (x[i] > max)
max = x[i];
return max;
}
static int powi(int a, int b) {
if (a == 0)
return 0;
int ans = 1;
while (b > 0) {
if ((b & 1) > 0)
ans *= a;
a *= a;
b >>= 1;
}
return ans;
}
static long powl(long a, int b) {
if (a == 0)
return 0;
long ans = 1;
while (b > 0) {
if ((b & 1) > 0)
ans *= a;
a *= a;
b >>= 1;
}
return ans;
}
static int fli(double d) {
return (int) d;
}
static int cei(double d) {
return (int) ceil(d);
}
static long fll(double d) {
return (long) d;
}
static long cel(double d) {
return (long) ceil(d);
}
static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
static int lcm(int a, int b) {
return (a / gcd(a, b)) * b;
}
static long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
static int[] exgcd(int a, int b) {
if (b == 0)
return new int[] { 1, 0 };
int[] y = exgcd(b, a % b);
return new int[] { y[1], y[0] - y[1] * (a / b) };
}
static long[] exgcd(long a, long b) {
if (b == 0)
return new long[] { 1, 0 };
long[] y = exgcd(b, a % b);
return new long[] { y[1], y[0] - y[1] * (a / b) };
}
static int randInt(int min, int max) {
return __r.nextInt(max - min + 1) + min;
}
static long mix(long x) {
x += 0x9e3779b97f4a7c15L;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L;
x = (x ^ (x >> 27)) * 0x94d049bb133111ebL;
return x ^ (x >> 31);
}
public static boolean[] findPrimes(int limit) {
assert limit >= 2;
final boolean[] nonPrimes = new boolean[limit];
nonPrimes[0] = true;
nonPrimes[1] = true;
int sqrt = (int) Math.sqrt(limit);
for (int i = 2; i <= sqrt; i++) {
if (nonPrimes[i])
continue;
for (int j = i; j < limit; j += i) {
if (!nonPrimes[j] && i != j)
nonPrimes[j] = true;
}
}
return nonPrimes;
}
// array util
static void reverse(int[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
int swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void reverse(long[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
long swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void reverse(double[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
double swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void reverse(char[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
char swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void shuffle(int[] a) {
int n = a.length - 1;
for (int i = 0; i < n; ++i) {
int ind = randInt(i, n);
int swap = a[i];
a[i] = a[ind];
a[ind] = swap;
}
}
static void shuffle(long[] a) {
int n = a.length - 1;
for (int i = 0; i < n; ++i) {
int ind = randInt(i, n);
long swap = a[i];
a[i] = a[ind];
a[ind] = swap;
}
}
static void shuffle(double[] a) {
int n = a.length - 1;
for (int i = 0; i < n; ++i) {
int ind = randInt(i, n);
double swap = a[i];
a[i] = a[ind];
a[ind] = swap;
}
}
static void rsort(int[] a) {
shuffle(a);
sort(a);
}
static void rsort(long[] a) {
shuffle(a);
sort(a);
}
static void rsort(double[] a) {
shuffle(a);
sort(a);
}
static int[] copy(int[] a) {
int[] ans = new int[a.length];
for (int i = 0; i < a.length; ++i)
ans[i] = a[i];
return ans;
}
static long[] copy(long[] a) {
long[] ans = new long[a.length];
for (int i = 0; i < a.length; ++i)
ans[i] = a[i];
return ans;
}
static double[] copy(double[] a) {
double[] ans = new double[a.length];
for (int i = 0; i < a.length; ++i)
ans[i] = a[i];
return ans;
}
static char[] copy(char[] a) {
char[] ans = new char[a.length];
for (int i = 0; i < a.length; ++i)
ans[i] = a[i];
return ans;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] ria(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = Integer.parseInt(next());
return a;
}
long nextLong() {
return Long.parseLong(next());
}
long[] rla(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = Long.parseLong(next());
return a;
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 91ee540be246f0e907788d40455e3058 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
int n = scanner.nextInt();
int[] nums = new int[n];
for (int j = 0; j < n; j++) {
nums[j] = scanner.nextInt();
}
if (satisfied(nums)) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
public static boolean satisfied(int[] nums) {
int n = nums.length, base = nums[0], pos = 0;
while (pos < n && base == 0) {
base = nums[pos++];
}
for (int i = pos; i < n; i++) {
if (nums[i] % base > 0) {
return false;
}
}
return true;
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 52d015066f16040212a1b00b3e864914 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
public class Solution{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while(t-- > 0){
int n = scanner.nextInt();
String check = "YES";
int[] arr = new int[n];
for(int i = 0 ; i < n ; i++){
arr[i] = scanner.nextInt();
if (arr[i] % arr[0] != 0) {
check = "NO";
}
}
System.out.println(check);
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | c930cb7bd0e57c486732fb3a7e1e92b3 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | /*
IF I HAD CHOICE, I WOULD HAVE BEEN A PIRATE, LOL XD ;
_____________#############
_____________##___________##
______________#____________#
_______________#____________#_##
_______________#__###############
_____##############______________#
_____##____________#_____################
______#______##############______________#
______##_____##___________#______________##
_______#______#____PARTH___#______________#
______##_______#___________##____________#
______###########__________##___________##
___________#_#_##________###_____########_____###
___________#_#_###########_#######_______#####__#########
######_____#_#______##_#_______#_#########___########
##___#########______##_#____#######________#####
__##________##################____##______###
____#____________________________##_#____##
_____#_____###_____##_____###_____###___##
______#___##_##___##_#____#_##__________#
______##____##_____###_____##__________##
________##___________________________##
___________#########################
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
static PrintWriter out = new PrintWriter(System.out);
static FastReader sc = new FastReader();
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args)
{
int tes = sc.nextInt();
while(tes-->0){
solve();
}
out.close();
}
private static void solve() {
int n = sc.nextInt();
int [] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i]=sc.nextInt();
}
for (int i = 1; i < n; i++) {
if (arr[i]%arr[0]!=0){
out.println("NO");
return;
}
}
out.println("YES");
}
}
/* Test case 0 :-
*/ | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 2cd844704f8420acc5e2974e0e412c71 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.OutputStream;
import java.io.BufferedOutputStream;
import java.util.*;
public class CodeForces_808 {
public static void main(String[] args)throws Exception{
FastScanner in = new FastScanner();OutputStream out = new BufferedOutputStream ( System.out );
int t=in.nextInt();
while (t-->0){
int n=in.nextInt();int[] a=new int[n];
for(int i=0;i<n;i++){
a[i]=in.nextInt();
}
boolean flag=true;
for(int i=1;i<n;i++){
if((a[i]%a[0])!=0){
flag=false;
break;
}
}
if(flag)
System.out.println("YES");
else
System.out.println("NO");
}
}
public static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 00968eea9566809ff8a5e5ae9163138e | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class Solution {
static class FastScanner {
private BufferedReader in;
private PrintWriter out;
private StringTokenizer tok = new StringTokenizer("");
public FastScanner() {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
String readString() throws IOException {
while (!tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
int readInt() throws IOException {
return Integer.parseInt(readString());
}
long readLong() throws IOException {
return Long.parseLong(readString());
}
double readDouble() throws IOException {
return Double.parseDouble(readString());
}
public void print(Object object) {
out.println(object);
}
public void print(Object[] arr) {
out.println(Arrays.toString(arr));
}
public void printMatrix(Object[][] matrix) {
int row = matrix.length, col = matrix[0].length;
for (int i = 0; i < row; ++i) {
for (int j = 0; j < col; ++j) {
out.print(matrix[i][j] + " ");
}
out.println();
}
}
public void preDestroy() {
try {
in.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) throws IOException {
Solution obj = new Solution();
FastScanner fastScanner = new FastScanner();
obj.solve(fastScanner, fastScanner.out);
fastScanner.preDestroy();
}
public void solve(FastScanner in, PrintWriter out) throws IOException {
int test = in.readInt();
while(test > 0) {
int n = in.readInt();
int[] arr = new int[n];
boolean flag = true;
for(int i = 0; i < n; ++ i) {
arr[i] = in.readInt();
}
if (arr[0] != 1) {
int end = 0;
for(int i = 1; i < n; ++ i) {
if ((arr[i] - arr[i - 1] == 1) || arr[i] == 1) {
end = i;
break;
}
}
end = end == 0 ? n - 1 : end;
for(int i = 1; i <= end; ++ i) {
if(arr[i] % arr[0] != 0) {
flag = false;
break;
}
}
}
out.println(flag ? "YES" : "NO");
--test;
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 9e7332eec9bc79e9f744988bf6205059 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.awt.image.AreaAveragingScaleFilter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class div8072 {
static class Pair implements Comparable<Pair>{
int val;
char ch;
int freq;
Pair(int val, char ch, int freq){
this.val = val;
this.ch = ch;
this.freq = freq;
}
@Override
public int compareTo(Pair o) {
return this.val - o.val;
}
}
public static void main(String[] args) {
FastScanner scn = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
try{
int t = scn.nextInt();
while(t-- > 0) {
int n = scn.nextInt();
int[] arr = new int[n];
for(int i =0;i<n;i++){
arr[i] =scn.nextInt();
}
boolean flag = true;
HashSet<Integer> hs = new HashSet<>();
int min = arr[0];
int smin = Integer.MAX_VALUE;
int sum = 0;
for(int i = 1;i<arr.length;i++){
// System.out.print(arr[i] + " " + arr[i-1]);
if(arr[i]%arr[0]!=0){
flag = false;
break;
}
}
// System.out.println();
if(flag){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
catch(Exception e){
return;
}
out.close();
}
static final Random random=new Random();
static final int mod=1_000_000_007;
static void ruffleSort(int[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static long add(long a, long b) {
return (a+b)%mod;
}
static long sub(long a, long b) {
return ((a-b)%mod+mod)%mod;
}
static long mul(long a, long b) {
return (a*b)%mod;
}
static long exp(long base, long exp) {
if (exp==0) return 1;
long half=exp(base, exp/2);
if (exp%2==0) return mul(half, half);
return mul(half, mul(half, base));
}
static long[] factorials=new long[2_000_001];
static long[] invFactorials=new long[2_000_001];
static void precompFacts() {
factorials[0]=invFactorials[0]=1;
for (int i=1; i<factorials.length; i++) factorials[i]=mul(factorials[i-1], i);
invFactorials[factorials.length-1]=exp(factorials[factorials.length-1], mod-2);
for (int i=invFactorials.length-2; i>=0; i--)
invFactorials[i]=mul(invFactorials[i+1], i+1);
}
static long nCk(int n, int k) {
return mul(factorials[n], mul(invFactorials[k], invFactorials[n-k]));
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 60ba57ec0473826246a885fd5b67eec1 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int A = scn.nextInt();
StringBuilder sb = new StringBuilder("");
while(A-- > 0) {
int n = scn.nextInt();
int[] arr = new int[n];
for(int i=0 ; i<n ; i++) {
arr[i] = scn.nextInt();
}
String ans = "YES";
for(int i=1 ; i<n ; i++) {
if(arr[i] % arr[i - 1] == 0) {
arr[i] = arr[i-1];
}else {
ans = "NO";
break;
}
}
sb.append(ans + "\n");
}
System.out.println(sb);
}
// public static int gcd(int a, int b) {
// if (b == 0)
// return a;
// return gcd(b, a % b);
// }
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | e7b6196456acb276633967939fce74ae | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.*;
import java.util.*;
public class _cf {
public static void main (String[] args) { new _cf(); }
public _cf() {
Scanner s = new Scanner();
PrintWriter out = new PrintWriter(System.out);
int T = s.nextInt();
while(T-- > 0) {
int n = s.nextInt();
int[] a = new int[n];
boolean possible = true;
for(int i = 0; i < n; i++) {
a[i] = s.nextInt();
if (a[i] % a[0] != 0) possible = false;
}
if(possible) out.println("YES");
else out.println("NO");
}
out.close();
}
class Scanner {
public int BS = 1<<16;
public char NC = (char)0;
byte[] buf = new byte[BS];
int bId = 0, size = 0;
char c = NC;
double num = 1;
BufferedInputStream in;
public Scanner() {
in = new BufferedInputStream(System.in, BS);
}
public Scanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
}
catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
public char nextChar(){
while(bId==size) {
try {
size = in.read(buf);
}catch(Exception e) {
return NC;
}
if(size==-1)return NC;
bId=0;
}
return (char)buf[bId++];
}
public int nextInt() {
return (int)nextLong();
}
public long nextLong() {
num=1;
boolean neg = false;
if(c==NC)c=nextChar();
for(;(c<'0' || c>'9'); c = nextChar()) {
if(c=='-')neg=true;
}
long res = 0;
for(; c>='0' && c <='9'; c=nextChar()) {
res = (res<<3)+(res<<1)+c-'0';
num*=10;
}
return neg?-res:res;
}
public double nextDouble() {
double cur = nextLong();
return c!='.' ? cur:cur+nextLong()/num;
}
public String next() {
StringBuilder res = new StringBuilder();
while(c<=32)c=nextChar();
while(c>32) {
res.append(c);
c=nextChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while(c<=32)c=nextChar();
while(c!='\n') {
res.append(c);
c=nextChar();
}
return res.toString();
}
public boolean hasNext() {
if(c>32)return true;
while(true) {
c=nextChar();
if(c==NC)return false;
else if(c>32)return true;
}
}
public int[] nextIntArray(int n) {
int[] res = new int[n];
for(int i = 0; i < n; i++) res[i] = nextInt();
return res;
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 723d1f50f08cb03559df5546a74723a6 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.*;
import java.util.*;
public class CODE {
public static void main(String[] args) {
try {
System.setIn(new FileInputStream("input.txt"));
System.setOut(new PrintStream(new FileOutputStream("output.txt")));
} catch (Exception e) {
System.err.println("Error");
}
FastReader scn = new FastReader();
int np = scn.nextInt();
for (int l = 0; l < np; l++) {
int n = scn.nextInt();
long[] ar = new long[n];
boolean f = true;
for (int i = 0; i < n; i++) {
ar[i] = scn.nextLong();
}
for (int i = 1; i < n; i++) {
if (ar[i] % ar[0] != 0) {
f = false;
break;
}
}
if (f) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | b12c7987e7058911a4359c0406a54744 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes |
import java.io.*;
import java.util.*;
public class A {
static FastScanner scan = new FastScanner();
static Scanner scanner = new Scanner(System.in);
static PrintWriter printWriter = new PrintWriter(System.out);
static long MOD = 998244353;
static long MOD2 = MOD * MOD;
static int positiveInf = Integer.MAX_VALUE;
static int negativeInf = Integer.MIN_VALUE;
static long ded = (long) (1e17) + 9;
static long end = Long.MAX_VALUE;
public static void main(String[] args) {
int t = scan.nextInt();
while (t-- > 0) {
solve();
}
printWriter.close();
scanner.close();
}
public static void solve(){
int n = scan.nextInt();
int[] arr = new int[n];
int max = 0;
Set<Integer> set = new HashSet<>();
for(int i =0;i<arr.length;i++){
arr[i]= scan.nextInt();
max = Math.max(arr[i],max);
set.add(arr[i]);
}
if(set.size()==1){
printWriter.println("YES");
return;
}
boolean div = true;
int a =arr[0];
for(int i =1;i<arr.length;i++){
if(arr[i] % a !=0){
div=false;
break;
}
}
if(div){
printWriter.println("YES");
}
else{
printWriter.println("NO");
}
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L) return 19;
if (l >= 100000000000000000L) return 18;
if (l >= 10000000000000000L) return 17;
if (l >= 1000000000000000L) return 16;
if (l >= 100000000000000L) return 15;
if (l >= 10000000000000L) return 14;
if (l >= 1000000000000L) return 13;
if (l >= 100000000000L) return 12;
if (l >= 10000000000L) return 11;
if (l >= 1000000000L) return 10;
if (l >= 100000000L) return 9;
if (l >= 10000000L) return 8;
if (l >= 1000000L) return 7;
if (l >= 100000L) return 6;
if (l >= 10000L) return 5;
if (l >= 1000L) return 4;
if (l >= 100L) return 3;
if (l >= 10L) return 2;
return 1;
}
public static void yes(){
printWriter.println("YES");
}
public static void no(){
printWriter.println("NO");
}
static class Pair implements Comparable<Pair> {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o){
if(this.y==o.y){
return this.x-o.x;
}
return this.y-o.y;
}
}
public static long mul(long a, long b) {
return ((a % MOD) * (b % MOD)) % MOD;
}
public static long add(long a, long b) {
return ((a % MOD) + (b % MOD)) % MOD;
}
public static long c2(long n) {
if ((n & 1) == 0) {
return mul(n / 2, n - 1);
} else {
return mul(n, (n - 1) / 2);
}
}
//Shuffle Sort
static final Random random = new Random();
static void ruffleSort(int[] a) {
int n = a.length;//shuffle, then sort
for (int i = 0; i < n; i++) {
int oi = random.nextInt(n); int temp= a[oi];
a[oi] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
//Brian Kernighan's Algorithm
static long countSetBits(long n) {
if (n == 0) return 0;
return 1 + countSetBits(n & (n - 1));
}
//Euclidean Algorithm
static long gcd(long A, long B) {
if (B == 0) return A;
return gcd(B, A % B);
}
//Modular Exponentiation
static long fastExpo(long x, long n) {
if (n == 0) return 1;
if ((n & 1) == 0) return fastExpo((x * x) % MOD, n / 2) % MOD;
return ((x % MOD) * fastExpo((x * x) % MOD, (n - 1) / 2)) % MOD;
}
//AKS Algorithm
static boolean isPrime(long n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i <= Math.sqrt(n); i += 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
public static long modinv(long x) {
return modpow(x, MOD - 2);
}
public static long modpow(long a, long b) {
if (b == 0) {
return 1;
}
long x = modpow(a, b / 2);
x = (x * x) % MOD;
if (b % 2 == 1) {
return (x * a) % MOD;
}
return x;
}
public static boolean isInteger(int n) {
return Math.sqrt(n) % 1 == 0;
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | bda9b1fdb0c15a6803e621aa003a69d2 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
public static void main (String[] args) throws java.lang.Exception {
Scanner scn = new Scanner(System.in);
int tc = scn.nextInt();
while (tc != 0) {
int n = scn.nextInt();
int[] arr = new int[n];
for (int i = 0 ; i < n ; i++) {
arr[i] = scn.nextInt();
}
solve(n, arr);
tc--;
}
}
public static void solve(int n, int[] arr) {
for (int i = 1 ; i < n ; i++) {
if (arr[i] % arr[0] != 0) {
System.out.println("NO");
return;
}
}
System.out.println("YES");
return;
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 31d80885abc256a5b544f2d9b9ef5282 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static class pair{
int x;
int y;
pair(int x1,int y1){
x=x1;
y=y1;
}
}
static FastReader in=new FastReader();
static final Random random=new Random();
static long mod=1000000007L;
static HashMap<String,Integer>map=new HashMap<>();
public static void main(String args[]) throws IOException {
int t=in.nextInt();
while(t-->0){
int n=in.nextInt();
int arr[]=in.readintarray(n);
int ind=arr[0];
boolean flag=false;
for(int i=1;i<n;i++){
if(arr[i]%ind!=0){
flag=true;
break;
}
}
if(flag){
print("NO");
}
else{
print("YES");
}
}
}
static int max(int a, int b)
{
if(a<b)
return b;
return a;
}
static void ruffleSort(int[] a) {
int n=a.length;
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static < E > void print(E res)
{
System.out.println(res);
}
static int gcd(int a,int b)
{
if(b==0)
{
return a;
}
return gcd(b,a%b);
}
static int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
static int abs(int a)
{
if(a<0)
return -1*a;
return a;
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
int [] readintarray(int n) {
int res [] = new int [n];
for(int i = 0; i<n; i++)res[i] = nextInt();
return res;
}
long [] readlongarray(int n) {
long res [] = new long [n];
for(int i = 0; i<n; i++)res[i] = nextLong();
return res;
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | cdd83a8535cb01f378952abe79b08180 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
//static int mod = 998244353;
static int mod = (int)1e9+7;
static boolean[] prime = new boolean[1];
static int[][] dir1 = new int[][]{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
static int[][] dir2 = new int[][]{{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
static int inf = 0x3f3f3f3f;
static {
for (int i = 2; i < prime.length; i++)
prime[i] = true;
for (int i = 2; i < prime.length; i++) {
if (prime[i]) {
for (int k = 2; i * k < prime.length; k++) {
prime[i * k] = false;
}
}
}
}
static class JoinSet {
int[] fa;
JoinSet(int n) {
fa = new int[n];
for (int i = 0; i < n; i++)
fa[i] = i;
}
int find(int t) {
if (t != fa[t])
fa[t] = find(fa[t]);
return fa[t];
}
void join(int x, int y) {
x = find(x);
y = find(y);
fa[x] = y;
}
}
static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
static long lcm(long a, long b) {
return a * b / gcd(a, b);
}
static int get() throws Exception {
String ss = bf.readLine();
if (ss.contains(" "))
ss = ss.substring(0, ss.indexOf(" "));
return Integer.parseInt(ss);
}
static long getx() throws Exception {
String ss = bf.readLine();
if (ss.contains(" "))
ss = ss.substring(0, ss.indexOf(" "));
return Long.parseLong(ss);
}
static int[] getint() throws Exception {
String[] s = bf.readLine().split(" ");
int[] a = new int[s.length];
for (int i = 0; i < a.length; i++) {
a[i] = Integer.parseInt(s[i]);
}
return a;
}
static long[] getlong() throws Exception {
String[] s = bf.readLine().split(" ");
long[] a = new long[s.length];
for (int i = 0; i < a.length; i++) {
a[i] = Long.parseLong(s[i]);
}
return a;
}
static char[] getstr() throws Exception {
return bf.readLine().toCharArray();
}
static void println() throws Exception {
bw.write("\n");
}
static void print(int a) throws Exception {
bw.write(a + "\n");
}
static void print(long a) throws Exception {
bw.write(a + "\n");
}
static void print(String a) throws Exception {
bw.write(a + "\n");
}
static void print(int[] a) throws Exception {
for (int i : a) {
bw.write(i + " ");
}
println();
}
static void print(long[] a) throws Exception {
for (long i : a) {
bw.write(i + " ");
}
println();
}
static void print(int[][] a) throws Exception {
for (int i[] : a)
print(i);
}
static void print(long[][] a) throws Exception {
for (long[] i : a)
print(i);
}
static void print(char[] a) throws Exception {
for (char i : a) {
bw.write(i + "");
}
println();
}
static long pow(long a, long b) {
long ans = 1;
while (b > 0) {
if ((b & 1) == 1) {
ans *= a;
}
a *= a;
b >>= 1;
}
return ans;
}
static int powmod(long a, long b, int mod) {
long ans = 1;
while (b > 0) {
if ((b & 1) == 1) {
ans = ans * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return (int) ans;
}
static void sort(int[] a) {
int n = a.length;
Integer[] b = new Integer[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[i];
}
static void sort(long[] a) {
int n = a.length;
Long[] b = new Long[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[i];
}
static void resort(int[] a) {
int n = a.length;
Integer[] b = new Integer[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[n - 1 - i];
}
static void resort(long[] a) {
int n = a.length;
Long[] b = new Long[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[n - 1 - i];
}
static int max(int a, int b) {
return Math.max(a, b);
}
static int min(int a, int b) {
return Math.min(a, b);
}
static long max(long a, long b) {
return Math.max(a, b);
}
static long min(long a, long b) {
return Math.min(a, b);
}
static int max(int[] a) {
int max = a[0];
for (int i : a)
max = max(max, i);
return max;
}
static int min(int[] a) {
int min = a[0];
for (int i : a)
min = min(min, i);
return min;
}
static long max(long[] a) {
long max = a[0];
for (long i : a)
max = max(max, i);
return max;
}
static long min(long[] a) {
long min = a[0];
for (long i : a)
min = min(min, i);
return min;
}
static int abs(int a) {
return Math.abs(a);
}
static long abs(long a) {
return Math.abs(a);
}
static void yes() throws Exception {
print("Yes");
}
static void no() throws Exception {
print("No");
}
static int[] getarr(List<Integer> list) {
int n = list.size();
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = list.get(i);
return a;
}
static List<Integer>[] lists;
static class LCA{
int[] dep;
int[][] fa;
int[] log;
boolean[] v;
public LCA(int n){
dep = new int[n+5];
log = new int[n+5];
fa = new int[n+5][31];
v = new boolean[n+5];
for (int i = 2; i <= n; ++i) {
log[i] = log[i/2] + 1;
}
dfs(1,0);
}
private void dfs(int cur, int pre){
if(v[cur]) return;
v[cur] = true;
dep[cur] = dep[pre]+1;
fa[cur][0] = pre;
for (int i = 1; i <= log[dep[cur]]; ++i) {
fa[cur][i] = fa[fa[cur][i - 1]][i - 1];
}
for(int i : lists[cur]){
dfs(i,cur);
}
}
private int lca(int a, int b){
if(dep[a] > dep[b]){
int t = a;
a = b;
b = t;
}
while (dep[a] != dep[b]){
b = fa[b][log[dep[b] - dep[a]]];
}
if(a == b) return a;
for (int k = log[dep[a]]; k >= 0; k--) {
if (fa[a][k] != fa[b][k]) {
a = fa[a][k]; b = fa[b][k];
}
}
return fa[a][0];
}
}
public static void main(String[] args) throws Exception {
int T = 1;
T = get();
f:while (T-- > 0) {
int n = get();
int a[] = getint();
for(int i = 1;i < n;i++){
if(a[i]%a[0] != 0) {
no();
continue f;
}
}
yes();
}
bw.flush();
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | b266950423e3005d5fd45e28ed01ca47 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | // LARGEST SQUARE
// package com.company
/*
* @author :: Yuvraj Singh
* CS UNDERGRAD AT IT GGV BILASPUR
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import static java.lang.Math.*;
import static java.lang.System.out;
public class Main {
// Solution here
ArrayList<Pair> arr;
void solve(int t) {
int n= in.nextInt();
long ans = 0;
long[] arr= longArr(n);
boolean f= true;
for(int i=1; i<n; i++){
if(arr[i] % arr[0] != 0){
f= false;
}
}
if(f){
sb.append("YES");
}else
sb.append("NO");
sb.append("\n");
}
void start(){
sb= new StringBuffer();
int t= in.nextInt();
for(int i=1;i<=t;i++) {
solve(i);
}
out.print(sb);
}
// Starter Code
FastReader in;
StringBuffer sb;
public static void main(String[] args) {
new Main().run();
}
void run(){
in= new FastReader();
start();
}
void bubbleSort(int[] arr){
int n= arr.length;
for(int i=n-1; i>0; i--){
for(int j=0; j<i; j++){
if(arr[i] < arr[j]){
swap(arr, i, j);
}
}
}
}
void swap(int[] arr, int i, int j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
long numberOfWays(long n, long k) {
// Base Cases
if (n == 0)
return 1;
if (k == 0)
return 1;
if (n >= (int)Math.pow(2, k)) {
int curr_val = (int)Math.pow(2, k);
return numberOfWays(n - curr_val, k)
+ numberOfWays(n, k - 1);
}
else
return numberOfWays(n, k - 1);
}
boolean palindrome(String s){
int i=0, j= s.length()-1;
while(i<j){
if(s.charAt(i)!=s.charAt(j)) return false;
i++; j--;
}
return true;
}
int call(int[] A, int N, int K) {
int i = 0, j = 0, sum = 0;
int maxLen = Integer.MIN_VALUE;
while (j < N) {
sum += A[j];
if (sum < K) {
j++;
}
else if (sum == K) {
maxLen = Math.max(maxLen, j-i+1);
j++;
}
else if (sum > K) {
while (sum > K) {
sum -= A[i];
i++;
}
if(sum == K){
maxLen = Math.max(maxLen, j-i+1);
}
j++;
}
}
return maxLen;
}
int largestNum(int n)
{
int num = 0;
// Iterate through all possible values
for (int i = 0; i <= 32; i++)
{
// Multiply the number by 2 i times
int x = (1 << i);
if ((x - 1) >= n)
num = (1 << i) - 1;
else
break;
}
// Return the final result
return num;
}
static boolean isPrime(int n)
{
// Corner case
if (n <= 1)
return false;
// Check from 2 to n-1
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
// Useful Functions
void swap( int i , int j) {
int tmp = i;
i = j;
j = tmp;
}
int call(int i,int j, int[][] mat, int[][] dp){
int m= mat.length;
int n= mat[0].length;
if(i>=m || j>=n){
return Integer.MIN_VALUE;
}
if(i==m-1 && j==n-1){
return mat[i][j];
}
if(dp[i][j] != -1){
return dp[i][j];
}
return dp[i][j] = max(call(i+1, j, mat, dp), call(i, j+1, mat, dp)) + mat[i][j];
}
int util(int i,int j, int[][] mat, int[][] dp){
int m= mat.length;
int n= mat[0].length;
if(i>=m || j>=n){
return Integer.MAX_VALUE;
}
if(i==m-1 && j==n-1){
return mat[i][j];
}
if(dp[i][j] != -1){
return dp[i][j];
}
return dp[i][j] = min(util(i+1, j, mat, dp), util(i, j+1, mat, dp)) + mat[i][j];
}
long power(long x, long y, long p) {
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int lower_bound(long[] a, long x) { // x is the target value or key
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]>=x) r=m;
else l=m;
}
return r;
}
int upper_bound(long[] arr, int key) {
int i=0, j=arr.length-1;
if (arr[j]<=key) return j+1;
if(arr[i]>key) return i;
while (i<j){
int mid= (i+j)/2;
if(arr[mid]<=key){
i= mid+1;
}else{
j=mid;
}
}
return i;
}
void sort(long[] A){
int n = A.length;
Random rnd = new Random();
for(int i=0; i<n; ++i){
long tmp = A[i];
int randomPos = i + rnd.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
int[] intArr(int n){
int[] res= new int[n];
for(int i=0;i<n;i++){
res[i]= in.nextInt();
}
return res;
}
long[] longArr(int n){
long[] res= new long[n];
for(int i=0;i<n;i++){
res[i]= in.nextLong();
}
return res;
}
// // sieve of eratosthenes code for precomputing whether numbers are prime or not up to MAX_VALUE
long MAX= 100000000;
int[] precomp;
void sieve(){
long n= MAX;
precomp = new int[(int) (n+1)];
boolean[] prime = new boolean[(int) (n+1)];
for(int i=0;i<=n;i++)
prime[i] = true;
for(long p = 2; p*p <=n; p++)
{
// If prime[p] is not changed, then it is a prime
if(prime[(int) p])
{
// Update all multiples of p
for(long i = p*p; i <= n; i += p)
prime[(int) i] = false;
}
}
// Print all prime numbers
for(long i = 2; i <= n; i++)
{
if(prime[(int) i])
precomp[(int) i]= 1;
}
}
long REVERSE(long N) {
// code here
long rev=0;
long org= N;
while (N!=0){
long d= N%10;
rev = rev*10 +d;
N /= 10;
}
return rev;
}
long sumOfDigits(String n){
long sum= 0;
for (char c: n.toCharArray()){
sum += Integer.parseInt(String.valueOf(c));
}
return sum;
}
long[] revArray(long[] arr) {
int n= arr.length;
int i=0, j=n-1;
while (i<j){
long temp= arr[i];
arr[i]= arr[j];
arr[j]= temp;
i++;
j--;
}
return arr;
}
long gcd(long a, long b){
if (b==0)
return a;
return gcd(b, a%b);
}
long lcm(long a,long b){
return (a*b)/gcd(a,b);
}
static class Pair implements Comparable<Pair>{
long first;
long second;
Pair(long x, long y){
this.first=x;
this.second=y;
}
@Override
public int compareTo(Pair o) {
return 0;
}
}
// static class Compare {
// static void compare(ArrayList<Pair> arr, int n) {
// arr.sort(new Comparator<Pair>() {
// @Override
// public int compare(Pair p1, Pair p2) {
// return (int) (p2.first - p1.first);
// }
// });
// }
// }
public static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while (st==null || !st.hasMoreElements()){
try{
st=new StringTokenizer(br.readLine());
}catch (Exception e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
float nextFloat(){
return Float.parseFloat(next());
}
String nextLine(){
String str="";
try{
str=br.readLine();
}catch (Exception e){
e.printStackTrace();
}
return str;
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | bcec05c7d801dd08bb879a0cf6f2b88b | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes |
import java.util.*;
public class CodeForces {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int[] a=new int[n];
boolean flag=true;
for (int i = 0; i < n; i++){
a[i]= sc.nextInt();
}
for (int i = 1; i < n; i++) {
if(a[i]%a[0]!=0){
flag=false;
break;
}
}
if (!flag) System.out.println("NO");
else System.out.println("YES");
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | b5f3e83a7b302f2ae70c9f1a30e4ebaa | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.awt.image.AreaAveragingScaleFilter;
import java.io.*;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.*;
public class Pratice {
static final long mod = 1000000007;
static StringBuilder sb = new StringBuilder();
static int xn = (int) (2e5 + 10);
static long ans;
static boolean prime[] = new boolean[1000001];
// calculate sqrt and cuberoot
// static Set<Long> set=new TreeSet<>();
// static
// {
// long n=1000000001;
//
//
// for(int i=1;i*i<=n;i++)
// {
// long x=i*i;
// set.add(x);
// }
// for(int i=1;i*i*i<=n;i++)
// {
// long x=i*i*i;
// set.add(x);
// }
// }
static void sieveOfEratosthenes() {
for (int i = 0; i <= 1000000; i++)
prime[i] = true;
prime[0] = false;
prime[1] = false;
for (int p = 2; p * p <= 1000000; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= 1000000; i += p)
prime[i] = false;
}
}
}
public static void main(String[] args) throws IOException {
Reader reader = new Reader();
int t = reader.nextInt();
while (t-- > 0) {
int n=reader.nextInt();
long arr[]=new long[n];
for (int i = 0; i <n; i++) {
arr[i] = reader.nextLong();
}
boolean flag=false;
for(int i=1;i<n;i++)
{
if(arr[i]%arr[0]!=0)
{
flag=true;
}
}
if (flag)
System.out.println("No");
else
System.out.println("Yes");
}
}
// }
// static void SieveOfEratosthenes(int n, boolean prime[],
// boolean primesquare[], int a[])
// {
// // Create a boolean array "prime[0..n]" and
// // initialize all entries it as true. A value
// // in prime[i] will finally be false if i is
// // Not a prime, else true.
// for (int i = 2; i <= n; i++)
// prime[i] = true;
//
// /* Create a boolean array "primesquare[0..n*n+1]"
// and initialize all entries it as false.
// A value in squareprime[i] will finally
// be true if i is square of prime,
// else false.*/
// for (int i = 0; i < ((n * n) + 1); i++)
// primesquare[i] = false;
//
// // 1 is not a prime number
// prime[1] = false;
//
// for (int p = 2; p * p <= n; p++) {
// // If prime[p] is not changed,
// // then it is a prime
// if (prime[p] == true) {
// // Update all multiples of p
// for (int i = p * 2; i <= n; i += p)
// prime[i] = false;
// }
// }
//
// int j = 0;
// for (int p = 2; p <= n; p++) {
// if (prime[p]) {
//
// a[j] = p;
//
//
// primesquare[p * p] = true;
// j++;
// }
// }
// }
//
//
// static int countDivisors(int n)
// {
//
// if (n == 1)
// return 1;
//
// boolean prime[] = new boolean[n + 1];
// boolean primesquare[] = new boolean[(n * n) + 1];
//
// int a[] = new int[n];
//
//
// SieveOfEratosthenes(n, prime, primesquare, a);
//
//
// int ans = 1;
//
// // Loop for counting factors of n
// for (int i = 0;; i++) {
// // a[i] is not less than cube root n
// if (a[i] * a[i] * a[i] > n)
// break;
//
// int cnt = 1;
//
// // if a[i] is a factor of n
// while (n % a[i] == 0) {
// n = n / a[i];
//
// // incrementing power
// cnt = cnt + 1;
// }
//
//
// ans = ans * cnt;
// }
//
//
// if (prime[n])
// ans = ans * 2;
//
// // Second case
// else if (primesquare[n])
// ans = ans * 3;
//
// // Third case
// else if (n != 1)
// ans = ans * 4;
//
// return ans; // Total divisors
// }
public static long[] inarr(long n) throws IOException {
Reader reader = new Reader();
long arr[]=new long[(int) n];
for (long i = 0; i < n; i++) {
arr[(int) i]=reader.nextLong();
}
return arr;
}
public static boolean checkPerfectSquare(int number)
{
int x=number % 10;
if (x==2 || x==3 || x==7 || x==8)
{
return false;
}
for (int i=0; i<=number/2 + 1; i++)
{
if (i*i==number)
{
return true;
}
}
return false;
}
// check number is prime or not
public static boolean isPrime(int n) {
return BigInteger.valueOf(n).isProbablePrime(1);
}
// return the gcd of two numbers
public static long gcd(long a, long b)
{
BigInteger b1 = BigInteger.valueOf(a);
BigInteger b2 = BigInteger.valueOf(b);
BigInteger gcd = b1.gcd(b2);
return gcd.longValue();
}
// return lcm of number
static long lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
// number of digits in the given number
public static long numberOfDigits(long n)
{
long ans= (long) (Math.floor((Math.log10(n)))+1);
return ans;
}
// return most significant bit in the number
public static long mostSignificantNumber(long n)
{
double k=Math.log10(n);
k=k-Math.floor(k);
int ans=(int)Math.pow(10,k);
return ans;
}
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | c88d88405f46921eeb057bf7f7c7e2df | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class ReduceToZero {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for( int i=0; i < t; i++){
int n = sc.nextInt();
sc.nextLine();
String[] val = sc.nextLine().split(" ");
int[] nums = new int[n];
for( int j=0; j < n; j++){
nums[j] = Integer.parseInt( val[j]);
}
process( nums);
}
sc.close();
}
public static void process( int[] nums){
int n= nums.length;
boolean flag1 = true;
for( int i=1; i < n; i++ ){
boolean flag2 = false;
for( int j=0; j < i; j++){
if( nums[j] <= nums[i] && nums[i] % nums[j] == 0 )
flag2 = true;
}
if( flag2 == false)
flag1 = false;
}
if( flag1 == true)
System.out.println("YES");
else
System.out.println("NO");
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 6184f44c6ec73ac39dfb75c74324cf76 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
sc.nextLine();
String[] values = sc.nextLine().split(" ");
int[] arr = new int[n];
int j = 0;
for (String val : values) {
arr[j++] = Integer.parseInt(val);
}
System.out.println(solve(arr));
}
sc.close();
}
public static String solve(int[] numbers) {
for (int i = 1; i < numbers.length; i++) {
if (numbers[i] % numbers[0] != 0)
return "NO";
}
return "YES";
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | b5990c40cc19202ecf4e54a94f0370b0 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class ReduceToZero {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for( int i=0; i < t; i++){
int n = sc.nextInt();
sc.nextLine();
String[] val = sc.nextLine().split(" ");
int[] nums = new int[n];
for( int j=0; j < n; j++){
nums[j] = Integer.parseInt( val[j]);
}
process( nums);
}
sc.close();
}
public static void process( int[] nums){
int n= nums.length;
boolean flag1 = true;
for( int i=1; i < n; i++ ){
boolean flag2 = false;
for( int j=0; j < i; j++){
if( nums[j] <= nums[i] && nums[i] % nums[j] == 0 )
flag2 = true;
}
if( flag2 == false)
flag1 = false;
}
if( flag1 == true)
System.out.println("YES");
else
System.out.println("NO");
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | f4139b9d094edf0d1f3c38a27dec36cf | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int tc = sc.nextInt();
for(int i = 0; i < tc; i++)
{
int n = sc.nextInt();
int arr[] = new int[n];
for(int j = 0; j < n; j++)
{
arr[j] = sc.nextInt();
}
int elem = arr[0];
boolean flag = false;
for(int j = 1; j < n; j++)
{
if(arr[j] % elem != 0)
{
flag =true;
break;
}
}
if(flag)
{
System.out.println("NO");
}
else
{
System.out.println("YES");
}
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 67a7fc0875074559e58aa9334ed184df | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes |
import java.io.*;
import java.math.*;
import java.util.*;
public class A_Difference_Operations
{
public static void main(String[] args)throws Exception
{
new Solver().solve();
}
}
//* Success is not final, failure is not fatal: it is the courage to continue that counts.
class Solver {
void solve() throws Exception
{
int t = sc.nextInt();
while(t-->0){
int n =sc.nextInt();
long[] arr = sc.getLongArray(n);
boolean isPos = true;
for(int i = 1;i<n;i++){
long diff= sc.gcd(arr[i],arr[i-1]);
if(diff<0 || diff%arr[0]!=0){
isPos = false;
break;
}
}
System.out.println(isPos?"YES":"NO");
}
sc.flush();
}
final Helper sc;
final int MAXN = 1000_006;
final long MOD = (long) 1e9 + 7;
Solver() {
sc = new Helper(MOD, MAXN);
sc.initIO(System.in, System.out);
}
}
class Helper {
final long MOD;
final int MAXN;
final Random rnd;
public Helper(long mod, int maxn) {
MOD = mod;
MAXN = maxn;
rnd = new Random();
}
public static int[] sieve;
public static ArrayList<Integer> primes;
public void setSieve() {
primes = new ArrayList<>();
sieve = new int[MAXN];
int i, j;
for (i = 2; i*i < MAXN; ++i)
if (sieve[i] == 0) {
primes.add(i);
for (j = i*i; j < MAXN; j += i) {
sieve[j] = i;
}
}
}
public static long[] factorial;
public void setFactorial() {
factorial = new long[MAXN];
factorial[0] = 1;
for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD;
}
public long getFactorial(int n) {
if (factorial == null) setFactorial();
return factorial[n];
}
public long ncr(int n, int r) {
if (r > n) return 0;
if (factorial == null) setFactorial();
long numerator = factorial[n];
long denominator = factorial[r] * factorial[n - r] % MOD;
return numerator * pow(denominator, MOD - 2, MOD) % MOD;
}
public long[] getLongArray(int size) throws Exception {
long[] ar = new long[size];
for (int i = 0; i < size; ++i) ar[i] = nextLong();
return ar;
}
public int[] getIntArray(int size) throws Exception {
int[] ar = new int[size];
for (int i = 0; i < size; ++i) ar[i] = nextInt();
return ar;
}
public long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
public int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
public long max(long[] ar) {
long ret = ar[0];
for (long itr : ar) ret = Math.max(ret, itr);
return ret;
}
public int max(int[] ar) {
int ret = ar[0];
for (int itr : ar) ret = Math.max(ret, itr);
return ret;
}
public long min(long[] ar) {
long ret = ar[0];
for (long itr : ar) ret = Math.min(ret, itr);
return ret;
}
public int min(int[] ar) {
int ret = ar[0];
for (int itr : ar) ret = Math.min(ret, itr);
return ret;
}
public long sum(long[] ar) {
long sum = 0;
for (long itr : ar) sum += itr;
return sum;
}
public long sum(int[] ar) {
long sum = 0;
for (int itr : ar) sum += itr;
return sum;
}
public void shuffle(int[] ar) {
int r;
for (int i = 0; i < ar.length; ++i) {
r = rnd.nextInt(ar.length);
if (r != i) {
ar[i] ^= ar[r];
ar[r] ^= ar[i];
ar[i] ^= ar[r];
}
}
}
public void shuffle(long[] ar) {
int r;
for (int i = 0; i < ar.length; ++i) {
r = rnd.nextInt(ar.length);
if (r != i) {
ar[i] ^= ar[r];
ar[r] ^= ar[i];
ar[i] ^= ar[r];
}
}
}
public long pow(long base, long exp, long MOD) {
base %= MOD;
long ret = 1;
while (exp > 0) {
if ((exp & 1) == 1) ret = ret * base % MOD;
base = base * base % MOD;
exp >>= 1;
}
return ret;
}
static byte[] buf = new byte[1000_006];
static int index, total;
static InputStream in;
static BufferedWriter bw;
public void initIO(InputStream is, OutputStream os) {
try {
in = is;
bw = new BufferedWriter(new OutputStreamWriter(os));
} catch (Exception e) {
}
}
public void initIO(String inputFile, String outputFile) {
try {
in = new FileInputStream(inputFile);
bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(outputFile)));
} catch (Exception e) {
}
}
private int scan() throws Exception {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0)
return -1;
}
return buf[index++];
}
public String nextLine() throws Exception {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c >= 32; c = scan())
sb.append((char) c);
return sb.toString();
}
public String next() throws Exception {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan())
sb.append((char) c);
return sb.toString();
}
public int nextInt() throws Exception {
int c, val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+')
c = scan();
for (; c >= '0' && c <= '9'; c = scan())
val = (val << 3) + (val << 1) + (c & 15);
return neg ? -val : val;
}
public long nextLong() throws Exception {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+')
c = scan();
for (; c >= '0' && c <= '9'; c = scan())
val = (val << 3) + (val << 1) + (c & 15);
return neg ? -val : val;
}
public void print(Object a) throws Exception {
bw.write(a.toString());
}
public void printsp(Object a) throws Exception {
print(a);
print(" ");
}
public void println() throws Exception {
bw.write("\n");
}
public void printArray(int[] arr) throws Exception{
for(int i = 0;i<arr.length;i++){
print(arr[i]+ " ");
}
println();
}
public void println(Object a) throws Exception {
print(a);
println();
}
public void flush() throws Exception {
bw.flush();
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 37421001b510cb41f5da96f5f9a6d6c8 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes |
import java.util.Scanner;
/**
*
* @author Lenovo
*/
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
int flag = 0;
for (int j = 0; j < t; j++) {
int n = input.nextInt();
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = input.nextInt();
}
for (int i = n - 1; i > 0; i--) {
if (a[i] % a[0] == 0) {
flag = 1;
} else {
flag = 0;
break;
}
}
if (flag == 1) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | e99b4209bc8dd579ef9cc34e78d63db0 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.Math.PI;
import static java.lang.Math.min;
import static java.lang.System.arraycopy;
import static java.lang.System.exit;
import static java.util.Arrays.copyOf;
import java.util.LinkedList;
import java.util.List;
import java.util.Iterator;
import java.io.FileReader;
import java.io.FileWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Deque;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Comparator;
import java.lang.StringBuilder;
import java.util.Collections;
import java.util.*;
import java.text.DecimalFormat;
public class Solution {
// static class Edge{
// int u, v, w;
// Edge(int u, int v, int w){
// this.u = u;
// this.v = v;
// this.w = w;
// }
// }
static class Pair{
int first, second;
Pair(int first, int second){
this.first = first;
this.second = second;
}
@Override
public String toString(){
return (this.first+" "+this.second);
}
}
// static class Tuple{
// int first, second, third;
// Tuple(int first, int second, int third){
// this.first = first;
// this.second =second;
// this.third = third;
// }
// @Override
// public String toString(){
// return first+" "+second+" "+third;
// }
// }
// static class Point{
// int x, y;
// Point(int x, int y){
// this.x = x;
// this.y = y;
// }
// @Override
// public String toString(){
// return x+" "+y;
// }
// }
static BufferedReader in;
static PrintWriter out;
static StringTokenizer tok;
static int dx[] = {0, -1, 0, 1}; //left up right down
static int dy[] = {-1, 0, 1, 0};
static int MOD = (int)1e9+7, INF = (int)1e9;
static boolean vis[];
static ArrayList<Integer> adj[];
private static void solve() throws IOException{
int n = scanInt();
int arr[] = inputArray(n);
if(arr[0] == 1){
out.println("YES");
return;
}
for(int i = 1; i<n; ++i){
if(arr[i]%arr[0]!=0){
out.println("NO");
return;
}
}
out.println("YES");
}
private static int[] inputArray(int n) throws IOException {
int arr[] = new int[n];
for(int i=0; i<n; ++i)
arr[i] = scanInt();
return arr;
}
private static void displayArray(int arr[]){
for(int i = 0; i<arr.length; ++i)
out.print(arr[i]+" ");
out.println();
}
public static void main(String[] args) {
try {
long startTime = System.currentTimeMillis();
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
//in = new BufferedReader(new FileReader("input.txt"));
//out = new PrintWriter(new FileWriter("output.txt"));
int test = scanInt();
for(int t=1; t<=test; t++){
// out.print("Case #"+t+": ");
solve();
}
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
//out.println(totalTime+"---------- "+System.currentTimeMillis() );
in.close();
out.close();
} catch (Throwable e) {
e.printStackTrace();
exit(1);
}
}
static int scanInt() throws IOException {
return parseInt(scanString());
}
static long scanLong() throws IOException {
return parseLong(scanString());
}
static double scanDouble() throws IOException {
return parseDouble(scanString());
}
static String scanString() throws IOException {
if (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
static String scanLine() throws IOException {
return in.readLine();
}
private static void sort(int arr[]){
mergeSort(arr, 0, arr.length-1);
}
private static void sort(int arr[], int start, int end){
mergeSort(arr, start, end-1);
}
private static void mergeSort(int arr[], int start, int end){
if(start >= end)
return;
int mid = (start+end)/2;
mergeSort(arr, start, mid);
mergeSort(arr, mid+1, end);
merge(arr, start, mid, end);
}
private static void merge(int arr[], int start, int mid, int end){
int n1 = mid - start+1;
int n2 = end - mid;
int left[] = new int[n1];
int right[] = new int[n2];
for(int i = 0; i<n1; ++i){
left[i] = arr[i+start];
}
for(int i = 0; i<n2; ++i){
right[i] = arr[mid+1+i];
}
int i = 0, j = 0, curr = start;
while(i <n1 && j <n2){
if(left[i] <= right[j]){
arr[curr] = left[i];
++i;
}
else{
arr[curr] = right[j];
++j;
}
++curr;
}
while(i<n1){
arr[curr] = left[i];
++i; ++curr;
}
while(j<n2){
arr[curr] = right[j];
++j; ++curr;
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 1027062cb8625fe3a0f8c1e1a19693e5 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class Main{
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t-->0) {
int n=s.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++) {
a[i]=s.nextInt();
}
int diff=a[0];
int f=0;
for(int i=1;i<n;i++) {
if(a[i]%diff==0) {
}
else {
System.out.println("NO");
f=1;
break;
}
}
if(f==0) {
System.out.println("YES");
}
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | a39f3aed931373536ceb8443263df159 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
public class CodeForces2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int len = sc.nextInt();
int[] A = new int[len];
for (int j = 0; j < len; j++) {
A[j] = sc.nextInt();
}
boolean ans = differenceOperations(A);
if (ans) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
private static boolean differenceOperations(int[] A) {
int count=0;
for(int i = A.length-1 ; i>=1 ; i--) {
if((A[i] % A[0]) == 0) {
count++;
}
}
if(count == A.length-1) {
return true;
}
else {
return false;
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | aef938fb1d1aeda952ec3bf628cc0d2d | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes |
import java.util.Scanner;
public class Srhossain{
public static void main(String[] args){
new Srhossain();
}
public Srhossain(){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int x = sc.nextInt();
for(int i = n; i > 1; i--){
int y = sc.nextInt();
if((y%x) != 0){
n = -1;
}
}
if(n == -1){
System.out.println("NO");
}
else{
System.out.println("YES");
}
}
sc.close();
}
public void showarr(int[] arr){
for(int i=0; i<arr.length; i++)
System.out.print(arr[i]+" ");
showln("");
}
public void show(String s){ System.out.print(s); }
public void showln(String s){ System.out.println(s); }
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 8107ed6033d4591c20cd6d76eabeef69 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0)
{
int n = sc.nextInt();
long[] nums = new long[n];
for(int i=0;i<n;i++)
{
nums[i] = sc.nextLong();
}
boolean flag = true;
for(int i=1;i<n;i++)
{
if(nums[i]%nums[0]!=0)
{
flag = false;
break;
}
}
if(flag==false)
System.out.println("no");
else
System.out.println("yes");
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 81b086ac45bb03ae8f62402ea102decb | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
import java.util.StringTokenizer;
public class App {
public static Scanner scan = new Scanner(System.in);
public static void main(String[] args) throws Exception {
int n = Integer.parseInt(scan.nextLine());
while (n > 0) {
System.out.println(solve() ? "YES" : "NO");
n--;
}
}
public static boolean solve() {
StringTokenizer st = new StringTokenizer("a b");
int length = Integer.parseInt(scan.nextLine());
int arr[] = new int[length];
st = new StringTokenizer(scan.nextLine());
for (int i = 0; i < length; i++) {
arr[i] = Integer.parseInt(st.nextToken());
if(i >= 1)
{
if (arr[i] % arr[0] != 0) {
return false;
}
}
}
return true;
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 39a6b2d0b1158f46b197f64c48c2ff42 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef {
public static void main(String[] args) throws java.lang.Exception {
PrintWriter out = new PrintWriter(System.out);
FastScanner sc = new FastScanner();
int tater = sc.nextInt();
while (tater-- > 0) {
int n = sc.nextInt();
int a[] = new int[n];
boolean isIncreasing = true;
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
if (a[i] %a[0] != 0){
isIncreasing = false;
}
}
if (isIncreasing) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
out.flush();
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 7e0aba290e213d94c7deac64826d4744 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | //package com.company;
import java.io.*;
import java.util.*;
public class Main{
static final Random random = new Random();
static boolean[] primecheck;
static ArrayList<Integer>[] adj;
static int[] vis;
static int[] parent;
static int[] rank;
static int[] fact;
static int[] invFact;
static int[] ft;
static int mod = (int)1e9 + 7;
public static void main(String[] args) {
OutputStream outputStream = System.out;
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(outputStream);
PROBLEM solver = new PROBLEM();
int t = 1;
t = in.ni();
for (int i = 0; i < t; i++) {
//out.print("Case #" + (i+1) + ": ");
solver.solve(in, out);
}
out.close();
}
static class PROBLEM {
public static void solve(FastReader in, PrintWriter out) {
int n = in.ni(), a[] = in.ra(n);
for (int i = 1; i < n; i++) {
if((a[i]/a[i-1])*a[i-1] == a[i]){
a[i] = a[i-1];
continue;
}
out.println("NO");
return;
}
out.println("YES");
}
}
static int findLower(int[] a, int x){
int l = 0, r = a.length-1;
while(l<=r){
int mid = l + (r-l)/2;
if(a[mid]>=x) r = mid-1;
else l = mid+1;
}
return l;
}
static int findHigher(int[] a, int x){
int l = 0, r = a.length-1;
while(l<=r){
int mid = l + (r-l)/2;
if(a[mid]<=x) l = mid+1;
else r = mid-1;
}
return r;
}
static void graph(int n, int e, FastReader in){
adj = new ArrayList[n+1];
vis = new int[n+1];
for (int i = 0; i < n + 1; i++) adj[i] = new ArrayList<>();
for (int i = 0; i < e; i++) {
int a = in.ni(), b = in.ni();
adj[a].add(b);
adj[b].add(a);
}
}
static int[] dx = {0, 0, 1, -1, 0, 0}, dy = {1, -1, 0, 0, 0, 0}, dz = {0, 0, 0, 0, 1, -1};
static int lower_bound(int array[], int key) {
int index = Arrays.binarySearch(array, key);
// If key is not present in the array
if (index < 0) {
// Index specify the position of the key
// when inserted in the sorted array
// so the element currently present at
// this position will be the lower bound
return Math.abs(index) - 1;
}
// If key is present in the array
// we move leftwards to find its first occurrence
else {
// Decrement the index to find the first
// occurrence of the key
// while (index > 0) {
//
// // If previous value is same
// if (array[index - 1] == key)
// index--;
//
// // Previous value is different which means
// // current index is the first occurrence of
// // the key
// else
// return index;
// }
return index;
}
}
static int upper_bound(int arr[], int key)
{
int index = Arrays.binarySearch(arr, key);
int n = arr.length;
// If key is not present in the array
if (index < 0) {
// Index specify the position of the key
// when inserted in the sorted array
// so the element currently present at
// this position will be the upper bound
return Math.abs(index) - 1;
}
// If key is present in the array
// we move rightwards to find next greater value
else {
// Increment the index until value is equal to
// key
// while (index < n) {
//
// // If current value is same
// if (arr[index] == key)
// index++;
//
// // Current value is different which means
// // it is the greater than the key
// else {
// return index;
// }
// }
return index;
}
}
static int getKthElement(int k){
int l = 0, r = ft.length-1, el = Integer.MAX_VALUE;
while(l <= r){
int mid = l+r>>1;
if(sumFenwick(ft, mid) >= k){
el = Math.min(el, mid);
r = mid-1;
}else l = mid+1;
}
return el;
}
static int rangeFenwick(int[] ft, int i, int j){
return sumFenwick(ft, j) - sumFenwick(ft, i);
}
static int sumFenwick(int[] ft, int i){
int sum = 0;
for(; i>0; i&=~(i&-i)) sum+=ft[i];
return sum;
}
static void addFenwick(int[] ft, int i, int x){
int n = ft.length;
for(; i<n; i+=i&-i) ft[i] += x;
}
static void combi(){
fact = new int[200001]; fact[0] = 1;
invFact = new int[200001]; invFact[0] = 1;
for (int i = 1; i < fact.length; i++) {
fact[i] = (int)(((long)fact[i-1]%mod * i%mod) % mod);
invFact[i] = (mod - ((mod/i)*invFact[mod%i])%mod)%mod;
}
}
static int nCk(int n, int k){
return fact[n] * invFact[k]%mod * invFact[n-k]%mod;
}
static String reverse(String s){
char[] ch = s.toCharArray();
for (int j = 0; j < ch.length / 2; j++) {
char temp = ch[j];
ch[j] = ch[ch.length-j-1];
ch[ch.length-j-1] = temp;
}
return String.valueOf(ch);
}
static int[][] matrixMul(int[][] a, int[][] m){
if(a[0].length == m.length) {
int[][] b = new int[a.length][m.length];
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m.length; j++) {
int sum = 0;
for (int k = 0; k < m.length; k++) {
sum += m[i][k] * m[k][j];
}
b[i][j] = sum;
}
}
return b;
}
return null;
}
static void dfs(int i, int d){
vis[i] = 1;
for(int j : adj[i]){
if (vis[j] == 0) dfs(j, d+1);
}
}
static int find(int u){
if(u == parent[u]) return u;
return parent[u] = find(parent[u]);
}
static void union(int u, int v){
int a = find(u), b = find(v);
if(a == b) return;
if(rank[a] > rank[b]) parent[b] = a;
else if(rank[a] < rank[b]) parent[a] = b;
else{
parent[b] = a;
rank[a]++;
}
}
static void dsu(int n){
parent = new int[n];
rank = new int[n];
for (int i = 0; i < parent.length; i++) {
parent[i] = i;
rank[i] = 1;
}
}
static boolean isPalindrome(char[] s){
boolean b = true;
for (int i = 0; i < s.length / 2; i++) {
if(s[i] != s[s.length-1-i]){
b = false;
break;
}
}
return b;
}
static void yn(boolean b, PrintWriter out){
if(b) out.println("YES");
else out.println("NO");
}
static void pa(int[] a, PrintWriter out){
for (int j : a) out.print(j + " ");
out.println();
}
static void pa(long[] a, PrintWriter out){
for (long j : a) out.print(j + " ");
out.println();
}
public static void sortByColumn(int arr[][], int col)
{
// Using built-in sort function Arrays.sort
Arrays.sort(arr, new Comparator<>() {
@Override
// Compare values according to columns
public int compare(final int[] entry1,
final int[] entry2) {
// To sort in descending order revert
// the '>' Operator
if (entry1[col] > entry2[col])
return 1;
else
return -1;
}
}); // End of function call sort().
}
static boolean isPoT(long n){
return ((n&(n-1)) == 0);
}
static long sigmaK(long k){
return (k*(k+1))/2;
}
static void swap(int[] a, int l, int r) {
int temp = a[l];
a[l] = a[r];
a[r] = temp;
}
static int binarySearch(int[] a, int l, int r, int x){
if(r>=l){
int mid = l + (r-l)/2;
if(a[mid] == x) return mid;
if(a[mid] > x) return binarySearch(a, l, mid-1, x);
else return binarySearch(a,mid+1, r, x);
}
return -1;
}
static long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
static long lcm(long a, long b){
return (a / gcd(a, b)) * b;
}
static int ceil(int a, int b){
return (a+b-1)/b;
}
static long ceil(long a, long b){
return (a+b-1)/b;
}
static boolean isSquare(double a) {
boolean isSq = false;
double b = Math.sqrt(a);
double c = Math.sqrt(a) - Math.floor(b);
if (c == 0) isSq = true;
return isSq;
}
static long fast_pow(long a, long b) { //Jeel bhai OP
if(b == 0)
return 1L;
long val = fast_pow(a, b / 2);
if(b % 2 == 0)
return val * val % mod;
else
return val * val % mod * a % mod;
}
// static class Pair implements Comparable<Pair>{
//
// int x;
// int y;
//
// Pair(int x, int y){
// this.x = x;
// this.y = y;
// }
//
// public int compareTo(Pair o){
//
// int ans = Integer.compare(x, o.x);
// if(o.x == x) ans = Integer.compare(y, o.y);
//
// return ans;
//
//// int ans = Integer.compare(y, o.y);
//// if(o.y == y) ans = Integer.compare(x, o.x);
////
//// return ans;
// }
// }
static class Tuple implements Comparable<Tuple>{
int x, y, id;
Tuple(int x, int y, int id){
this.x = x;
this.y = y;
this.id = id;
}
public int compareTo(Tuple o){
int ans = Integer.compare(x, o.x);
if(o.x == x) ans = Integer.compare(y, o.y);
return ans;
}
}
public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
public U x;
public V y;
public Pair(U x, V y) {
this.x = x;
this.y = y;
}
public int hashCode() {
return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
}
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Pair<U, V> p = (Pair<U, V>) o;
return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
}
public int compareTo(Pair<U, V> b) {
int cmpU = x.compareTo(b.x);
return cmpU != 0 ? cmpU : y.compareTo(b.y);
}
public int compareToY(Pair<U, V> b) {
int cmpU = y.compareTo(b.y);
return cmpU != 0 ? cmpU : x.compareTo(b.x);
}
public String toString() {
return String.format("(%s, %s)", x.toString(), y.toString());
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int ni() {
return Integer.parseInt(next());
}
long nl() {
return Long.parseLong(next());
}
double nd() {
return Double.parseDouble(next());
}
char nc() {
return next().charAt(0);
}
boolean nb() {
return !(ni() == 0);
}
// boolean nextBoolean(){return Boolean.parseBoolean(next());}
String nline() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int[] ra(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) array[i] = ni();
return array;
}
public long[] ral(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) array[i] = nl();
return array;
}
}
static void ruffleSort(int[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
public static void Sieve(int n) {
Arrays.fill(primecheck, true);
primecheck[0] = false;
primecheck[1] = false;
for (int i = 2; i * i < n + 1; i++) {
if (primecheck[i]) {
for (int j = i * 2; j < n + 1; j += i) {
primecheck[j] = false;
}
}
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 785adad9371a578b8dcf9c8244c1618f | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0){
t--;
int n = sc.nextInt();
int a[]=new int[n];
int i=0;
int x=0;
while(i<n){
a[i]=sc.nextInt();
if(i>=1){
if(a[i]%a[0]!=0 ){
x=1;
}
}
i++;
}
if(x==0){
System.out.println("Yes");
}
else{
System.out.println("No");
}
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 32a72040690da7382f118459a035d8c5 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.*;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
//OutputStream outputStream = System.out;
//PrintWriter w = new PrintWriter(outputStream);
int i,j;
int t=in.nextInt();
for(i=0;i<t;i++)
{
int n,m, x,c=0,k;
n=in.nextInt();
int a[]=new int[n];
for(j=0;j<n;j++)
{
a[j]=in.nextInt();
}
for(j=n-1;j>=0;j--)
{
if(a[j]%a[0]!=0)
{
System.out.println("NO");
break;
}
else
{
if(j!=1)
continue;
else
{
System.out.println("YES");
break;
}
}
}
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 973e3af625085f09b175baa08f1e73d8 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class Solution{
public static final Scanner in= new Scanner(System.in);
static Long globalInt;
public static String Solve(int n){
int[] array = new int[n];
for(int i=0; i<n; i++)
array[i] = in.nextInt();
int first = array[0];
for(int i=1 ;i<n; i++)
if(array[i]%first != 0)
return "NO";
return "YES";
}
public static void main(String[] args){
int cases=in.nextInt();
for(int i=0; i<cases; i++){
int n=in.nextInt();
System.out.println(Solve(n));
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 28c0d9133017f52522b866324f114212 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
public class Solution{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while(t-- > 0){
int n = scanner.nextInt();
String check = "YES";
int[] arr = new int[n];
for(int i = 0 ; i < n ; i++){
arr[i] = scanner.nextInt();
if (arr[i] % arr[0] != 0) {
check = "NO";
}
}
System.out.println(check);
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | bef67e7f501994b01de72799fd1b8b40 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | /* Online Java Compiler and Editor */
import java.util.*;
public class HelloWorld {
public static void main(String []args) {
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
while(t-- > 0) {
int n = scn.nextInt();
int[] arr = new int[n];
for(int i =0; i<n; i++) {
arr[i] = scn.nextInt();
}
boolean ans = true;
if(arr[0] == 1) {
System.out.println("YES");
continue;
}
for(int i = 1; i<n-1; i++) {
if(arr[i]%arr[i-1] == 0)arr[i] = arr[i-1];
else arr[i] = arr[i]%arr[i-1];
}
for(int i = n-1; i> 0; i--) {
arr[i] = arr[i]%arr[i-1];
if(arr[i] != 0)ans = false;
}
if(ans) System.out.println("YES");
else System.out.println("NO");
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 2034e4c1acddda24c9766eaa0ea37f6d | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | /*LoudSilence*/
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Solution {
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
static FastScanner s = new FastScanner();
static FastWriter out = new FastWriter();
final static int mod = (int)1e9 + 7;
final static int INT_MAX = Integer.MAX_VALUE;
final static int INT_MIN = Integer.MIN_VALUE;
final static long LONG_MAX = Long.MAX_VALUE;
final static long LONG_MIN = Long.MIN_VALUE;
final static double DOUBLE_MAX = Double.MAX_VALUE;
final static double DOUBLE_MIN = Double.MIN_VALUE;
final static float FLOAT_MAX = Float.MAX_VALUE;
final static float FLOAT_MIN = Float.MIN_VALUE;
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
static class FastScanner{BufferedReader br;StringTokenizer st;
public FastScanner() {if(System.getProperty("ONLINE_JUDGE") == null){try {br = new BufferedReader(new FileReader("E:\\Competitive Coding\\input.txt"));}
catch (FileNotFoundException e) {br = new BufferedReader(new InputStreamReader(System.in));}}else{br = new BufferedReader(new InputStreamReader(System.in));}}
String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException e){e.printStackTrace();}}return st.nextToken();}
int nextInt(){return Integer.parseInt(next());}
long nextLong(){return Long.parseLong(next());}
double nextDouble(){return Double.parseDouble(next());}
List<Integer> readIntList(int n){List<Integer> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextInt()); return arr;}
List<Long> readLongList(int n){List<Long> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextLong()); return arr;}
int[] readIntArr(int n){int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = s.nextInt(); return arr;}
long[] readLongArr(int n){long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = s.nextLong(); return arr;}
String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}}
static class FastWriter{private BufferedWriter bw;public FastWriter(){if(System.getProperty("ONLINE_JUDGE") == null){try {this.bw = new BufferedWriter(new FileWriter("E:\\Competitive Coding\\output.txt"));}
catch (IOException e) {this.bw = new BufferedWriter(new OutputStreamWriter(System.out));}}else{this.bw = new BufferedWriter(new OutputStreamWriter(System.out));}}
public void print(Object object) throws IOException{bw.append(""+ object);}
public void println(Object object) throws IOException{print(object);bw.append("\n");}
public void debug(int object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");}
public void debug(long object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");}
public void close() throws IOException{bw.close();}}
public static void println(Object str) throws IOException{out.println(""+str);}
public static void println(Object str, int nextLine) throws IOException{out.print(""+str);}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
public static ArrayList<Integer> seive(int n){ArrayList<Integer> list = new ArrayList<>();int arr[] = new int[n+1];for(long i = 2; i <= n; i++) {if(arr[(int)i] == 1) {continue;}else {list.add((int)i);for(long j = i*i; j <= n; j = j + i) {arr[(int)j] = 1;}}}return list;}
public static long gcd(long a, long b){if(a > b) {a = (a+b)-(b=a);}if(a == 0L){return b;}return gcd(b%a, a);}
public static void swap(int[] arr, int i, int j) {arr[i] = arr[i] ^ arr[j]; arr[j] = arr[j] ^ arr[i]; arr[i] = arr[i] ^ arr[j];}
public static boolean isPrime(long n){if(n < 2){return false;}if(n == 2 || n == 3){return true;}if(n%2 == 0 || n%3 == 0){return false;}long sqrtN = (long)Math.sqrt(n)+1;for(long i = 6L; i <= sqrtN; i += 6) {if(n%(i-1) == 0 || n%(i+1) == 0) return false;}return true;}
public static long mod_add(long a, long b){ return (a%mod + b%mod)%mod;}
public static long mod_sub(long a, long b){ return (a%mod - b%mod + mod)%mod;}
public static long mod_mul(long a, long b){ return (a%mod * b%mod)%mod;}
public static long modInv(long a, long b){ return expo(a, b-2)%b;}
public static long mod_div(long a, long b){return mod_mul(a, modInv(b, mod));}
public static long expo (long a, long n){if(n == 0){return 1;}long recAns = expo(mod_mul(a,a), n/2);if(n % 2 == 0){return recAns;}else{return mod_mul(a, recAns);}}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
// Pair class
public static class Pair<X extends Comparable<X>,Y extends Comparable<Y>> implements Comparable<Pair<X, Y>>{
X first;
Y second;
public Pair(X first, Y second){
this.first = first;
this.second = second;
}
public String toString(){
return "( " + first+" , "+second+" )";
}
@Override
public int compareTo(Pair<X, Y> o) {
int t = first.compareTo(o.first);
if(t == 0) return second.compareTo(o.second);
return t;
}
}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
// Code begins
public static void solve() throws IOException {
int n = s.nextInt();
int arr[] = s.readIntArr(n);
int gcd = arr[0];
for(int i = 1; i < n; i++){
gcd = (int)gcd(gcd, arr[i]);
}
for(int i = 0; i < n; i++){
arr[i] = arr[i]/gcd;
}
if(arr[0] == 1){
println("YES");
}else{
println("NO");
}
}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
public static void main(String[] args) throws IOException {
int test = s.nextInt();
for(int t = 1; t <= test; t++) {
solve();
}
out.close();
}
}
// public static boolean allsame(int arr[]){
// for(int i = 0; i < arr.length-1; i++){
// if(arr[i] != arr[i+1]) return false;
// }
// return true;
// }
//
// public static List<List<Integer>> permutation(int arr[], int i){
// if(i == 0){
// List<List<Integer>> ans = new ArrayList<>();
// List<Integer> li = new ArrayList<>();
// li.add(arr[i]);
// ans.add(li);
// return ans;
// }
// int temp = arr[i];
// List<List<Integer>> rec = permutation(arr, i-1);
// List<List<Integer>> ans = new ArrayList<>();
// for(List<Integer> li : rec){
// for(int j = 0; j <= li.size(); j++){
// List<Integer> list = new ArrayList<>();
// for(int ele: li){
// list.add(ele);
// }
// list.add(j, temp);
// ans.add(list);
// }
// }
// return ans;
// }
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 1f0b29183f2cdb52b787683141766eb8 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static StringBuilder sb;
static dsu dsu;
static long fact[];
static int mod = (int) (1e9 + 7);
static void print(int[]arr){
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+" ");
}
System.out.println();
}
static void print(int t){
System.out.println(t);
}
static long get1(long val,long p){
for(long i=0;i<p;i++){
val=(long)val/2;
}
return val;
}
static int get(long t, ArrayList<Long>temp, long[][]arr,long n){
if(t<n)return (int)t;
for(int i=1;i<temp.size();i++){
long l=temp.get(i-1);
long r=temp.get(i)-1;
if(t>=l&&t<=r){
long dis=t-l;
return get(arr[i-1][0]+dis,temp,arr,n);
}
}
return -1;
}
static void solve() {
int n=i();
int[]arr=new int[n];
for(int i=0;i<n;i++)arr[i]=i();
for(int i=1;i<n;i++){
int dif=arr[i]-arr[i-1];
if(arr[i]%arr[0]!=0){
sb.append("NO\n");
return;
}
}
sb.append("YES\n");
}
public static void main(String[] args) {
sb = new StringBuilder();
int test =i();
fact=new long[(int)1e6+10];
fact[0]=fact[1]=1;
for(int i=2;i<fact.length;i++)
{ fact[i]=((long)(i%mod)*(long)(fact[i-1]%mod))%mod; }
while (test-- > 0) {
solve();
}
System.out.println(sb);
}
//**************NCR%P******{************
static long ncr(int n, int r) {
if (r > n)
return (long) 0;
long res = fact[n] % mod;
// System.out.println(res);
res = ((long) (res % mod) * (long) (p(fact[r], mod - 2) % mod)) % mod;
res = ((long) (res % mod) * (long) (p(fact[n - r], mod - 2) % mod)) % mod;
// System.out.println(res);
return res;
}
static long p(long x, long y)// POWER FXN //
{
if (y == 0)
return 1;
long res = 1;
while (y > 0) {
if (y % 2 == 1) {
res = (res * x) % mod;
y--;
}
x = (x * x) % mod;
y = y / 2;
}
return res;
}
//**************END******************
// *************Disjoint set
// union*********//
static class dsu {
int parent[];
dsu(int n) {
parent = new int[n];
for (int i = 0; i < n; i++)
parent[i] = i;
}
int find(int a) {
if (parent[a] ==a)
return a;
else {
int x = find(parent[a]);
parent[a] = x;
return x;
}
}
void merge(int a, int b) {
a = find(a);
b = find(b);
if (a == b)
return;
parent[b] = a;
}
}
//**************PRIME FACTORIZE **********************************//
static TreeMap<Integer, Integer> prime(long n) {
TreeMap<Integer, Integer> h = new TreeMap<>();
long num = n;
for (int i = 2; i <= Math.sqrt(num); i++) {
if (n % i == 0) {
int nt = 0;
while (n % i == 0) {
n = n / i;
nt++;
}
h.put(i, nt);
}
}
if (n != 1)
h.put((int) n, 1);
return h;
}
//****CLASS PAIR ************************************************
static class Pair implements Comparable<Pair> {
int i;
int l;
Pair(int i, int l) {
this.i = i;
this.l = l;
}
public int compareTo(Pair o) {
return (int) (this.l - o.l);
}
}
//****CLASS PAIR **************************************************
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int Int() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String String() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return String();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
static InputReader in = new InputReader(System.in);
static OutputWriter out = new OutputWriter(System.out);
public static long[] sort(long[] a2) {
int n = a2.length;
ArrayList<Long> l = new ArrayList<>();
for (long i : a2)
l.add(i);
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a2[i] = l.get(i);
return a2;
}
public static char[] sort(char[] a2) {
int n = a2.length;
ArrayList<Character> l = new ArrayList<>();
for (char i : a2)
l.add(i);
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a2[i] = l.get(i);
return a2;
}
public static long pow(long x, long y) {
long res = 1;
while (y > 0) {
if (y % 2 != 0) {
res = (res * x);// % modulus;
y--;
}
x = (x * x);// % modulus;
y = y / 2;
}
return res;
}
//GCD___+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public static long gcd(long x, long y) {
if (x == 0)
return y;
else
return gcd(y % x, x);
}
// ******LOWEST COMMON MULTIPLE
// *********************************************
public static long lcm(long x, long y) {
return (x * (y / gcd(x, y)));
}
//INPUT PATTERN********************************************************
public static int i() {
return in.Int();
}
public static long l() {
String s = in.String();
return Long.parseLong(s);
}
public static String s() {
return in.String();
}
public static int[] readArrayi(int n) {
int A[] = new int[n];
for (int i = 0; i < n; i++) {
A[i] = i();
}
return A;
}
public static long[] readArray(long n) {
long A[] = new long[(int) n];
for (int i = 0; i < n; i++) {
A[i] = l();
}
return A;
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | c4a26e733cfd20569f035a0bbbea3772 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
public class ColumnSwapping
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++)
{
int n=sc.nextInt();
int arr[]=new int[n];
for(int j=0;j<n;j++)
{
arr[j]=sc.nextInt();
}
int flg=0;
for(int j=1;j<n;j++)
{
if(arr[j]%arr[0]!=0)
{
flg=1;
break;
}
}
if(flg==0) System.out.println("YES");
else System.out.println("NO");
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 20efdbdc6070cab162f96770fa7ad7a7 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class ans{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int [] arr = new int[n];
for(int i=0;i<n;i++){
arr[i] = sc.nextInt();
}
int val = arr[0];
String ans = "Yes";
for(int i:arr){
if(i%val!=0){
ans="No";
break;
}
}
System.out.println(ans);
}
}
}
// int n = sc.nextInt(); // size of n array;
// int[] arr = new int[n];
// for(int i=0;i<n;i++){
// arr[i] = sc.nextInt();
// }
// int pa6i string levva
// int a = sc.nextInt();
// sc.nextLine();
// String str = sc.nextLine(); | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 33d5f7ee119ff33f4e4652d2ce6c116e | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
public class DifferenceOperations {
public static void main(String[] args) {
Scanner input=new Scanner (System.in);
int t=input.nextInt();
for(int i=0;i<t;i++)
{
boolean flag=true;
int n=input.nextInt();
int arr[]=new int[n];
for(int m=0;m<n;m++)
{
arr[m]=input.nextInt();
}
int first=arr[0];
for(int m=1;m<n;m++)
{
if(arr[m]%first==0)
continue;
else
{
flag=false;
break;
}
}
if (flag)
System.out.println("YES");
else
System.out.println("NO");
}}} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 29825166d49379de840d66b2309b783f | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class CF808 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
int[] a = new int[n];
for(int i =0 ; i<n;i++) {
a[i] = sc.nextInt();
}
if(n==2) {
if(a[1]%a[0]==0) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
else {
boolean c = true;
if(a[1]%a[0]!=0) {
c = false;
}
for(int i = 2;i<n;i++) {
if((a[i])%a[0]!=0) {
c = false;
break;
}
}
if(c) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | d0718f6b47d6373198efdb191d1d4c27 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static long mod = 1000000007;
static int[]parent;
static int[]rank;
static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
public static void main(String[] args) throws IOException {
FastReader sc = new FastReader();
int t = sc.nextInt();
while( t-- > 0) {
int n=sc.nextInt();
int[]arr=new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
boolean f=true;
for(int i=1;i<n;i++){
if(arr[i]%arr[0]!=0){
f=false;
break;
}
}
if(f){
out.println("yes");
}else{
out.println("No");
}
}
out.flush();
}
public static int find(int x){
if(parent[x]==x){
return x;
}else{
int px=parent[x];
int lead=find(px);
parent[x]=lead;
return lead;
}
}
public static class Pair{
long first;
long second;
Pair(long first,long second){
this.first=first;
this.second=second;
}
}
public static void union(int l1,int l2){
if(rank[l1]>rank[l2]){
parent[l2]=l1;
rank[l1]++;
}else if(rank[l2]>rank[l1]){
parent[l1]=l2;
rank[l2]++;
}else{
parent[l1]=l2;
rank[l2]++;
}
}
public static void reverse(Long[]arr,int i,int j){
while(i<=j){
long temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
i++;
j--;
}
}
public static int gcd(int n1,int n2){
while(n1%n2!=0){
int rem=n2%n1;
n2=n1;
n1=rem;
}
return n1;
}
// static class Pair{
// int val;
// int bd;
// Pair(int val,int bd){
// this.val=val;
// this.bd=bd;
// }
// }
public static int binarySearch(int[]arr,int data){
int left = 0;
int right = arr.length - 1;
int ceil = -1;
int floor = 0;
while(left <= right){
int mid = (left + right) / 2;
if(data > arr[mid]){
left = mid + 1;
floor = arr[mid];
} else if(data < arr[mid]){
right = mid - 1;
ceil = mid+1;
} else {
floor = arr[mid];
ceil = mid+1;
break;
}
}
return ceil;
}
/*
* WARNING -> DONT EVER USE ARRAYS.SORT() IN ANY WAY.
* A B C are easy just dont give up , you can do it!
* FIRST AND VERY IMP -> READ AND UNDERSTAND THE QUESTION VERY CAREFULLY.
* WARNING -> DONT CODE BULLSHIT , ALWAYS CHECK THE LOGIC ON MULTIPLE TESTCASES AND EDGECASES BEFORE.
* SECOND -> TRY TO FIND RELEVENT PATTERN SMARTLY.
* WARNING -> IF YOU THINK YOUR SOLUION IS JUST DUMB DONT SUBMIT IT BEFORE RECHECKING ON YOUR END.
*/
public static boolean ifpowof2(long n ) {
return ((n&(n-1)) == 0);
}
static boolean isprime(long x ) {
if( x== 2) {
return true;
}
if( x%2 == 0) {
return false;
}
for( long i = 3 ;i*i <= x ;i+=2) {
if( x%i == 0) {
return false;
}
}
return true;
}
static boolean[] sieveOfEratosthenes(long n) {
boolean prime[] = new boolean[(int)n + 1];
for (int i = 0; i <= n; i++) {
prime[i] = true;
}
for (long p = 2; p * p <= n; p++) {
if (prime[(int)p] == true) {
for (long i = p * p; i <= n; i += p)
prime[(int)i] = false;
}
}
return prime;
}
public static int[] nextLargerElement(int[] arr, int n) {
Stack<Integer> stack = new Stack<>();
int rtrn[] = new int[n];
rtrn[n-1] = -1;
stack.push( n-1);
for( int i = n-2 ;i >= 0 ; i--){
int temp = arr[i];
int lol = -1;
while( !stack.isEmpty() && arr[stack.peek()] <= temp){
if(arr[stack.peek()] == temp ) {
lol = stack.peek();
}
stack.pop();
}
if( stack.isEmpty()){
if( lol != -1) {
rtrn[i] = lol;
}
else {
rtrn[i] = -1;
}
}
else{
rtrn[i] = stack.peek();
}
stack.push( i);
}
return rtrn;
}
static void mysort(int[] arr) {
for(int i=0;i<arr.length;i++) {
int rand = (int) (Math.random() * arr.length);
int loc = arr[rand];
arr[rand] = arr[i];
arr[i] = loc;
}
Arrays.sort(arr);
}
static void mySort(Long[] arr) {
for(int i=0;i<arr.length;i++) {
int rand = (int) (Math.random() * arr.length);
long loc = arr[rand];
arr[rand] = arr[i];
arr[i] = loc;
}
Arrays.sort(arr);
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static long lcm(long a, long b)
{
return (a / gcd(a, b)) * b;
}
static long rightmostsetbit(long n) {
return n&-n;
}
static long leftmostsetbit(long n)
{
long k = (long)(Math.log(n) / Math.log(2));
return k;
}
static HashMap<Long,Long> primefactor( long n){
HashMap<Long ,Long> hm = new HashMap<>();
long temp = 0;
while( n%2 == 0) {
temp++;
n/=2;
}
if( temp!= 0) {
hm.put( 2L, temp);
}
long c = (long)Math.sqrt(n);
for( long i = 3 ; i <= c ; i+=2) {
temp = 0;
while( n% i == 0) {
temp++;
n/=i;
}
if( temp!= 0) {
hm.put( i, temp);
}
}
if( n!= 1) {
hm.put( n , 1L);
}
return hm;
}
static ArrayList<Integer> allfactors(int abs) {
HashMap<Integer,Integer> hm = new HashMap<>();
ArrayList<Integer> rtrn = new ArrayList<>();
for( int i = 2 ;i*i <= abs; i++) {
if( abs% i == 0) {
hm.put( i , 0);
hm.put(abs/i, 0);
}
}
for( int x : hm.keySet()) {
rtrn.add(x);
}
if( abs != 0) {
rtrn.add(abs);
}
return rtrn;
}
public static int[][] prefixsum( int n , int m , int arr[][] ){
int prefixsum[][] = new int[n+1][m+1];
for( int i = 1 ;i <= n ;i++) {
for( int j = 1 ; j<= m ; j++) {
int toadd = 0;
if( arr[i-1][j-1] == 1) {
toadd = 1;
}
prefixsum[i][j] = toadd + prefixsum[i][j-1] + prefixsum[i-1][j] - prefixsum[i-1][j-1];
}
}
return prefixsum;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 8926233817488462cbbb765242018537 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.*;
import java.util.*;
public class edu130 {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object) throws IOException {
bw.append("" + object);
}
public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}
public void close() throws IOException {
bw.close();
}
}
public static void main(String[] args) {
try {
FastReader sc = new FastReader();
FastWriter out = new FastWriter();
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int [] arr=new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
boolean cc=false;
for(int i=1;i<n;i++){
if(arr[i]%arr[0]!=0){
cc=true;
break;
}
}
if(cc){
if(arr[0]==1){
System.out.println("YES");
}else{
System.out.println("NO");
}
}else{
System.out.println("YES");
}
}
}catch(Exception e){
return;
}
}
private static void swap(long[] arr, int i, int ii) {
long temp=arr[i];
arr[i]=arr[ii];
arr[ii]=temp;
}
public static int lcm(int a,int b){
return (a/gcd(a,b))*b;
}
private static int gcd(int a, int b) {
if(b==0)return a;
return gcd(b,a%b);
}
static class Pair {
int a;
int b;
Pair(int a, int b) {
this.a = a;
this.b = b;
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 9192a93e7d3506518b605fc2eae3bb38 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Solution {
public static String solve(int n, int[] a) {
int f = a[0];
for(int i = 1; i<n; i++) {
if(a[i]%f!=0) {
return "NO";
}
}
return "YES";
}
public static void main(String[] args) throws IOException {
Reader r = new Reader();
BufferedWriter o = new BufferedWriter(new OutputStreamWriter(System.out));
int t = r.readI();
outer: for(int z = 1; z<=t; z++){
int n = r.readI();
int[] a = r.readArrI();
o.write(solve(n, a)+"\n");
o.flush();
}
}
}
class Reader {
BufferedReader r;
Reader(){
r = new BufferedReader(new InputStreamReader(System.in));
}
public int[] readArrI() throws IOException {
String[] s = r.readLine().split(" ");
int n = s.length;
int[] a = new int[n];
for(int j=0; j<n;j++) {
a[j] = Integer.parseInt(s[j]);
}
return a;
}
public long[] readArrL() throws IOException {
String[] s = r.readLine().split(" ");
int n = s.length;
long[] a = new long[n];
for(int j=0; j<n;j++) {
a[j] = Long.parseLong(s[j]);
}
return a;
}
public int readI() throws IOException {
String[] s = r.readLine().split(" ");
int n = Integer.parseInt(s[0]);
return n;
}
public long readL() throws IOException {
String[] s = r.readLine().split(" ");
long n = Long.parseLong(s[0]);
return n;
}
public String readS() throws IOException {
String s = r.readLine();
return s;
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 31ce48398c68318a0547bbbe5958c5e1 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
public class A_1 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int f=1; f<=T; f++)
{
int n = sc.nextInt();
int arr[] = new int[n];
for(int i=0; i<n; i++)
{
arr[i] =sc.nextInt();
}
boolean ans = true;
for(int i=1; i<n; i++)
{
if(arr[i]%arr[i-1]!=0)
{
arr[i] = arr[i]%arr[i-1];
}
}
for(int i=1; i<n; i++)
{
if(arr[i]%arr[i-1]==0)
{
arr[i] = arr[i-1];
}
}
for(int i=1; i<n; i++)
{
if(arr[i]!=arr[i-1])
{
ans = false;
break;
}
}
if(ans)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 8082da9dfa7a5f3d191acfb3d3474abd | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.*;
import java.util.*;
public class Prob1 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
int testCases = Integer.parseInt(br.readLine());
while (testCases--!=0) {
int n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = Integer.parseInt(st.nextToken());
}
boolean yes = true;
for (int i = 1; i < n; i++) {
if (nums[i] % nums[0] != 0) {
pw.println("NO");
yes = false;
break;
}
}
if (yes) {
pw.println("YES");
}
}
pw.close();
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 11 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.