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 | f142abb550d2b591098200ffba9fce8f | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 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.System.out;
import static java.lang.System.out;
public class Main {
public static void main(String[] args) throws Exception {
int t = A.nextInt();
for (int i = 0; i < t; i++) {
int n = A.nextInt();
for (int j = 0; j < n; j++) {
out.print((j+2)+" ");
}
out.println();
}
out.close();
}
public static class A {
public static long pow(long a, long b, long mod) {
if (b == 0) return 1;
long p = pow(a, b / 2, mod) % mod;
return ((p * p) % mod * Math.max(b % 2 * a, 1)) % mod;
}
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 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer in = new StringTokenizer("");
static PrintWriter out = new PrintWriter(System.out);
public static String nextToken() throws IOException {
while (in == null || !in.hasMoreTokens()) in = new StringTokenizer(br.readLine());
return in.nextToken();
}
public static Double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
public static int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public static long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
public static String nextLine() throws IOException {
return br.readLine();
}
}
}
class O implements Comparable<O> {
int a;
int b;
public O(int a, int b) {
this.a = a;
this.b = b;
}
@Override
public int compareTo(O o) {
return Integer.compare(o.b, b);
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 61cac5ceae31ae4bfcbf314d63e7fb98 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
public class LongestString {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long cases = scanner.nextLong();
scanner.nextLine();
while (cases-- > 0){
int n = scanner.nextInt();
for(int i=2; i<=n+1; i++){
System.out.print(i+" ");
}
System.out.print("\n");
}
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | b56456bbd5e4b1c6322cde6230063285 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
public class Solving {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
ArrayList<Long> primes = soe();
StringBuilder str=new StringBuilder();
// System.out.println(primes);
while(t-->0)
{
int n= in.nextInt();
for(int i=0;i<n;i++)
{
str.append(primes.get(i)+" ");
}
str.append("\n");
// str.append(ans+"\n");
}
System.out.println(str.toString());
}
static ArrayList<Long> soe()
{
ArrayList<Long> list = new ArrayList<Long>();
list.add(2L);
HashSet<Long> notprimes = new HashSet<Long>();
for(int i=3;i<120000;i+=2)
{
if(!notprimes.contains((long)i))
{
list.add((long)i);
for(int j=i;j<120000;j+=i)
{
notprimes.add((long)j);
}
}
}
// System.out.println(list.size());
return list;
}
static void morStringSolve(){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String s = in.next();
if(s.length() == 1 || s.charAt(0) <= s.charAt(1)) {
System.out.print("" + s.charAt(0) + s.charAt(0));
}
else {
int end = 1;
while (end + 1 < n && s.charAt(end + 1) <= s.charAt(end)) ++end;
for (int i = 0; i <= end; i++) {
System.out.print(s.charAt(i));
}
for (int i = end; i >= 0; i--) {
System.out.print(s.charAt(i));
}
}
System.out.println();
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 6a7e44f14f87404a1e1e970312dc98a6 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
import javax.swing.plaf.synth.SynthOptionPaneUI;
import java.io.*;
public class ss {
static FastReader fr=new FastReader();
static final Random random=new Random();
static long mod=1000000007L;
static HashMap<String,Integer>map=new HashMap<>();
static ArrayList<Long> soe()
{
ArrayList<Long> list = new ArrayList<Long>();
list.add(2l);
HashSet<Long> notprimes = new HashSet<Long>();
for(int i=3;i<120000;i+=2)
{
if(!notprimes.contains((long)i))
{
list.add((long)i);
for(int j=i;j<120000;j+=i)
{
notprimes.add((long)j);
}
}
}
// System.out.println(list.size());
return list;
}
public static void main(String args[]) throws IOException {
int t=fr.nextInt();
ArrayList<Long> primes = soe();
StringBuilder str=new StringBuilder();
// System.out.println(primes);
while(t-->0)
{
//
int n= fr.nextInt();
for(int i=0;i<n;i++)
{
str.append(primes.get(i)+" ");
}
str.append("\n");
// str.append(ans+"\n");
}
System.out.println(str.toString());
}
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 | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 6c62d3e6c1b8a0446b1f62e1b175c02b | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
import javax.swing.plaf.synth.SynthOptionPaneUI;
import java.io.*;
public class Solution {
static FastReader fr=new FastReader();
static final Random random=new Random();
static long mod=1000000007L;
static HashMap<String,Integer>map=new HashMap<>();
static ArrayList<Long> soe()
{
ArrayList<Long> list = new ArrayList<Long>();
list.add(2l);
HashSet<Long> notprimes = new HashSet<Long>();
for(int i=3;i<120000;i+=2)
{
if(!notprimes.contains((long)i))
{
list.add((long)i);
for(int j=i;j<120000;j+=i)
{
notprimes.add((long)j);
}
}
}
// System.out.println(list.size());
return list;
}
public static void main(String args[]) throws IOException {
int t=fr.nextInt();
ArrayList<Long> primes = soe();
StringBuilder str=new StringBuilder();
// System.out.println(primes);
while(t-->0)
{
//
int n= fr.nextInt();
for(int i=0;i<n;i++)
{
str.append(primes.get(i)+" ");
}
str.append("\n");
// str.append(ans+"\n");
}
System.out.println(str.toString());
}
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 | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 9d787e8961e3d1de33768b94e2d3b582 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Template {
private 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) {
FastReader scanner = new FastReader();
int tests = scanner.nextInt();
while (tests > 0) {
tests--;
int size = scanner.nextInt();
for (int i = 2; i <= size+1; i++) {
System.out.print(i + " ");
}
System.out.println();
}
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 9cfeb75c8cc84632d19209f7b18d4dda | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.sql.Array;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
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 []arr=new int[n];
for (int i = 0; i <n ; i++) {
arr[i]=2+i;
}
for (int i = 0; i < n; i++) {
System.out.print(arr[i]+" ");
}
System.out.println();
}
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | a3982fc9e9b182bf6123aea050d2ed1f | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
import java.io.*;
public class findArray {
static InputReader ir = new InputReader(System.in);
static PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args) {
int t = ir.nextInt();
for (int i = 0; i < t; i++) {
solve();
}
pw.close();
}
public static void solve() {
int n = ir.nextInt();
// ArrayList<Integer> a = new ArrayList<>();
if (n == 1) {
pw.println(1);
return;
}
for (int i = 2; i < n + 2; i++) {
pw.print(i + " ");
}
pw.println();
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
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 nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
public static int[] readArr(int N) {
int[] arr = new int[N];
for (int i = 0; i < N; i++) {
arr[i] = ir.nextInt();
}
return arr;
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 2944f67645156e90e267b1029388d938 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.Scanner;
public class findArray {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int noOfTests = sc.nextInt();
while(noOfTests-->0){
int n = sc.nextInt();
for (int k = 2; k <n+2; k++){
System.out.print(k+" ");
}
System.out.println();
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | fa8a60aa4fbfe146d47dab082170861a | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class findArray {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int noOfTests = sc.nextInt();
ArrayList<Integer> a = new ArrayList<>();
int i, j;
boolean flag;
for (i = 1; i < 10000; i++) {
if (i == 1)
continue;
flag = true;
for (j = 2; j <= i / 2; ++j) {
if (i % j == 0) {
flag = false;
break;
}
}
if (flag)
a.add(i);
}
while(noOfTests-->0){
int n = sc.nextInt();
for (int k = 0; k <n; k++){
System.out.print(a.get(k)+" ");
}
System.out.println();
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 5b0d12183bb68fac2e1df35f7c890a40 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class aa{
public static void main(String[] args){
FastReader sc = new FastReader();
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
for(int i=2;i<=n+1;i++) {
System.out.print(i+" ");
}
System.out.println();
}
}
static class pair {
int x;int y;
pair(int x,int y){
this.x=x;
this.y=y;
}
}
static void sort(int a[]) {
ArrayList<Integer> aa= new ArrayList<>();
for(int i:a)aa.add(i);
Collections.sort(aa);
int j=0;
for(int i:aa)a[j++]=i;
}
static ArrayList<Integer> primeFac(int n){
ArrayList<Integer>ans = new ArrayList<Integer>();
int lp[]=new int [n+1];
Arrays.fill(lp, 0); //0-prime
for(int i=2;i<=n;i++) {
if(lp[i]==0) {
for(int j=i;j<=n;j+=i) {
if(lp[j]==0) lp[j]=i;
}
}
}
int fac=n;
while(fac>1) {
ans.add(lp[fac]);
fac=fac/lp[fac];
}
print(ans);
return ans;
}
static ArrayList<Long> prime_in_given_range(long l,long r){
ArrayList<Long> ans= new ArrayList<>();
int n=(int)Math.sqrt(r)+1;
int prime[]=sieve_of_Eratosthenes(n);
long res[]=new long [(int)(r-l)+1];
for(int i=0;i<=r-l;i++) {
res[i]=i+l;
}
for(int i=0;i<prime.length;i++) {
if(prime[i]==1) {
System.out.println(2);
for(int j=Math.max((int)i*i, (int)(l+i-1)/i*i);j<=r;j+=i) {
res[j-(int)l]=0;
}
}
}
for(long i:res) if(i!=0)ans.add(i);
return ans;
}
static int [] sieve_of_Eratosthenes(int n) {
int prime[]=new int [n];
Arrays.fill(prime, 1); // 1-prime | 0-not prime
prime[0]=prime[1]=0;
for(int i=2;i<n;i++) {
if(prime[i]==1) {
for(int j=i*i;j<n;j+=i) {
prime[j]=0;
}
}
}
return prime;
}
static long binpow(long a,long b) {
long res=1;
if(b==0)return a;
if(a==0)return 1;
while(b>0) {
if((b&1)==1) {
res*=a;
}
a*=a;
b>>=1;
}
return res;
}
static void print(int a[]) {
System.out.println(a.length);
for(int i:a) {
System.out.print(i+" ");
}
System.out.println();
}
static void print(long a[]) {
System.out.println(a.length);
for(long i:a) {
System.out.print(i+" ");
}
System.out.println();
}
static void print(ArrayList<Integer> a) {
System.out.println(a.size());
for(long i:a) {
System.out.print(i+" ");
}
System.out.println();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
int [] fastArray(int n) {
int a[]=new int [n];
for(int i=0;i<n;i++) {
a[i]=nextInt();
}
return a;
}
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 | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | e291413980b9453e54e1b159f0a86656 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.Scanner;
public class make {
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];
int count=2;
arr[0]=2;
for(int j=0; j<n-1; j++){
int i1 = arr[j + 1] - arr[j];
if(i1 >0){
arr[j+1]=count;
count++;
}
else if(i1 ==0){
count+=2;
arr[j+1]=count;
}
else {
count++;
arr[j+1]=count;
}
}
for(int k=0; k<n; k++){
System.out.print(arr[k] + " ");
}
System.out.println();
}
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 581afb678115e845759578b3c189edfa | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
public class HelloWorld {
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();
for(int j = 2; j <= n + 1; j++){
System.out.print(j + " ");
}
System.out.println();
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 28dfbc7c742ae8e1d1668e723235bbb8 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.io.*;
import java.util.*;
public class RoughW2 {
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int t = 1; t<=T; t++) {
int N = sc.nextInt();
for(int i = 2; i<=N+1; i++) {
System.out.print(i+" ");
} System.out.println();
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | e02f4e7b9eaaef6f9bb81027abde7929 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner go = new Scanner(System.in);
int t = go.nextInt();
while (t-->0){
int n = go.nextInt();
int[] a = new int[n];
for (int i = 0; i<n;i++){
a[i] = i+2;
}
// a[n-1] = 1;
for (int i=0; i<n; i++){
System.out.print(a[i] + " ");
}
System.out.println();
}
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 6f7b5256da1c4ba8592c90d3dbcc1874 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes |
// * * * the goal is to be worlds best * * * //
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;
}
}
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
for(int i = 2; i <= n + 1; i++){
System.out.print(i + " ");
}
System.out.println();
}
}
static long sum(long n){
long temp = n;
long sum = 0;
while(temp > 0){
sum += temp % 10;
temp /= 10;
}
return sum;
}
// Use this instead of Arrays.sort() on an array of ints. Arrays.sort() is n^2
// worst case since it uses a version of quicksort. Although this would never
// actually show up in the real world, in codeforces, people can hack, so
// this is needed.
static void ruffleSort(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);
}
// Use this to input code since it is faster than a Scanner
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());
}
}
// use this to find the index of any element in the array +1 ///
// returns an array that corresponds to the index of the i+1th in the array a[]
// runs only for array containing different values enclosed btw 0 to n-1
static int[] indexOf(int[] a) {
int[] toRet=new int[a.length];
for (int i=0; i<a.length; i++) {
toRet[a[i]]=i+1;
}
return toRet;
}
static long gcd(long n, long l) {
if (l==0) return n;
return gcd(l, n%l);
}
//generates all the prime numbers upto n
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 = 100000000 + 7;
static final int max_val = 2147483647;
static final int min_val = max_val + 1;
//fastPow
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));
}
//multiply two long numbers
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));
}
// Returns factorial of n
static int fact(int n)
{
int res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
// to generate the lps array
// lps means longest preffix that is also a suffix
static void generateLPS(int lps[] , String p){
int l = 0;
int r = 1;
while(l < p.length() && l < r && r < p.length()){
if(p.charAt(l) == p.charAt(r)){
lps[r] = l + 1;
l++;
r++;
}
else{
if(l > 0)
l = lps[l - 1];
else
r++;
}
}
}
//count sort --> it runs in O(n) time but compromises in space
static ArrayList<Integer> countSort(int a[]){
int max = Integer.MIN_VALUE;
for(int i=0;i<a.length;i++){
max = Math.max(max , a[i]);
}
int posfre[] = new int[max+1];
boolean negPres = false;
for(int i=0;i<a.length;i++){
if(a[i]>=0){
posfre[a[i]]++;
}
else{
negPres = true;
}
}
ArrayList<Integer> res = new ArrayList<>();
if(negPres){
int min = Integer.MAX_VALUE;
for(int i=0;i<a.length;i++){
min = Math.min(min , a[i]);
}
int negfre[] = new int[-1*min+1];
for(int i=0;i<a.length;i++){
if(a[i]<0){
negfre[-1*a[i]]++;
}
}
for(int i=min;i<0;i++){
for(int j=0;j<negfre[-1*i];j++){
res.add(i);
}
}
for(int i=0;i<=max;i++){
for(int j=0;j<posfre[i];j++){
res.add(i);
}
}
return res;
}
for(int i=0;i<=max;i++){
for(int j=0;j<posfre[i];j++){
res.add(i);
}
}
return res;
}
// returns the index of the element which is just smaller than or
// equal to the tar in the given arraylist
static int lowBound(ArrayList<Integer> ll,long tar ,int l,int r){
if(l>r) return l;
int mid=l+(r-l)/2;
if(ll.get(mid)>=tar){
return lowBound(ll,tar,l,mid-1);
}
return lowBound(ll,tar,mid+1,r);
}
// returns the index of the element which is just greater than or
// equal to the tar in the given arraylist
static int upBound(ArrayList<Integer> ll,long tar,int l ,int r){
if(l>r) return l;
int mid=l+(r-l)/2;
if(ll.get(mid)<=tar){
return upBound(ll,tar,l,mid-1);
}
return upBound(ll,tar,mid+1 ,r);
}
static void swap(int i , int j , int a[]){
int x = a[i];
int y = a[j];
a[j] = x;
a[i] = y;
}
// a -> z == 97 -> 122
// String.format("%.9f", ans) ,--> to get upto 9 decimal places , (ans is double)
// write
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 40b99f534b66c6d6bc041a3e9cabb75e | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 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.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
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 BufferedReader in;
static PrintWriter out;
static StringTokenizer tok;
static int mod= (int)1e9+1;
static boolean isPrime[];
private static void solve() throws IOException{
int n = scanInt();
for(int i = 1; i<=n; ++i){
out.print((i+1)+" ");
}
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();
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | bffb4686e64834e9df57efd287605fd4 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
public class sbr{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t-->0){
int n=s.nextInt();
int count=2;
while(n-->0){
System.out.print(count+" ");
count++;
}
System.out.println();
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 5c7a91b2ef210e80f24044d1ac7c646d | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.Scanner;
public class A {
public static void main(String[] args) throws Exception {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
boolean[] prime = new boolean[1000006];
int n = prime.length-1;
for(int i=0;i<=n;i++)
prime[i] = true;
for(int p = 2; p*p <=n; p++)
{
if(prime[p] == true)
{
// Update all multiples of p
for(int i = p*p; i <= n; i += p)
prime[i] = false;
}
}
while(t --> 0 ){
int tot = s.nextInt();
int r=0;
int i=2;
while(r<tot){
if(prime[i]==true){
System.out.print(i+" ");
r++;
}
i++;
}
System.out.println("");
}
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | d2396cac01d3f7fa8a9fc99f290a67fa | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
new Main().run();
}
void run() {
try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
int count = Integer.parseInt(in.readLine());
int inNum;
for (int i = 0; i < count; i++) {
inNum = Integer.parseInt(in.readLine());
System.out.println(find(inNum));
}
} catch (IOException e) {
e.printStackTrace();
}
}
public StringBuilder find(int inNum) {
StringBuilder out = new StringBuilder();
int start = 1000000000;
for (int i = inNum - 1; i >= 0 ; i--) {
out.insert(0, start + " ");
start--;
}
return out;
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 38b365ac8479e9fac5bbccd6c8207b54 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
import java.lang.*;
public class Main
{
public static void main (String[] args) //throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt(),n;
while(t-- >0){
n=sc.nextInt();
int i=2;
for(;n>0;i++,n--)
System.out.print(i+" ");
System.out.println();
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | c9fab20f5220df6a5c8f4a0b1ed3dce0 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 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();
if(n==1){
System.out.print(1);
}
if(n>1){
for(int i=2;i<n+2;i++){
System.out.print(i+" ");
}
}
System.out.println();
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | c3839004f7066884dda8aef423541419 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < t; i++) {
int n = in.nextInt();
for (int j = 0, z = 2; j < n; j++, z++) {
sb.append(z);
if (j + 1 <= n) sb.append(" ");
}
sb.append("\n");
}
System.out.println(sb.toString());
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 2a602eb9760c221db030d184837a7254 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
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();
for(int j=1;j<=n;j++)
{
System.out.print((j+1)+" ");
}
System.out.println("");
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 29addb49175504c59c53f10df512c8be | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class div2 {
public static void main(String[] args) throws IOException {
Reader sc=new Reader();
int t=sc.nextInt();
boolean prime[] = new boolean[1000001];
for (int i = 0; i < prime.length; i++)
prime[i] = true;
for (int p = 2; p * p < prime.length; 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 <prime.length; i += p)
prime[i] = false;
}
}
ArrayList<Integer> ans=new ArrayList<>();
for (int i = 2; i < prime.length; i++)
{
if (prime[i] == true)
ans.add(i);
}
while(t-->0)
{
int n=sc.nextInt();
if(n==1)
{
System.out.println("1");
}
else
{
for(int i=0;i<ans.size();i++)
{
if(n==0)
{
break;
}
System.out.print(ans.get(i)+" ");
n--;
}
System.out.println();
}
}
}
}
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') {
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 | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 1fb4da5e8e691f329ec0c9f77188e0fe | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class contest {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
PrintWriter out=new PrintWriter(System.out);
while(t-->0){
int n = sc.nextInt();
int[] arr= new int[n];
//arr.add(0);
for(int j=0; j<n; j++){
arr[j] = j+2;
}
for (int i =0; i<n; i++){
out.print(arr[i]+" ");
}
out.println();
}
out.close();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public boolean hasNext() {return st.hasMoreTokens();}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public double nextDouble() throws IOException {return Double.parseDouble(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public boolean ready() throws IOException {return br.ready(); }
}}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 9c18c2ddefd58e6e6f5a9e8963bde483 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | //package contests;
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.math.*;
import java.io.*;
public class javaTemplate {
public static final int M = 1000000007 ;
public static BigInteger f1 = new BigInteger("1000000007") ;
static FastReader sc = new FastReader();
static int N = 86028121 ;
static boolean globB[] = new boolean[N+1] ;
static int globA[] = new int[10000000] ;
public static void main(String[] args) {
int t = sc.nextInt() ;
while(t -- != 0) {
int n = sc.nextInt() ;
int x = 2 ;
for(int i = 0 ; i< n ; i++) {
System.out.print(x + " ");
x ++ ;
}
System.out.println();
}
}
// public ArrayList <Integer> boundary(Node node) {
// Node temp = node ;
// ArrayList<Integer> ans = new ArrayList<>() ;
// ArrayList<Integer> x = new ArrayList<>() ;
// while(true) {
// if(temp.left != null) {
// ans.add(temp.val) ;
// temp = temp.left ;
// } else if(temp.right != null) {
// ans.add(temp.val) ;
// temp = temp.right ;
// } else {
// break ;
// }
// }
// temp = node ;
// while(true) {
// if(temp.left == null && temp.right == null) {
//
// }
// }
// return ans ;
// }
public class ListNode {
int val;
ListNode next;
ListNode() {}
ListNode(int val) { this.val = val; }
ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
// Tree class
static class Node {
int val ;
Node left ;
Node right ;
Node(int val) {
this.val = val ;
}
}
/*
@ Observation is imp. for problem A and B
1->> Read the problem properly take time to read the problem
if it is too lengthy.
2->> Draw the test cases of A and B
3->> Don't over think the problem
4->> Try to take sum variable as long
5->> Avoid Nested if else statement
6->> If it looks like a Greedy problem try to figure out the ans.
for the smallest test case.
7->> If it is a binary String check no. of 0's and 1's.
If it is a even try to pair it (may be not applicable for every questions).
8->> Always check the constrains and try BruteForce
9->> Sometimes math formulas are also imp.
@ Implement it quickly
*/
//_________________________//Template//_____________________________________________________________________
// FAST I/O
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;
}
}
// Sorting
public static void sort(long[] arr) {
ArrayList<Long> ls = new ArrayList<Long>();
for(long x: arr)
ls.add(x);
Collections.sort(ls);
for(int i=0; i < arr.length; i++)
arr[i] = ls.get(i);
}
// Modulo
static int mod(int a) {
return (a%M+M)%M;
}
// **Using Comparator for Sorting**
// Arrays.sort(a, new Comparator<long[]>() {
// @Override
// public int compare(long[] o1, long[] o2) {
// return (int)(o2[1] - o1[1]);
// }
// });
// Palindrom or Not
static boolean isPalindrome(String str, int low, int high) {
while (low < high) {
if (str.charAt(low) != str.charAt(high)) return false;
low++;
high--;
}
return true;
}
// check if sorted or not
public static boolean isSorted(int[] a)
{
for (int i = 0; i < a.length - 1; i++)
{
if (a[i] > a[i + 1]) {
return false;
}
}
return true;
}
// GCD
public static int GCD(int a , int b) {
if(b == 0) return a ;
return GCD(b, a%b) ;
}
// sieve
public static void sieve() {
Arrays.fill(globB, true);
globB[0] = false ;
globB[1] = false ;
for(int i = 2 ; i * i <= N ; i++) {
if(globB[i]) {
for(int j = i * i ; j<= N ; j+= i) {
globB[j] = false ;
}
}
}
}
// fastPower
public static long fastPowerModulo(long a, long b, long n) {
long res = 1 ;
while(b > 0) {
if((b&1) != 0) {
res = (res * a % n) % n ;
}
a = (a % n * a % n) % n ;
b = b >> 1 ;
}
return res ;
}
// LCM
static int LCM(int a, int b)
{
return (a / GCD(a, b)) * b;
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | a1f980f1337c3b0d124f95d9e7cf3ea2 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int t = Integer.parseInt(br.readLine());
for(; t>0; t--){
int n = Integer.parseInt(br.readLine().trim());
for(int i=1; i<=n; i++) {
sb.append(i+1 + " ");
} sb.append('\n');
}
System.out.println(sb);
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 62e12713e0990bd8819a3dbc7a8d5bc8 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | /*package whatever //do not write package name here */
import java.util.*;
public class GFG {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
if(n==1)
{
System.out.println(1);
}
else{
for(int i=2;i<=n+1;i++){
System.out.print(i+" ");
}
System.out.println();
}
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | cfaa6dfe2ee010d16ec71798971d5624 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes |
import java.util.*;
import java.io.*;
public class CF758A {
public static void main(String[] args) {
FastReader fastReader = new FastReader();
int t = fastReader.nextInt();//test cases count
while(t-->0) {
int n = fastReader.nextInt();
if(n==1) {
System.out.println("1");
} else if(n==2) {
System.out.println("2 3");
} else {
findResult(n);
}
}
}
static void findResult(int n) {
long s=2;
while(n-->0) {
System.out.print(s+" ");
s+=1;
}
System.out.println();
}
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 | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 5b5fa56bc8d026187614a8792e27ad09 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.io.*;
import java.lang.*;
public class problemA{
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
StringBuilder sb=new StringBuilder();
while(t-->0){
String s=br.readLine();
int n;
if(s.equals("one"))
n=1;
else
n=Integer.parseInt(s);
int[]arr=new int[n];
StringBuilder sb1=new StringBuilder();
for(int i=0;i<n;i++){
arr[i]=i+2;
sb1.append(arr[i]);
if(i!=n-1)
sb1.append(" ");
}
sb.append(sb1.toString()+"\n");
}
System.out.println(sb);
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | c35ef93965f890b324d32dc3643787d4 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.io.*;
import java.util.*;
public class CF_748_1 {
public static void main(String[] args){
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
//int[] arr = new int [n];
for(int i = 2; i <= n+1; i++){
System.out.print(i + " ");
}
System.out.println();
}
}
}
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 | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | d73c5d82ac5ffa485bc36bdf82dd2dd5 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
public class pr1{
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();
for(int j=2;j<=n+1;j++){
System.out.print(j+" ");
}
System.out.println("");
}
}
}
/**
*/ | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 3946540494413e9908a50e7e3fe3e016 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
import java.io.*;
public class A_Find_Array{
public static void main(String[] args) throws Exception {
FastReader scan = new FastReader(System.in);
int testCases = scan.nextInt();
while(testCases-->0){
int size = scan.nextInt();
for(int i = 2;i<=size+1;i++){
System.out.print(i+" ");
}
System.out.println();
}
}
static class FastReader{
byte[] buf = new byte[2048];
int index, total;
InputStream in;
FastReader(InputStream is) {
in = is;
}
int scan() throws IOException {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) {
return -1;
}
}
return buf[index++];
}
String next() throws IOException {
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();
}
int nextInt() throws IOException {
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;
}
long nextLong() throws IOException {
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;
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 28fb485db786a6a55997253bee75fd83 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
import java.math.*;
public class Main {
static int mod = 1000000007;
/*****************code By Priyanshu *******************************************/
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;
}
}
// this > other return +ve
// this < other return -ve
// this == other return 0
public static class Pair implements Comparable<Pair> {
long st;
long et;
public Pair(long st, long et) {
this.st = st;
this.et = et;
}
public int compareTo(Pair other) {
if (this.st != other.st) {
return (int)(this.st - other.st);
} else {
return (int)(this.et - other.et);
}
}
}
static long fastPower(long a, long b, int n) {
long res = 1;
while ( b > 0) {
if ( (b&1) != 0) {
res = (res * a % n) % n;
}
a = (a % n * a % n) % n;
b = b >> 1;
}
return res;
}
// function to find
// the rightmost set bit
static int PositionRightmostSetbit(int n)
{
// Position variable initialize
// with 1 m variable is used to
// check the set bit
int position = 1;
int m = 1;
while ((n & m) == 0) {
// left shift
m = m << 1;
position++;
}
return position;
}
// used for swapping ith and jth elements of array
// public static void swap(int[] arr, int i, int j) {
// int temp = arr[i];
// arr[i] = arr[j];
// arr[j] = temp;
// }
public static void swap(long i, long j) {
long temp = i;
i = j;
j = temp;
}
static boolean palindrome(String s) {
return new StringBuilder(s).reverse().toString().equals(s);
}
static boolean isPerfectSquare(double x)
{
double sr = Math.sqrt(x);
return ((sr * sr) == x);
}
public static long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static int nod(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>=1000000000) return 10;
if(l>=100000000) return 9;
if(l>=10000000) return 8;
if(l>=1000000) return 7;
if(l>=100000) return 6;
if(l>=10000) return 5;
if(l>=1000) return 4;
if(l>=100) return 3;
if(l>=10) return 2;
return 1;
}
//Arrays.sort(a,(c,d) -> Integer.compare(c[0],d[0]));
public static boolean areAllBitsSet(int n )
{
// all bits are not set
if (n == 0)
return false;
// if true, then all bits are set
if (((n + 1) & n) == 0)
return true;
// else all bits are not set
return false;
}
public static long[] sort(long[] arr) {
List<Long> temp = new ArrayList();
for (long i : arr) temp.add(i);
Collections.sort(temp);
int start = 0;
for (long i : temp) arr[start++] = i;
return arr;
}
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;
}
public static void print( int arr[] ){
Arrays.stream(arr).forEach(str -> System.out.print(str + " "));
}
static boolean isPowerOfTwo (int x)
{
/* First x in the below expression is
for the case when x is 0 */
return x!=0 && ((x&(x-1)) == 0);
}
static class Help {
int index;
int val;
int res ;
//Constructor
Help(int i, int v) {
index = i;
val = v;
res = 0;
}
}
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 sc = new FastReader();
int t = Integer.parseInt(sc.next());
// int t = 1;
// StringBuilder ans = new StringBuilder();
// ArrayList<Integer> a = new ArrayList<>();
while(t-->0){
int n = sc.nextInt();
int a[] = new int[n];
int i = 0;
int val = 2;
while(i < n){
// if(i%2 == 0){
// a[i] = 2;
// }else{
// a[i] = 7;
// }
a[i] = val;
val++;
i++;
}
for(int j : a){
System.out.print(j+ " ");
}
System.out.println();
}
}
}
//code By Priyanshu
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | c1270b198cc14f1f88a1346b2e8782f1 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.io.*;
public class MyClass {
public static void main(String args[])throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t-->0){
String s="";
int n=Integer.parseInt(br.readLine());
for(int i=1;i<=n;i++){
s+=""+(i+1)+" ";
}
System.out.println(s.trim());
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 4332721f093cd33577119f02dbabc62e | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | /* JAIKARA SHERAWAALI DA BOLO SACHE DARBAR KI JAI
HAR HAR MAHADEV JAI BHOLENAATH
Rohit Kumar
NIT JAMSHEDPUR
*/
import java.util.*;
import java.io.*;
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.hasMoreTokens()){
try{
st=new StringTokenizer(br.readLine());
}
catch(IOException e){
e.printStackTrace();
}
}
return st.nextToken();}
long nextLong(){ return Long.parseLong(next());}
int nextInt(){ return Integer.parseInt(next());}
}
static <t>void print(t o){
System.out.println(o);
}
static boolean islapindrome(String s){
int fhalf[]=new int[26];
int shalf[]=new int[26];
int i=0,j=s.length()-1;
while(i<j){
fhalf[s.charAt(i)-'a']++;
shalf[s.charAt(j)-'a']++;
i++;
j--;
}
for(int k=0;k<26;k++){
if(fhalf[k]!=shalf[k])return false;
}
return true;
}
static int mod=(int)1e9+7;
static String text="foo";
public static void main (String args[]) throws IOException{
try{
System.setIn(new FileInputStream("input.txt"));
System.setOut(new PrintStream(new FileOutputStream("output.txt"))); }
catch (Exception e) {
System.err.println("Error");
}
FastReader sc=new FastReader();
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
if(n==1)
{
System.out.println(1);
continue;
}
long k=2;
for(int i=0;i<n;i++)
{
System.out.print(k+" ");
k++;
}
// int arr[]=new int[n];
// for(int i=0;i<n;i++)
// {
// arr[i]=sc.nextInt();
// }
System.out.println();
}
}
void sieveOfEratosthenes(int n)
{
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)
System.out.print(i + " ");
}
}
static long gcd(long a,long b)
{
if(b==0) return a;
return gcd(b,a%b);
}
static boolean isprime(int 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*i<=n;i=i+6)
{
if(n%i==0||n%(i+2)==0)
return false;
}
return true;
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 9f6ee508a9e09c371c6eec3e660b6aab | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes |
import java.util.*;
public class Codeforces {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
while(sc.hasNext()) {
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
StringBuilder ss = new StringBuilder();
ss.append(n +" ");
long val = n+1;
while(n-->1) {
ss.append(val +" ");
val++;
}
System.out.println(ss);
}
}
}
static void primeFactors(long n , ArrayList<Integer> al) {
while(n%2 == 0) {
al.add(2);
n = n/2;
}
for(int i = 3 ; i*i<= n;i+=2) {
while(n%i == 0) {
al.add(i);
n = n/i;
}
}
if(n>2) {
al.add((int) n);
}
}
static class Pair implements Comparable<Pair>{
int a;
int b;
Pair(int a, int b){
this.a = a;
this.b = b;
}
@Override
public int compareTo(Pair o) {
// TODO Auto-generated method stub
int temp = this.a - o.a;
if(temp == 0) {
return this.b - o.b;
}
else {
return temp;
}
}
}
static long gcd(long a , long b) {
if(b == 0) {
return a;
}
return gcd(b, a%b);
}
static boolean isPalindrome(int a[]) {
int i= 0;
int j = a.length - 1;
while(i<=j) {
if(a[i] != a[j]) {
return false;
}
i++;
j--;
}
return true;
}
static boolean isSubsequence(String a , String b) {
int i = 0 , j = 0;
while(i<a.length() && j<b.length()) {
if(a.charAt(i) == b.charAt(j)) {
i++;
j++;
}
else {
j++;
}
}
if(i == a.length()) {
return true;
}
return false;
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 9a0e26fd2141720128cdd14bac5f2ad1 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.Scanner;
public class MainT {
public static Scanner read = new Scanner(System.in);
public static void main(String[] args) {
int t = read.nextInt();
while (t-->0) {
solve();
}
}
private static void solve() {
int n = read.nextInt();
long s = 2;
for (int i = 0; i < n; i++) {
System.out.println(s);
s = s+1;
}
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | b80258161c5feff740cb51941cabe8de | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*; import java.io.*; import java.math.*;
public class Main{
//見なくていいよ ここから------------------------------------------
static class InputIterator{
ArrayList<String> inputLine = new ArrayList<>(buf);
int index = 0; int max; String read;
InputIterator(){
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try{
while((read = br.readLine()) != null){
inputLine.addAll(Arrays.asList(read.split(" ")));
}
}catch(IOException e){}
max = inputLine.size();
}
boolean hasNext(){return (index < max);}
String next(){
if(hasNext()){
return inputLine.get(index++);
}else{
throw new IndexOutOfBoundsException("There is no more input");
}
}
}
//入力バッファサイズのつもり。入力点数(スペース区切りでの要素数)が100万を超える場合はバッファサイズを100万にすること
static int buf = 1024;
static HashMap<Integer, String> CONVSTR = new HashMap<>();
static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
static PrintWriter out = new PrintWriter(System.out);
static void flush(){out.flush();}
static void myout(Object t){out.println(t);}
static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
static String next(){return ii.next();}
static boolean hasNext(){return ii.hasNext();}
static int nextInt(){return Integer.parseInt(next());}
static long nextLong(){return Long.parseLong(next());}
static double nextDouble(){return Double.parseDouble(next());}
static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
static ArrayList<String> nextStrArray(int size){
ArrayList<String> ret = new ArrayList<>(size);
for(int i = 0; i < size; i++){
ret.add(next());
}
return ret;
}
static ArrayList<Integer> nextIntArray(int size){
ArrayList<Integer> ret = new ArrayList<>(size);
for(int i = 0; i < size; i++){
ret.add(Integer.parseInt(next()));
}
return ret;
}
static ArrayList<Long> nextLongArray(int size){
ArrayList<Long> ret = new ArrayList<>(size);
for(int i = 0; i < size; i++){
ret.add(Long.parseLong(next()));
}
return ret;
}
@SuppressWarnings("unchecked")
static String myconv(Object list, int no){//only join
StringBuilder sb = new StringBuilder("");
String joinString = CONVSTR.get(no);
if(list instanceof String[]){
return String.join(joinString, (String[])list);
}else if(list instanceof long[]){
long[] tmp = (long[])list;
if(tmp.length == 0){
return "";
}
sb.append(String.valueOf(tmp[0]));
for(int i = 1; i < tmp.length; i++){
sb.append(joinString).append(String.valueOf(tmp[i]));
}
return sb.toString();
}else if(list instanceof int[]){
int[] tmp = (int[])list;
if(tmp.length == 0){
return "";
}
sb.append(String.valueOf(tmp[0]));
for(int i = 1; i < tmp.length; i++){
sb.append(joinString).append(String.valueOf(tmp[i]));
}
return sb.toString();
}else if(list instanceof ArrayList){
ArrayList tmp = (ArrayList)list;
if(tmp.size() == 0){
return "";
}
sb.append(tmp.get(0));
for(int i = 1; i < tmp.size(); i++){
sb.append(joinString).append(tmp.get(i));
}
return sb.toString();
}else{
throw new ClassCastException("Don't join");
}
}
static ArrayList<String> myconv(String str, int no){//only split
String splitString = CONVSTR.get(no);
return new ArrayList<String>(Arrays.asList(str.split(splitString)));
}
static ArrayList<String> myconv(String str, String no){
return new ArrayList<String>(Arrays.asList(str.split(no)));
}
public static void main(String[] args){
CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
solve();flush();
}
//見なくていいよ ここまで------------------------------------------
//このコードをコンパイルするときは、「-encoding UTF-8」を指定すること
static void solve(){//ここがメイン関数
int t = nextInt();
TreeSet<Integer> set = new TreeSet<>(sieveOfEratos(100000));
while(hasNext()){
int N = nextInt();
ArrayList<Integer> list = new ArrayList<>();
for(int a : set){
if(list.size() < N){
list.add(a);
}else{
break;
}
}
myout(myconv(list, 8));
}
}
//メソッド追加エリア ここから
static HashSet<Integer> sieveOfEratos(int val){
HashSet<Integer> primes = new HashSet<>();
HashSet<Integer> nums = new HashSet<>();
int[] used = {2, 3, 5, 7, 11};
int underPrime = 13;
if(val <= 1){
return nums;
}
for(int i = 0; i < used.length; i++){
if(used[i] <= val){
nums.add(used[i]);
}
}
for(int i = underPrime; i <= val; i += 2){
boolean continued = false;
for(int j = 0; j < used.length; j++){
if(i % used[j] == 0){
continued = true;
break;
}
}
if(continued){
continue;
}
nums.add(i);
}
int i = 2;
while(i <= Math.sqrt(val)){
if(!nums.contains(i)){
if(i == 2){
i++;
}else{
i += 2;
}
continue;
}
int count = 1;
while(i * count <= val){
if(i <= 11 && Arrays.asList(used).contains(i)){
break;
}
if(count == 1){
primes.add(i);
}
nums.remove(i * count);
count++;
}
if(i == 2){
i++;
}else{
i += 2;
}
}
Iterator<Integer> it = primes.iterator();
while(it.hasNext()){
nums.add(it.next());
}
return nums;
}
//メソッド追加エリア ここまで
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 3ac826e25576abf6a8259e63ec04ce06 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Gp {
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 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') {
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();
}
}
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Reader s=new Reader();
//FastReader s=new FastReader();
int t=s.nextInt();
for(int i=0;i<t;i++) {
int n=s.nextInt();
for(int j=1;j<=n;j++) {
System.out.print((j+1)+" ");
}
System.out.println();
}
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 662a484a3ca0811d2f129c04b7f70ff3 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | // HOPE
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////// //////////
/////// //////////
/////// RRRRRRRRRRRRR YY YY AA NN NN //////////
/////// RR RR YY YY AA AA NN NN NN //////////
/////// RR RR YY YY AA AA NN NN NN //////////
/////// RRRRRRRRRR YY YY AAAAAAAAAAAA NN NN NN //////////
/////// RR RR YY AAAAAAAAAAAAAA NN NN NN //////////
/////// RR RR YY AA AA NN NN NN //////////
/////// RR RR YY AA AA NN NN //////////
/////// RR RR_____________________________________________________________________________ //////////
//////// //////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.math.*;
public class Codeforces1 {
static PrintWriter out = new PrintWriter(System.out);
static final int mod=1_000_000_007;
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[] readIntArray(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());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//Try seeing general case
public static void main(String[] args) {
FastReader s = new FastReader();
int t = s.nextInt();
while(t-->0)
{
int n = s.nextInt();
int i=3;
int count = 0;
while(count!=n)
{
out.print(i+" ");
i+=2;
count++;
}
out.println();
}
out.close();
}
public static void find()
{
}
/////////////////////////////////////////////////THE END///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static int gcd(int x,int y)
{
return y==0?x:gcd(y,x%y);
}
public static long gcd(long x,long y)
{
return y==0L?x:gcd(y,x%y);
}
public static int lcm(int a, int b) {
return (a * b) / gcd(a, b);
}
public static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
public static long pow(long a,long b)
{
if(b==0L)
return 1L;
long tmp=1;
while(b>1L)
{
if((b&1L)==1)
tmp*=a;
a*=a;
b>>=1;
}
return (tmp*a);
}
public static long modPow(long a,long b,long mod)
{
if(b==0L)
return 1L;
long tmp=1;
while(b>1L)
{
if((b&1L)==1L)
tmp*=a;
a*=a;
a%=mod;
tmp%=mod;
b>>=1;
}
return (tmp*a)%mod;
}
static long mul(long a, long b) {
return a*b%mod;
}
static long fact(int n) {
long ans=1;
for (int i=2; i<=n; i++) ans=mul(ans, i);
return ans;
}
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 void debug(int ...a)
{
for(int x: a)
out.print(x+" ");
out.println();
}
static void debug(long ...a)
{
for(long x: a)
out.print(x+" ");
out.println();
}
static void debugMatrix(int[][] a)
{
for(int[] x:a)
out.println(Arrays.toString(x));
}
static void debugMatrix(long[][] a)
{
for(long[] x:a)
out.println(Arrays.toString(x));
}
static void reverseArray(int[] a) {
int n = a.length;
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
static void reverseArray(long[] a) {
int n = a.length;
long[] arr = new long[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
static void sort(int[] a)
{
ArrayList<Integer> ls = new ArrayList<>();
for(int x: a) ls.add(x);
Collections.sort(ls);
for(int i=0;i<a.length;i++)
a[i] = ls.get(i);
}
static void sort(long[] a)
{
ArrayList<Long> ls = new ArrayList<>();
for(long x: a) ls.add(x);
Collections.sort(ls);
for(int i=0;i<a.length;i++)
a[i] = ls.get(i);
}
static class Pair{
int x, y;
Pair(int x, int y)
{
this.x = x;
this.y = y;
}
@Override
public String toString() {
return "Pair{" +
"x=" + x +
", y=" + y +
'}';
}
}
static class MyCmp implements Comparator<Pair>
{
public int compare(Pair p1, Pair p2)
{
return p1.x-p2.x;
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 07238a315269a89bfe1b2a3bf88ce1a4 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
import java.io.*;
public class Main {
// Graph
// prefix sums
//inputs
public static void main(String args[])throws Exception{
Input sc=new Input();
precalculates p=new precalculates();
StringBuilder sb=new StringBuilder();
int t=sc.readInt();
for(int f=0;f<t;f++){
int n=sc.readInt();
for(int i=0;i<n;i++){
sb.append(i+2+" ");
}
sb.append("\n");
}
System.out.print(sb);
}
}
class Input{
BufferedReader br;
StringTokenizer st;
Input(){
br=new BufferedReader(new InputStreamReader(System.in));
st=new StringTokenizer("");
}
public int[] readArray() throws Exception{
st=new StringTokenizer(br.readLine());
int a[]=new int[st.countTokens()];
for(int i=0;i<a.length;i++){
a[i]=Integer.parseInt(st.nextToken());
}
return a;
}
public long[] readArrayLong() throws Exception{
st=new StringTokenizer(br.readLine());
long a[]=new long[st.countTokens()];
for(int i=0;i<a.length;i++){
a[i]=Long.parseLong(st.nextToken());
}
return a;
}
public int readInt() throws Exception{
st=new StringTokenizer(br.readLine());
return Integer.parseInt(st.nextToken());
}
public long readLong() throws Exception{
st=new StringTokenizer(br.readLine());
return Long.parseLong(st.nextToken());
}
public String readString() throws Exception{
return br.readLine();
}
public int[][] read2dArray(int n,int m)throws Exception{
int a[][]=new int[n][m];
for(int i=0;i<n;i++){
st=new StringTokenizer(br.readLine());
for(int j=0;j<m;j++){
a[i][j]=Integer.parseInt(st.nextToken());
}
}
return a;
}
}
class precalculates{
public int[] prefixSumOneDimentional(int a[]){
int n=a.length;
int dp[]=new int[n];
for(int i=0;i<n;i++){
if(i==0)
dp[i]=a[i];
else
dp[i]=dp[i-1]+a[i];
}
return dp;
}
public int[] postSumOneDimentional(int a[]) {
int n = a.length;
int dp[] = new int[n];
for (int i = n - 1; i >= 0; i--) {
if (i == n - 1)
dp[i] = a[i];
else
dp[i] = dp[i + 1] + a[i];
}
return dp;
}
public int[][] prefixSum2d(int a[][]){
int n=a.length;int m=a[0].length;
int dp[][]=new int[n+1][m+1];
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
dp[i][j]=a[i-1][j-1]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
}
}
return dp;
}
public long pow(long a,long b){
long mod=1000000007;
long ans=0;
if(b<=0)
return 1;
if(b%2==0){
ans=pow(a,b/2)%mod;
return ((ans%mod)*(ans%mod))%mod;
}else{
return ((a%mod)*(ans%mod))%mod;
}
}
}
class GraphInteger{
HashMap<Integer,vertex> vtces;
class vertex{
HashMap<Integer,Integer> children;
public vertex(){
children=new HashMap<>();
}
}
public GraphInteger(){
vtces=new HashMap<>();
}
public void addVertex(int a){
vtces.put(a,new vertex());
}
public void addEdge(int a,int b,int cost){
if(!vtces.containsKey(a)){
vtces.put(a,new vertex());
}
if(!vtces.containsKey(b)){
vtces.put(b,new vertex());
}
vtces.get(a).children.put(b,cost);
// vtces.get(b).children.put(a,cost);
}
public boolean isCyclicDirected(){
boolean isdone[]=new boolean[vtces.size()+1];
boolean check[]=new boolean[vtces.size()+1];
for(int i=1;i<=vtces.size();i++) {
if (!isdone[i] && isCyclicDirected(i,isdone, check)) {
return true;
}
}
return false;
}
private boolean isCyclicDirected(int i,boolean isdone[],boolean check[]){
if(check[i])
return true;
if(isdone[i])
return false;
check[i]=true;
isdone[i]=true;
Set<Integer> set=vtces.get(i).children.keySet();
for(Integer ii:set){
if(isCyclicDirected(ii,isdone,check))
return true;
}
check[i]=false;
return false;
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 614b30175c93e29b8a6ff45342b5f505 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import com.sun.security.jgss.GSSUtil;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class javacp{
static FastReader fs=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;
}
int[] inputIntArray(int n){
int[] arr = new int[n];
for(int i=0;i<n;i++)
arr[i] = fs.nextInt();
return arr;
}
}
static void sort(int[] arr){
ArrayList<Integer> al = new ArrayList<>();
for(int val : arr){
al.add(val);
}
Collections.sort(al);
for(int i=0;i<arr.length;i++){
arr[i] = al.get(i);
}
}
static class Pair implements Comparable<Pair>{
int src;
int dest;
long wt;
Pair(int src,int dest,long wt){
this.src = src;
this.dest = dest;
this.wt = wt;
}
public int compareTo(Pair pair){
if(this.wt > pair.wt)
return 1;
else if(this.wt < pair.wt)
return -1;
else
return 0;
}
}
static int[] par1 , rank1 , size;
static int[] par2;
static int[] rank2;
static boolean union1(int vt1 , int vt2){
int parent1 = findParent1(vt1) , parent2 = findParent1(vt2);
int r1 = rank1[parent1] , r2 = rank1[parent2];
if(parent1 == parent2) return false;
if(r1 < r2) {
par1[parent1] = parent2;
size[parent2] += size[parent1];
}
else{
par1[parent2] = parent1;
size[parent1] += size[parent2];
}
if(r1 == r2) rank1[parent1]++;
return true;
}
static void union2(int vt1 , int vt2){
int parent1 = findParent2(vt1) , parent2 = findParent2(vt2);
int r1 = rank2[parent1] , r2 = rank2[parent2];
if(parent1 == parent2) return;
if(r1 < r2)
par2[parent1] = parent2;
else par2[parent2] = parent1;
if(r1 == r2) rank2[parent1]++;
}
static int findParent1(int vt){
if(par1[vt] == vt) return vt;
par1[vt] = findParent1(par1[vt]);
return par1[vt];
}
static int findParent2(int vt){
if(par2[vt] == vt) return vt;
par2[vt] = findParent2(par2[vt]);
return par2[vt];
}
static void initialise1(int numOfVtces){
par1 = new int[numOfVtces];
rank1 = new int[numOfVtces];
size = new int[numOfVtces];
for(int i=0;i<numOfVtces;i++){
par1[i] = i;
rank1[i] = 1;
size[i] = 1;
}
}
static void initialise2(int numOfVtces){
par2 = new int[numOfVtces];
rank2 = new int[numOfVtces];
for(int i=0;i<numOfVtces;i++){
par2[i] = i;
rank2[i] = 0;
}
}
public static void main(String[] args) throws IOException{
int t = 1;
t = fs.nextInt();
while (t-- > 0) {
int n = fs.nextInt();
for(int i=1; i <= n; i++){
System.out.print((i+1)+" ");
}
System.out.println();
}
}
private static String generateABPattern(int a , int b){
StringBuilder sb = new StringBuilder();
while (a > 0 || b > 0){
if(b-a >= 2){
sb.append("bb");
if(a != 0){
sb.append("a");
a--;
}
b -= 2;
}
else if(a-b >= 2){
sb.append("aa");
if(b != 0){
sb.append("b");
b--;
}
a -= 2;
}
else if(a >= b){
sb.append("a");
a--;
}
else{
sb.append("b");
b--;
}
}
return sb.toString();
}
private static int binarySearch(int[] arr , int i , int j , int val){
while (i <= j){
int mid = (i+j)/2;
if(arr[mid] == val) return mid;
else if(arr[mid] > val) j = mid-1;
else i = mid+1;
}
return -1;
}
private static int lower_bound(int[] arr , int i, int j, int val){
int min = -1;
while (i <= j){
int mid = (i+j)/2;
if(arr[mid] > val) j = mid-1;
else{
min = mid;
i = mid+1;
}
}
return min;
}
private static int upper_bound(int[] arr, int i , int j , int val){
int min = -1;
while (i <= j){
int mid = (i+j)/2;
if(arr[mid] < val) i = mid+1;
else{
min = mid;
j = mid-1;
}
}
return min;
}
static int modInverse(int a, int m)
{
int m0 = m;
int y = 0, x = 1;
if (m == 1)
return 0;
while (a > 1) {
// q is quotient
int q = a / m;
int t = m;
// m is remainder now, process
// same as Euclid's algo
m = a % m;
a = t;
t = y;
// Update x and y
y = x - q * y;
x = t;
}
// Make x positive
if (x < 0)
x += m0;
return x;
}
static int mod = 1000000007;
static long power(long a,long b,long m) {
a %= m;
long res = 1;
while (b > 0) {
if ((b & 1) == 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
static class CustomSort implements Comparator<int[]> {
public int compare(int[] a, int[] b)
{
return a[0] - b[0];
}
}
static void printArr(int[] arr){
for(int i=0;i< arr.length;i++)
{
System.out.print(arr[i] + " ");
}
System.out.println();
}
private static int lcm(int a, int b) {
int gcd = gcd(a,b);
return (int)((long)a*(long)b)/gcd ;
}
private static int gcd(int a, int b) {
if(b == 0) return a;
else return gcd(b , a % b);
}
private static void swap(int[] arr, int start, int rand_pivot) {
int temp = arr[start];
arr[start] = arr[rand_pivot];
arr[rand_pivot] = temp;
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | a5e6a2d1084cf887ff310c518c625c04 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 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.StringTokenizer;
/**
*
* @author eslam
*/
public class JavaApplication916 {
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) throws IOException {
BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
FastReader input = new FastReader();
int t = input.nextInt();
for (int j = 0; j < t; j++) {
int n = input.nextInt();
int x = 2;
for (int i = 0; i < n; i++) {
log.write(x + " ");
x += 3;
}
log.write("\n");
}
log.flush();
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 7f645aeafc32730470554f3ff7e3e8f7 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes |
import java.io.*;
import java.math.*;
import java.util.*;
// @author : Dinosparton
public class test {
static class Pair{
long x;
long y;
Pair(long x,long y){
this.x = x;
this.y = y;
}
}
static class Duo{
int x;
String s;
Duo(int x,String s){
this.x = x;
this.s = s;
}
}
static class Sort implements Comparator<Pair>
{
@Override
public int compare(Pair a, Pair b)
{
if(a.x!=b.x)
{
return (int)(a.x - b.x);
}
else
{
return (int)(a.y-b.y);
}
}
}
static class Compare {
void compare(Pair arr[], int n)
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{
if(p1.x!=p2.x) {
return (int)(p1.x - p2.x);
}
else {
return (int)(p1.y - p2.y);
}
}
});
// for (int i = 0; i < n; i++) {
// System.out.print(arr[i].x + " " + arr[i].y + " ");
// }
// System.out.println();
}
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner()
{
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[]) throws Exception {
Scanner sc = new Scanner();
StringBuilder res = new StringBuilder();
int tc = sc.nextInt();
while(tc-->0) {
int n = sc.nextInt();
for(int i=1;i<=n;i++) {
res.append((i+1)+" ");
}
res.append("\n");
}
System.out.println(res);
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | c03ad76725203e79b6e1ee426bcc58b0 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
// ArrayList<Integer> al = new ArrayList<>();
// ArrayList<Pair<Integer, Integer>> al = new ArrayList<>();
// Set<Integer> set = new TreeSet<>();
// Pair<Integer, Integer> pair;
// Map<Integer, Integer> map = new HashMap<>();
// LinkedList<Integer> ll = new LinkedList<>();
// for(Map.Entry<Integer,Integer> e:map.entrySet())pn(e.getKey()+"
// "+e.getValue());
// map.put(key,map.getOrDefault(key,0)+1);
// ****************** Code Begins From Here******************************
public static void solve() {
int n = c.i(), a[] = new int[n];
for (int i = 0; i < n; i++)
a[i] = (i + 2);
watch(a);
}
public static void main(String[] args) throws FileNotFoundException {
c = new FastScanner();
pw = new PrintWriter(System.out);
int tc = 1;
tc = c.i();
long start = System.currentTimeMillis();
for (int t = 0; t < tc; t++) {
// p("Case #" + (t + 1) + ": ");
solve();
}
long end = System.currentTimeMillis();
if (System.getProperty("os.name").equals("Mac OS X")) {
pn("The Program takes " + (end - start) + "ms");
}
pw.close();
}
// math util
private static int lower(int a[], int x) {
int l = 0, r = a.length - 1, mid, ans = -1;
while (l <= r) {
mid = l + ((r - l) >> 1);
if (a[mid] <= x) {
ans = max(ans, mid);
l = mid + 1;
} else
r = mid - 1;
}
return ans;
}
private static int cei(double d) {
return (int) Math.ceil(d);
}
private static long ceil(double d) {
return (long) Math.ceil(d);
}
private static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
private static long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
private static int abs(int a, int b) {
return (int) Math.abs(a - b);
}
private static int abs(int a) {
return (int) Math.abs(a);
}
private static long abs(long a) {
return (long) Math.abs(a);
}
private static long abs(long a, long b) {
return (long) Math.abs(a - b);
}
private static int max(int a, int b) {
if (a > b) {
return a;
} else {
return b;
}
}
private static int min(int a, int b) {
if (a > b) {
return b;
} else {
return a;
}
}
private static long max(long a, long b) {
if (a > b) {
return a;
} else {
return b;
}
}
private static long min(long a, long b) {
if (a > b) {
return b;
} else {
return a;
}
}
private static int pow(int base, int exp) {
int result = 1;
while (exp != 0) {
if ((exp & 1) == 1)
result *= base;
exp >>= 1;
base *= base;
}
return result;
}
private static long powerMod(long base, long exp, long mod) {
long result = 1;
base %= mod;
while (exp > 0) {
if ((exp & 1) != 0)
result = (result * base) % mod;
exp >>= 1;
base = base * base % mod;
}
return result < 0 ? result + mod : result;
}
private static long addMod(long a, long b, long mod) {
return (a % mod + b % mod) % mod;
}
private static long subMod(long a, long b, long mod) {
return (a % mod - b % mod) % mod;
}
private static long mulMod(long a, long b, long mod) {
return ((a % mod) * (b % mod)) % mod;
}
private static long pow(long base, long exp) {
long result = 1;
while (exp != 0) {
if ((exp & 1) == 1)
result = result * base;
exp >>= 1;
base *= base;
}
return result;
}
// array util
private static void sortList(ArrayList<Integer> al) {
Collections.sort(al);
}
private static void sortListP(ArrayList<Pair<Integer, Integer>> al) {
Collections.sort(al);
}
private static void sort(int[] a) {
ArrayList<Integer> al = new ArrayList<>();
for (int e : a)
al.add(e);
sortList(al);
int i = 0;
for (int e : al)
a[i++] = e;
}
private static void sort(long[] a) {
ArrayList<Long> al = new ArrayList<>();
for (long e : a)
al.add(e);
Collections.sort(al);
int i = 0;
for (long e : al)
a[i++] = e;
}
private 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;
}
private 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;
}
private 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;
}
// output
private static void pn(Object o) {
pw.println(o);
}
private static void p(Object o) {
pw.print(o);
}
private static void pry() {
pn("Yes");
}
private static void pY() {
pn("YES");
}
private static void prn() {
pn("No");
}
private static void pN() {
pn("NO");
}
private static void flush() {
pw.flush();
}
private static void watch(int[] a) {
for (int e : a)
p(e + " ");
pn("");
}
private static void watch(long[] a) {
for (long e : a)
p(e + " ");
pn("");
}
private static void watch(char[] a) {
for (char e : a)
p(e);
pn("");
}
private static void watchList(ArrayList<Integer> al) {
for (int e : al)
p(e + " ");
pn("");
}
private static Set<Integer> putSet(int[] a) {
Set<Integer> set = new TreeSet<>();
for (int e : a)
set.add(e);
return set;
}
private static boolean[] sieve(int n) {
boolean[] isPrime = new boolean[n + 1];
Arrays.fill(isPrime, true);
isPrime[0] = false;
isPrime[1] = false;
for (int i = 2; i * i <= n; i++) {
for (int j = i * i; j <= n; j += i) {
isPrime[j] = false;
}
}
return isPrime;
}
private static class Pair<U, V> implements Comparable<Pair<U, V>> {
public final U first;
public V second;
public <U, V> Pair<U, V> makePair(U first, V second) {
return new Pair<U, V>(first, second);
}
public Pair(U first, V second) {
this.first = first;
this.second = second;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Pair pair = (Pair) o;
return !(first != null ? !first.equals(pair.first) : pair.first != null)
&& !(second != null ? !second.equals(pair.second) : pair.second != null);
}
@Override
public int hashCode() {
int result = first != null ? first.hashCode() : 0;
result = 31 * result + (second != null ? second.hashCode() : 0);
return result;
}
public Pair<V, U> swap() {
return makePair(second, first);
}
@Override
public String toString() {
return "(" + first + "," + second + ")";
}
@SuppressWarnings({ "unchecked" })
public int compareTo(Pair<U, V> o) {
int value = ((Comparable<U>) first).compareTo(o.first);
if (value != 0) {
return value;
}
return ((Comparable<V>) second).compareTo(o.second);
}
}
private static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() throws FileNotFoundException {
if (System.getProperty("os.name").equals("Mac OS X")) {
// Input is a file
br = new BufferedReader(new FileReader("input.txt"));
// PrintWriter class prints formatted representations
// of objects to a text-output stream.
PrintStream pw = new PrintStream(new FileOutputStream("output.txt"));
System.setOut(pw);
} else {
// Input is System.in
br = new BufferedReader(new InputStreamReader(System.in), 32768);
st = null;
}
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int i() {
return Integer.parseInt(next());
}
int[] intArray(int n) {
int[] ret = new int[n];
for (int i = 0; i < n; i++)
ret[i] = i();
return ret;
}
ArrayList<Integer> intList(int n) {
ArrayList<Integer> al = new ArrayList<>();
for (int i = 0; i < n; i++)
al.add(i());
return al;
}
long l() {
return Long.parseLong(next());
}
long[] longArray(int n) {
long[] ret = new long[n];
for (int i = 0; i < n; i++)
ret[i] = l();
return ret;
}
ArrayList<Long> longList(int n) {
ArrayList<Long> al = new ArrayList<>();
for (int i = 0; i < n; i++)
al.add(l());
return al;
}
double d() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
private static boolean arr[] = sieve(1000001);
private static ArrayList<Long> primes = new ArrayList<>();
private static int freq[] = new int[200005];
private static int mod = (int) (1e9 + 7);
private static final int IMAX = 2147483647;
private static final int IMIN = -2147483648;
private static final long LMAX = 9223372036854775807L;
private static final long LMIN = -9223372036854775808L;
private static FastScanner c;
private static PrintWriter pw;
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 741fd87b7b15d6d489e82e4fae004ea0 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
public class SolveJava{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int ts = in.nextInt();
while(ts-- > 0){
int n = in.nextInt();
for(int i = 12 ; i < n+12 ; i++){
System.out.print(i + " ");
}
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 7d61f6e040b9171515eb1fa96be8008e | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
import java.io.*;
public class A_Find_Array{
public static void main(String[] args) {
try {
FastReader in = new FastReader();
FastWriter out = new FastWriter();
int testCases = in.nextInt();
while(testCases-- > 0){
int n = in.nextInt();
int a = 3;
out.print(a);
for(int i = 0; i < n-1; i++){
a+=2;
out.print(" ");
out.print(a);
}
out.println("");
}
out.close();
} catch (Exception e) {
return;
}
}
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;
}
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;
}
// ArrayList<Integer> readArrayList(int n) {
// ArrayList<Integer> a = new ArrayList<>(n);
// for (int i = 0 ; i < n; i ++ ) a.add(fs.nextInt());
// return a;
// }
}
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();
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | c398c86cbafaf34b3df64b93ef5bd1df | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.Scanner;
import java.lang.Math;
public class CF2609{
public static void main(String[] args) throws Exception{
Scanner scan = new Scanner(System.in);
int testCases = scan.nextInt();
while(testCases > 0){
int arrayLength = scan.nextInt();
for(int i=2; i<arrayLength+2; i++){
System.out.print(i+" ");
}
System.out.println();
testCases--;
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | e9c9cdae145f6822f810b24f7a6b2e0d | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes |
import java.io.*;
import java.util.*;
public class Solution {
public static long gcd(long a,long b) {
if(a==0) return b;
return gcd(b%a,a);
}
public static long lcm(long a,long b) {
return (a*b)/gcd(a,b);
}
public static void main(String[] args) throws java.lang.Exception {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter out=new PrintWriter(System.out);
int testCases=Integer.parseInt(br.readLine());
while(testCases-->0) {
int n=Integer.parseInt(br.readLine());
for(int i=1;i<=n;i++) {
out.print((i+1)+" ");
}
out.println();
}
out.close();
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | d8927937670754f62a048e1be6523292 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.io.DataInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
public class Main {
private static void run() throws IOException {
int n = in.nextInt();
for (int i = 0; i < n; i++) {
out.print(i + 2);
out.print(' ');
}
out.println();
}
public static void main(String[] args) throws IOException {
in = new Reader();
out = new PrintWriter(new OutputStreamWriter(System.out));
int t = in.nextInt();
for (int i = 0; i < t; i++) {
run();
}
out.flush();
in.close();
out.close();
}
private static int gcd(int a, int b) {
if (a == 0 || b == 0)
return 0;
while (b != 0) {
int tmp;
tmp = a % b;
a = b;
b = tmp;
}
return a;
}
static final long mod = 1000000007;
static long pow_mod(long a, long b) {
long result = 1;
while (b != 0) {
if ((b & 1) != 0) result = (result * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return result;
}
private static long add_mod(long... longs) {
long ans = 0;
for (long now : longs) {
ans = (ans + now) % mod;
}
return ans;
}
private static long multiplied_mod(long... longs) {
long ans = 1;
for (long now : longs) {
ans = (ans * now) % mod;
}
return ans;
}
@SuppressWarnings("FieldCanBeLocal")
private static Reader in;
private static PrintWriter out;
private static int[] read_int_array(int len) throws IOException {
int[] a = new int[len];
for (int i = 0; i < len; i++) {
a[i] = in.nextInt();
}
return a;
}
private static long[] read_long_array(int len) throws IOException {
long[] a = new long[len];
for (int i = 0; i < len; i++) {
a[i] = in.nextLong();
}
return a;
}
private static void print_array(int[] array) {
for (int now : array) {
out.print(now);
out.print(' ');
}
out.println();
}
private static void print_array(long[] array) {
for (long now : array) {
out.print(now);
out.print(' ');
}
out.println();
}
static class Reader {
private static final int BUFFER_SIZE = 1 << 16;
private final DataInputStream din;
private final byte[] buffer;
private int bufferPointer, bytesRead;
Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
final byte[] buf = new byte[1024]; // 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 nextSign() throws IOException {
byte c = read();
while ('+' != c && '-' != c) {
c = read();
}
return '+' == c ? 0 : 1;
}
private static boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
public int skip() throws IOException {
int b;
// noinspection ALL
while ((b = read()) != -1 && isSpaceChar(b)) {
;
}
return b;
}
public char nc() throws IOException {
return (char) skip();
}
public String next() throws IOException {
int b = skip();
final StringBuilder sb = new StringBuilder();
while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = read();
}
return sb.toString();
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
final 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();
}
final 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();
}
final 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 {
din.close();
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 418726f72d690f47ede62fbf28f97623 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | /* package whatever; // 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 Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner in = new Scanner( System.in );
int t = in.nextInt();
for(int i = 0;i<t;i++){
int n = in.nextInt();
for(int j = 0;j<n;j++){
System.out.print(j+2+" ");
}
System.out.println("");
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 936903a29b4b3359bc2704602c9d05df | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
public class Main {
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*b)/gcd(a,b);
}
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int test = sc.nextInt();
for ( int t =0; t <test; t++) {
long x = sc.nextLong();
for ( int i=0; i<x; i++){
System.out.print((i+2)+" ");
}
System.out.println();
}
}
}
// 3
// 1
// 2
// 7 | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 4f422c7696649af6241d249ed5713f15 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner in = new Scanner(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int T = in.nextInt();
for (int t = 0; t < T; t++) {
int n = in.nextInt();
for (int i = 0; i < n; i++) {
out.print(i != 0 ? " " : "");
out.print(i + 2);
}
out.println();
}
out.close();
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 30914e5cf728c0fa24a21d460a7e23e9 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.Scanner;
public class FindArray {
public static void printArray(int n){
for (int i = 2; i <= n+1 ; i++) {
System.out.print(i + " ");
}
System.out.println();
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
for (int i = 0; i < t; i++) {
int n = input.nextInt();
printArray(n);
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 3c75adf0d827622d3c37fbd2dbbacd3b | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
public class Main{
public static void main(String args[]){
Scanner cin = new Scanner(System.in);
int t = cin.nextInt();
for (int i = 1; i<= t; i++){
int n = cin.nextInt();
for (int j = 2; j<= n+1; j++){
System.out.print(j);
System.out.print(" ");
}
System.out.println();
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | a063eb3034bd175ddbc4d2b439609af4 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.io.*;
import java.lang.*;
import java.util.*;
public class ComdeFormces {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
// Reader.init(System.in);
FastReader sc=new FastReader();
BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
// OutputStream out = new BufferedOutputStream ( System.out );
int t=sc.nextInt();
while(t--!=0) {
int n=sc.nextInt();
for(int i=3;n--!=0;i+=2)log.write(i+" ");
log.write("\n");
log.flush();
}
}
public static void radixSort(int a[]) {
int n=a.length;
int res[]=new int[n];
int p=1;
for(int i=0;i<=8;i++) {
int cnt[]=new int[10];
for(int j=0;j<n;j++) {
a[j]=res[j];
cnt[(a[j]/p)%10]++;
}
for(int j=1;j<=9;j++) {
cnt[j]+=cnt[j-1];
}
for(int j=n-1;j>=0;j--) {
res[cnt[(a[j]/p)%10]-1]=a[j];
cnt[(a[j]/p)%10]--;
}
p*=10;
}
}
static int bits(long n) {
int ans=0;
while(n!=0) {
if((n&1)==1)ans++;
n>>=1;
}
return ans;
}
static long flor(ArrayList<Long> ar,long el) {
int s=0;
int e=ar.size()-1;
while(s<=e) {
int m=s+(e-s)/2;
if(ar.get(m)==el)return ar.get(m);
else if(ar.get(m)<el)s=m+1;
else e=m-1;
}
return e>=0?e:-1;
}
public static int kadane(int a[]) {
int sum=0,mx=Integer.MIN_VALUE;
for(int i=0;i<a.length;i++) {
sum+=a[i];
mx=Math.max(mx, sum);
if(sum<0) sum=0;
}
return mx;
}
public static int m=1000000007;
public static int mul(int a, int b) {
return ((a%m)*(b%m))%m;
}
public static long mul(long a, long b) {
return ((a%m)*(b%m))%m;
}
public static int add(int a, int b) {
return ((a%m)+(b%m))%m;
}
public static long add(long a, long b) {
return ((a%m)+(b%m))%m;
}
//debug
public static <E> void p(E[][] a,String s) {
System.out.println(s);
for(int i=0;i<a.length;i++) {
for(int j=0;j<a[0].length;j++) {
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
public static void p(int[] a,String s) {
System.out.print(s+"=");
for(int i=0;i<a.length;i++)System.out.print(a[i]+" ");
System.out.println();
}
public static void p(long[] a,String s) {
System.out.print(s+"=");
for(int i=0;i<a.length;i++)System.out.print(a[i]+" ");
System.out.println();
}
public static <E> void p(E a,String s){
System.out.println(s+"="+a);
}
public static <E> void p(ArrayList<E> a,String s){
System.out.println(s+"="+a);
}
public static <E> void p(LinkedList<E> a,String s){
System.out.println(s+"="+a);
}
public static <E> void p(HashSet<E> a,String s){
System.out.println(s+"="+a);
}
public static <E> void p(Stack<E> a,String s){
System.out.println(s+"="+a);
}
public static <E> void p(Queue<E> a,String s){
System.out.println(s+"="+a);
}
//utils
static ArrayList<Integer> divisors(int n){
ArrayList<Integer> ar=new ArrayList<>();
for (int i=2; i<=Math.sqrt(n); i++){
if (n%i == 0){
if (n/i == i) {
ar.add(i);
}
else {
ar.add(i);
ar.add(n/i);
}
}
}
return ar;
}
static int primeDivisor(int n){
ArrayList<Integer> ar=new ArrayList<>();
int cnt=0;
boolean pr=false;
while(n%2==0) {
pr=true;
n/=2;
}
if(pr)ar.add(2);
for(int i=3;i*i<=n;i+=2) {
pr=false;
while(n%i==0) {
n/=i;
pr=true;
}
if(pr)ar.add(i);
}
if(n>2) ar.add(n);
return ar.size();
}
static long gcd(long a,long b) {
if(b==0)return a;
else return gcd(b,a%b);
}
static int gcd(int a,int b) {
if(b==0)return a;
else return gcd(b,a%b);
}
static long factmod(long n,long mod,long img) {
if(n==0)return 1;
long ans=1;
long temp=1;
while(n--!=0) {
if(temp!=img) {
ans=((ans%mod)*((temp)%mod))%mod;
}
temp++;
}
return ans%mod;
}
static int ncr(int n, int r){
if(r>n-r)r=n-r;
int ans=1;
for(int i=0;i<r;i++){
ans*=(n-i);
ans/=(i+1);
}
return ans;
}
public static class trip{
int a,b;
int c;
public trip(int a,int b,int c) {
this.a=a;
this.b=b;
this.c=c;
}
public int compareTo(trip q) {
return this.b-q.b;
}
}
static void mergesort(long[] a,int start,int end) {
if(start>=end)return ;
int mid=start+(end-start)/2;
mergesort(a,start,mid);
mergesort(a,mid+1,end);
merge(a,start,mid,end);
}
static void merge(long[] a, int start,int mid,int end) {
int ptr1=start;
int ptr2=mid+1;
long b[]=new long[end-start+1];
int i=0;
while(ptr1<=mid && ptr2<=end) {
if(a[ptr1]<=a[ptr2]) {
b[i]=a[ptr1];
ptr1++;
i++;
}
else {
b[i]=a[ptr2];
ptr2++;
i++;
}
}
while(ptr1<=mid) {
b[i]=a[ptr1];
ptr1++;
i++;
}
while(ptr2<=end) {
b[i]=a[ptr2];
ptr2++;
i++;
}
for(int j=start;j<=end;j++) {
a[j]=b[j-start];
}
}
public static class FastReader {
BufferedReader b;
StringTokenizer s;
public FastReader() {
b=new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while(s==null ||!s.hasMoreElements()) {
try {
s=new StringTokenizer(b.readLine());
}
catch(IOException e) {
e.printStackTrace();
}
}
return s.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str="";
try {
str=b.readLine();
}
catch(IOException e) {
e.printStackTrace();
}
return str;
}
boolean hasNext() {
if (s != null && s.hasMoreTokens()) {
return true;
}
String tmp;
try {
b.mark(1000);
tmp = b.readLine();
if (tmp == null) {
return false;
}
b.reset();
} catch (IOException e) {
return false;
}
return true;
}
}
public static class pair{
int a;
int b;
public pair(int a,int b) {
this.a=a;
this.b=b;
}
public int compareTo(pair b) {
return this.a-b.a;
}
// public int compareToo(pair b) {
// return this.b-b.b;
// }
@Override
public String toString() {
return "{"+this.a+" "+this.b+"}";
}
}
static long pow(long a, long pw) {
long temp;
if(pw==0)return 1;
temp=pow(a,pw/2);
if(pw%2==0)return temp*temp;
return a*temp*temp;
}
static int pow(int a, int pw) {
int temp;
if(pw==0)return 1;
temp=pow(a,pw/2);
if(pw%2==0)return temp*temp;
return a*temp*temp;
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | f9d0188d8248718c42a00958bff12707 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | //jiudge: 5571: 1648100913
import java.util.Scanner;
public class G {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
for(int i = 1; i <= N; i ++ ) {
int n = sc.nextInt();
int[] array = new int[n];
for(int j = 0; j < n; j ++ ) {
array[j] = j + 2;
}
for(int x : array) {
System.out.print(x + " ");
}
System.out.println();
}
sc.close();
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 45d6b20b6e8b7da1bf6df4157181a088 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;
public class A_Find_Array {
public static void main(String[] args) {
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
FastReader f = new FastReader();
int t = f.nextInt();
while(t-- > 0){
int n = f.nextInt();
for(int i = 2; i <= n+1; i++) {
out.print(i + " ");
}
out.println();
}
out.close();
}
public static void allDivisors(int n) {
for(int i = 1; i*i <= n; i++) {
if(n%i == 0) {
System.out.println(i + " ");
if(i != n/i) {
System.out.println(n/i + " ");
}
}
}
}
public static boolean isPrime(int n) {
if(n < 1) return false;
if(n == 2 || n == 3) return true;
if(n % 2 == 0 || n % 3 == 0) return false;
for(int i = 5; i*i <= n; i += 6) {
if(n % i == 0 || n % (i+2) == 0) {
return false;
}
}
return true;
}
public static int Gcd(int a, int b) {
int dividend = a > b ? a : b;
int divisor = a < b ? a : b;
while(divisor > 0) {
int reminder = dividend % divisor;
dividend = divisor;
divisor = reminder;
}
return dividend;
}
public static int lcm1(int a, int b) {
int lcm = Gcd(a, b);
int hcf = (a * b) / lcm;
return hcf;
}
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());
}
boolean nextBoolean() {
return Boolean.parseBoolean(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
/**
Dec Char Dec Char Dec Char Dec Char
--------- --------- --------- ----------
0 NUL (null) 32 SPACE 64 @ 96 `
1 SOH (start of heading) 33 ! 65 A 97 a
2 STX (start of text) 34 " 66 B 98 b
3 ETX (end of text) 35 # 67 C 99 c
4 EOT (end of transmission) 36 $ 68 D 100 d
5 ENQ (enquiry) 37 % 69 E 101 e
6 ACK (acknowledge) 38 & 70 F 102 f
7 BEL (bell) 39 ' 71 G 103 g
8 BS (backspace) 40 ( 72 H 104 h
9 TAB (horizontal tab) 41 ) 73 I 105 i
10 LF (NL line feed, new line) 42 * 74 J 106 j
11 VT (vertical tab) 43 + 75 K 107 k
12 FF (NP form feed, new page) 44 , 76 L 108 l
13 CR (carriage return) 45 - 77 M 109 m
14 SO (shift out) 46 . 78 N 110 n
15 SI (shift in) 47 / 79 O 111 o
16 DLE (data link escape) 48 0 80 P 112 p
17 DC1 (device control 1) 49 1 81 Q 113 q
18 DC2 (device control 2) 50 2 82 R 114 r
19 DC3 (device control 3) 51 3 83 S 115 s
20 DC4 (device control 4) 52 4 84 T 116 t
21 NAK (negative acknowledge) 53 5 85 U 117 u
22 SYN (synchronous idle) 54 6 86 V 118 v
23 ETB (end of trans. block) 55 7 87 W 119 w
24 CAN (cancel) 56 8 88 X 120 x
25 EM (end of medium) 57 9 89 Y 121 y
26 SUB (substitute) 58 : 90 Z 122 z
27 ESC (escape) 59 ; 91 [ 123 {
28 FS (file separator) 60 < 92 \ 124 |
29 GS (group separator) 61 = 93 ] 125 }
30 RS (record separator) 62 > 94 ^ 126 ~
31 US (unit separator) 63 ? 95 _ 127 DEL
*/
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 9de3c922d88ef9b1c823148ee4b287cb | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.io.*;
import java.util.*;
public class Solution {
static int mod=(int)1e9+7;
static long h[],add[];
public static void main(String[] args) {
Copied io = new Copied(System.in, System.out);
// int k=1;
int t = 1;
t = io.nextInt();
for (int i = 0; i < t; i++) {
// io.print("Case #" + k + ": ");
solve(io);
// k++;
}
io.close();
}
public static void solve(Copied io) {
int n=io.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++){
a[i]=i+2;
}
printArr(a, io);
}
static String sortString(String inputString) {
char tempArray[] = inputString.toCharArray();
Arrays.sort(tempArray);
return new String(tempArray);
}
static void binaryOutput(boolean ans, Copied io){
String a=new String("YES"), b=new String("NO");
if(ans){
io.println(a);
}
else{
io.println(b);
}
}
static int power(int x, int y, int p)
{
int res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0)
{
if ((y & 1) != 0)
res = (res * x) % p;
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
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 void sort(long[] a) {
ArrayList<Long> l = new ArrayList<>();
for (long i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static void printArr(int[] arr,Copied io) {
for (int x : arr)
io.print(x + " ");
io.println();
}
static void printArr(long[] arr,Copied io) {
for (long x : arr)
io.print(x + " ");
io.println();
}
static int[] listToInt(ArrayList<Integer> a){
int n=a.size();
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=a.get(i);
}
return arr;
}
static int mod_mul(int a, int b){ a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}
static int mod_add(int a, int b){ a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}
static int mod_sub(int a, int b){ a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod;}
}
// class Pair implements Cloneable, Comparable<Pair>
// {
// int x,y;
// Pair(int a,int b)
// {
// this.x=a;
// this.y=b;
// }
// @Override
// public boolean equals(Object obj)
// {
// if(obj instanceof Pair)
// {
// Pair p=(Pair)obj;
// return p.x==this.x && p.y==this.y;
// }
// return false;
// }
// @Override
// public int hashCode()
// {
// return Math.abs(x)+101*Math.abs(y);
// }
// @Override
// public String toString()
// {
// return "("+x+" "+y+")";
// }
// @Override
// protected Pair clone() throws CloneNotSupportedException {
// return new Pair(this.x,this.y);
// }
// @Override
// public int compareTo(Pair a)
// {
// int t= this.x-a.x;
// if(t!=0)
// return t;
// else
// return this.y-a.y;
// }
// }
// class byY implements Comparator<Pair>{
// // @Override
// public int compare(Pair o1,Pair o2){
// // -1 if want to swap and (1,0) otherwise.
// int t= o1.y-o2.y;
// if(t!=0)
// return t;
// else
// return o1.x-o2.x;
// }
// }
// class byX implements Comparator<Pair>{
// // @Override
// public int compare(Pair o1,Pair o2){
// // -1 if want to swap and (1,0) otherwise.
// int t= o1.x-o2.x;
// if(t!=0)
// return t;
// else
// return o1.y-o2.y;
// }
// }
// class DescendingOrder<T> implements Comparator<T>{
// @Override
// public int compare(Object o1,Object o2){
// // -1 if want to swap and (1,0) otherwise.
// int addingNumber=(Integer) o1,existingNumber=(Integer) o2;
// if(addingNumber>existingNumber) return -1;
// else if(addingNumber<existingNumber) return 1;
// else return 0;
// }
// }
class Copied extends PrintWriter {
public Copied(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public Copied(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public boolean hasMoreTokens() {
return peekToken() != null;
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public double nextDouble() {
return Double.parseDouble(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
public String next() {
return nextToken();
}
public double[] nextDoubles(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongs(int N) {
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null) return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) { }
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 277178a330ff51667a029688de601751 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int k = input.nextInt();
while (k-- != 0) {
int n = input.nextInt();
if (n == 1) System.out.println(1);
else {
for (int i = 0; i < n; i++) {
System.out.print(i + 2);
System.out.print(i == n - 1 ? '\n' : " ");
}
}
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 898f9aee903e61c4d090ac6b720da364 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes |
import static java.lang.System.out;
import java.util.*;
public class JavaApplication16 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int T = s.nextInt();
while(T-- > 0){
int n = s.nextInt();
out.print(2 + " ");
for(int i = 0; i < n - 1; i++){
out.print(i + 3 + " ");
}
out.println();
}
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 9f91cbe0131f4bc5f225a47db03ab5cc | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.Scanner;
public class FindArray {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0) {
int size = sc.nextInt();
int n = 2;
for(int i = 0; i < size; i++) {
System.out.print(n+++" ");
}
}
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 9ba8eda2c801ce1810991628a5238857 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.Scanner;
public class codeForce2 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t>0) {
int n = s.nextInt();
int f = 2;
int s1 = 3;
int arr[] = new int[n];
if(n == 1) {
System.out.println('1');
}else {
while(n>0) {
if(s1%f != 0) {
System.out.print(f+" ");
f++;
s1++;
}else {
System.out.print(s1+" ");
s1++;
}
n--;
}
}
t--;
}
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 619571b1da47fbf3d0f1dae00a5e83fc | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 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
{
// your code goes here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
for(int i = 2; i <= n + 1; i++){
System.out.print(i + " ");
}
System.out.println();
}
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 72f756b245f455d1d68cde566505bb3a | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | //package com.shroom;
import java.util.*;
public class dec {
private static final Scanner in = new Scanner(System.in);
public static void main(String[] args) throws Exception {
//
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] = i + 2;
System.out.print(arr[i] + " ");
}
System.out.println();
}
}
// 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);
// }
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 11 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 06bd1fc50c0d912002ca39b9332fc00b | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
public class A1608 {
private static final Scanner input = new Scanner(System.in);
public static void main(String[] args) {
final int t = input.nextInt();
for (int i = 0; i < t; i++) {
final int n = input.nextInt();
System.out.println(solve(n));
}
}
private static String solve(int n) {
String output = "";
for (int i = 2; i < n + 2; i++)
output += i + " ";
return output;
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 17 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 8867fa274fd63d2602a18d1e4149f0c3 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
public class Codeforces {
public static void main(String[] args) {
Scanner lta = new Scanner(System.in);
int t = lta.nextInt();
while (t-- > 0){
int n = lta.nextInt();
for (int i = n;i < n + n;i++){
System.out.print(i + " ");
}
System.out.println();
}
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 17 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 4c03dc49ed9380cfd94aceee56c7a749 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
public class Codeforces {
public static void main(String[] args) {
Scanner lta = new Scanner(System.in);
int t = lta.nextInt();
while (t-- > 0){
int n = lta.nextInt();
for (int i = n;i < n + n;i++){
System.out.print(i + " ");
}
System.out.println();
}
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 17 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | c3582a9d3051c97248649245c0195926 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.Scanner;
public class main{
public static void main(String [] args){
Scanner in = new Scanner(System.in);
int nt, n, i;
nt = in.nextInt();
while(nt > 0){
n = in.nextInt();
i = 2;
while(n > 0){
System.out.print(i + " ");
i ++;
n --;
}
System.out.println();
nt --;
}
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 17 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | d6ed8661a1fae8f4de0ba199e9010e31 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tc = 0; tc < t; ++tc) {
int n = sc.nextInt();
System.out.println(solve(n));
}
sc.close();
}
static String solve(int n) {
return IntStream.range(0, n)
.mapToObj(i -> String.valueOf(i + 2))
.collect(Collectors.joining(" "));
}
} | Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 17 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | fe93f7a03a1e0bbeabbf2bd185c78ff0 | train_109.jsonl | 1639217100 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem. | 256 megabytes | import java.util.*;
import java.util.function.*;
import java.io.*;
// you can compare with output.txt and expected out
public class Round758A {
MyPrintWriter out;
MyScanner in;
// final static long FIXED_RANDOM;
// static {
// FIXED_RANDOM = System.currentTimeMillis();
// }
final static String IMPOSSIBLE = "IMPOSSIBLE";
final static String POSSIBLE = "POSSIBLE";
final static String YES = "YES";
final static String NO = "NO";
private void initIO(boolean isFileIO) {
if (System.getProperty("ONLINE_JUDGE") == null && isFileIO) {
try{
in = new MyScanner(new FileInputStream("input.txt"));
out = new MyPrintWriter(new FileOutputStream("output.txt"));
}
catch(FileNotFoundException e){
e.printStackTrace();
}
}
else{
in = new MyScanner(System.in);
out = new MyPrintWriter(new BufferedOutputStream(System.out));
}
}
public static void main(String[] args){
// Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
Round758A sol = new Round758A();
sol.run();
}
private void run() {
boolean isDebug = false;
boolean isFileIO = true;
boolean hasMultipleTests = true;
initIO(isFileIO);
int t = hasMultipleTests? in.nextInt() : 1;
for (int i = 1; i <= t; ++i) {
if(isDebug){
out.printf("Test %d\n", i);
}
getInput();
solve();
printOutput();
}
in.close();
out.close();
}
// use suitable one between matrix(2, n) or matrix(n, 2) for graph edges, pairs, ...
int n;
void getInput() {
n = in.nextInt();
}
void printOutput() {
out.printlnAns(ans);
}
int[] ans;
void solve(){
ans = new int[n];
for(int i=0; i<n; i++)
ans[i] = i+2;
}
static class Pair implements Comparable<Pair>{
final static long FIXED_RANDOM = System.currentTimeMillis();
int first, second;
public Pair(int first, int second) {
this.first = first;
this.second = second;
}
@Override
public int hashCode() {
// http://xorshift.di.unimi.it/splitmix64.c
long x = first;
x <<= 32;
x += second;
x += FIXED_RANDOM;
x += 0x9e3779b97f4a7c15l;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9l;
x = (x ^ (x >> 27)) * 0x94d049bb133111ebl;
return (int)(x ^ (x >> 31));
}
@Override
public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
Pair other = (Pair) obj;
return first == other.first && second == other.second;
}
@Override
public String toString() {
return "[" + first + "," + second + "]";
}
@Override
public int compareTo(Pair o) {
int cmp = Integer.compare(first, o.first);
return cmp != 0? cmp: Integer.compare(second, o.second);
}
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
// 32768?
public MyScanner(InputStream is, int bufferSize) {
br = new BufferedReader(new InputStreamReader(is), bufferSize);
}
public MyScanner(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
// br = new BufferedReader(new InputStreamReader(System.in));
// br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
}
public void close() {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
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[][] nextMatrix(int n, int m) {
return nextMatrix(n, m, 0);
}
int[][] nextMatrix(int n, int m, int offset) {
int[][] mat = new int[n][m];
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
mat[i][j] = nextInt()+offset;
}
}
return mat;
}
int[][] nextTransposedMatrix(int n, int m){
return nextTransposedMatrix(n, m, 0);
}
int[][] nextTransposedMatrix(int n, int m, int offset){
int[][] mat = new int[m][n];
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
mat[j][i] = nextInt()+offset;
}
}
return mat;
}
int[] nextIntArray(int len) {
return nextIntArray(len, 0);
}
int[] nextIntArray(int len, int offset){
int[] a = new int[len];
for(int j=0; j<len; j++)
a[j] = nextInt()+offset;
return a;
}
long[] nextLongArray(int len) {
return nextLongArray(len, 0);
}
long[] nextLongArray(int len, int offset){
long[] a = new long[len];
for(int j=0; j<len; j++)
a[j] = nextLong()+offset;
return a;
}
String[] nextStringArray(int len) {
String[] s = new String[len];
for(int i=0; i<len; i++)
s[i] = next();
return s;
}
}
public static class MyPrintWriter extends PrintWriter{
public MyPrintWriter(OutputStream os) {
super(os);
}
public void printlnAns(long ans) {
println(ans);
}
public void printlnAns(int ans) {
println(ans);
}
public void printlnAns(boolean ans) {
if(ans)
println(YES);
else
println(NO);
}
public void printAns(long[] arr){
if(arr != null && arr.length > 0){
print(arr[0]);
for(int i=1; i<arr.length; i++){
print(" ");
print(arr[i]);
}
}
}
public void printlnAns(long[] arr){
printAns(arr);
println();
}
public void printAns(int[] arr){
if(arr != null && arr.length > 0){
print(arr[0]);
for(int i=1; i<arr.length; i++){
print(" ");
print(arr[i]);
}
}
}
public void printlnAns(int[] arr){
printAns(arr);
println();
}
public <T> void printAns(ArrayList<T> arr){
if(arr != null && arr.size() > 0){
print(arr.get(0));
for(int i=1; i<arr.size(); i++){
print(" ");
print(arr.get(i));
}
}
}
public <T> void printlnAns(ArrayList<T> arr){
printAns(arr);
println();
}
public void printAns(int[] arr, int add){
if(arr != null && arr.length > 0){
print(arr[0]+add);
for(int i=1; i<arr.length; i++){
print(" ");
print(arr[i]+add);
}
}
}
public void printlnAns(int[] arr, int add){
printAns(arr, add);
println();
}
public void printAns(ArrayList<Integer> arr, int add) {
if(arr != null && arr.size() > 0){
print(arr.get(0)+add);
for(int i=1; i<arr.size(); i++){
print(" ");
print(arr.get(i)+add);
}
}
}
public void printlnAns(ArrayList<Integer> arr, int add){
printAns(arr, add);
println();
}
public void printlnAnsSplit(long[] arr, int split){
if(arr != null){
for(int i=0; i<arr.length; i+=split){
print(arr[i]);
for(int j=i+1; j<i+split; j++){
print(" ");
print(arr[j]);
}
println();
}
}
}
public void printlnAnsSplit(int[] arr, int split){
if(arr != null){
for(int i=0; i<arr.length; i+=split){
print(arr[i]);
for(int j=i+1; j<i+split; j++){
print(" ");
print(arr[j]);
}
println();
}
}
}
public <T> void printlnAnsSplit(ArrayList<T> arr, int split){
if(arr != null && !arr.isEmpty()){
for(int i=0; i<arr.size(); i+=split){
print(arr.get(i));
for(int j=i+1; j<i+split; j++){
print(" ");
print(arr.get(j));
}
println();
}
}
}
}
static private void permutateAndSort(long[] a) {
int n = a.length;
Random R = new Random(System.currentTimeMillis());
for(int i=0; i<n; i++) {
int t = R.nextInt(n-i);
long temp = a[n-1-i];
a[n-1-i] = a[t];
a[t] = temp;
}
Arrays.sort(a);
}
static private void permutateAndSort(int[] a) {
int n = a.length;
Random R = new Random(System.currentTimeMillis());
for(int i=0; i<n; i++) {
int t = R.nextInt(n-i);
int temp = a[n-1-i];
a[n-1-i] = a[t];
a[t] = temp;
}
Arrays.sort(a);
}
static private int[][] constructChildren(int n, int[] parent, int parentRoot){
int[][] childrens = new int[n][];
int[] numChildren = new int[n];
for(int i=0; i<parent.length; i++) {
if(parent[i] != parentRoot)
numChildren[parent[i]]++;
}
for(int i=0; i<n; i++) {
childrens[i] = new int[numChildren[i]];
}
int[] idx = new int[n];
for(int i=0; i<parent.length; i++) {
if(parent[i] != parentRoot)
childrens[parent[i]][idx[parent[i]]++] = i;
}
return childrens;
}
static private int[][][] constructDirectedNeighborhood(int n, int[][] e){
int[] inDegree = new int[n];
int[] outDegree = new int[n];
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
outDegree[u]++;
inDegree[v]++;
}
int[][] inNeighbors = new int[n][];
int[][] outNeighbors = new int[n][];
for(int i=0; i<n; i++) {
inNeighbors[i] = new int[inDegree[i]];
outNeighbors[i] = new int[outDegree[i]];
}
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
outNeighbors[u][--outDegree[u]] = v;
inNeighbors[v][--inDegree[v]] = u;
}
return new int[][][] {inNeighbors, outNeighbors};
}
static private int[][] constructNeighborhood(int n, int[][] e) {
int[] degree = new int[n];
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
degree[u]++;
degree[v]++;
}
int[][] neighbors = new int[n][];
for(int i=0; i<n; i++)
neighbors[i] = new int[degree[i]];
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
neighbors[u][--degree[u]] = v;
neighbors[v][--degree[v]] = u;
}
return neighbors;
}
static private void drawGraph(int[][] e) {
makeDotUndirected(e);
try {
final Process process = new ProcessBuilder("dot", "-Tpng", "graph.dot")
.redirectOutput(new File("graph.png"))
.start();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
static private void makeDotUndirected(int[][] e) {
MyPrintWriter out2 = null;
try {
out2 = new MyPrintWriter(new FileOutputStream("graph.dot"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
out2.println("strict graph {");
for(int i=0; i<e.length; i++){
out2.println(e[i][0] + "--" + e[i][1] + ";");
}
out2.println("}");
out2.close();
}
static private void makeDotDirected(int[][] e) {
MyPrintWriter out2 = null;
try {
out2 = new MyPrintWriter(new FileOutputStream("graph.dot"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
out2.println("strict digraph {");
for(int i=0; i<e.length; i++){
out2.println(e[i][0] + "->" + e[i][1] + ";");
}
out2.println("}");
out2.close();
}
}
| Java | ["3\n1\n2\n7"] | 1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$. | Java 17 | standard input | [
"constructive algorithms",
"math"
] | 76bfced1345f871832957a65e2a660f8 | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | 800 | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | standard output | |
PASSED | 8c6ef1b9c452677fb50dd658c4a78427 | train_109.jsonl | 1639217100 | On an endless checkered sheet of paper, $$$n$$$ cells are chosen and colored in three colors, where $$$n$$$ is divisible by $$$3$$$. It turns out that there are exactly $$$\frac{n}{3}$$$ marked cells of each of three colors! Find the largest such $$$k$$$ that it's possible to choose $$$\frac{k}{3}$$$ cells of each color, remove all other marked cells, and then select three rectangles with sides parallel to the grid lines so that the following conditions hold: No two rectangles can intersect (but they can share a part of the boundary). In other words, the area of intersection of any two of these rectangles must be $$$0$$$. The $$$i$$$-th rectangle contains all the chosen cells of the $$$i$$$-th color and no chosen cells of other colors, for $$$i = 1, 2, 3$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution extends PrintWriter {
int[][] perm = new int[][] {{0,1,2},{0,2,1},{1,0,2},{1,2,0},{2,0,1},{2,1,0}};
void solve() {
n = sc.nextInt();
cells = new int[n][];
for(int i = 0; i < n; i++) {
cells[i] = new int[] {sc.nextInt(), sc.nextInt(), sc.nextInt()-1, 0};
}
int ans = 0;
for(int it = 0; it < 2; it++) {
sort();
pre_pos_by_y();
int l = 0;
int r = n/3+1;
while(l < r-1) {
int mid = (l+r)/2;
if(pre_case1(mid)) l = mid;
else r = mid;
}
ans = Math.max(ans, l);
l = 0;
r = n/3+1;
while(l < r-1) {
int mid = (l+r)/2;
if(pre_case2(mid, false)) l = mid;
else r = mid;
}
reverse();
pre_pos_by_y();
ans = Math.max(ans, l);
l = 0;
r = n/3+1;
while(l < r-1) {
int mid = (l+r)/2;
if(pre_case2(mid, true)) l = mid;
else r = mid;
}
ans = Math.max(ans, l);
invert_axis();
}
println(3*ans);
}
int[] pos_by_y;
void sort() {
Arrays.sort(cells, Comparator.comparing(arr -> arr[1]));
for(int i = 0; i < n; i++) {
cells[i][3] = i;
}
Arrays.sort(cells, Comparator.comparing(arr -> arr[0]));
}
void pre_pos_by_y() {
pos_by_y = new int[n];
for(int i = 0; i < n; i++) {
pos_by_y[cells[i][3]] = i;
}
}
int n;
int[][] cells;
boolean pre_case1(int k) {
for(int[] p : perm) {
if(case1(p, k)) return true;
}
return false;
}
boolean case1(int[] type, int k) {
int cnt = 0;
int idx = 0;
int last_x = -1<<30;
for(int it = 0; it <= 2; it++) {
cnt = 0;
for(; idx < n && cnt < k; idx++) {
if(cells[idx][0] > last_x && cells[idx][2] == type[it]) {
cnt++;
}
}
if(cnt < k) return false;
last_x = cells[idx-1][0];
}
return true;
}
boolean pre_case2(int k, boolean reversed) {
for(int[] p : perm) {
if(case2(p, k, reversed)) return true;
}
return false;
}
boolean case2(int[] type, int k, boolean reversed) {
int cnt = 0;
int idx = 0;
cnt = 0;
for(; idx < n && cnt < k; idx++) {
if(cells[idx][2] == type[0]) {
cnt++;
}
}
if(cnt < k) return false;
int last_x = cells[idx-1][0];
idx = 0;
int last_y = -1<<30;
for(int it = 1; it <= 2; it++) {
cnt = 0;
for(; idx < n && cnt < k; idx++) {
if(cells[pos_by_y[idx]][2] == type[it] && after(cells[pos_by_y[idx]][0], last_x, reversed) && cells[pos_by_y[idx]][1] > last_y) {
cnt++;
}
}
if(cnt < k) return false;
last_y = cells[pos_by_y[idx-1]][1];
}
return true;
}
boolean after(int x1, int x2, boolean reversed) { //x1 > x2
if(reversed) return x1 < x2;
else return x1 > x2;
}
void reverse() {
for(int i = 0; i < n/2; i++) {
int[] temp = cells[i];
cells[i] = cells[n-1-i];
cells[n-1-i] = temp;
}
}
void invert_axis() {
for(int i = 0; i < n; i++) {
int temp = cells[i][0];
cells[i][0] = cells[i][1];
cells[i][1] = temp;
}
}
// Main() throws FileNotFoundException { super(new File("output.txt")); }
// InputReader sc = new InputReader(new FileInputStream("test_input.txt"));
Solution() { super(System.out); }
InputReader sc = new InputReader(System.in);
static class InputReader {
InputReader(InputStream in) { this.in = in; } InputStream in;
private byte[] buf = new byte[16384];
private int curChar;
private int numChars;
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = in.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
/*
private String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}*/
public String nextString() {
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 long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long 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 int nextInt() {
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;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
public static void main(String[] $) {
new Thread(null, new Runnable() {
public void run() {
long start = System.nanoTime();
try {Solution solution = new Solution(); solution.solve(); solution.flush();}
catch (Exception e) {e.printStackTrace(); System.exit(1);}
System.err.println((System.nanoTime()-start)/1E9);
}
}, "1", 1 << 27).start();
}
} | Java | ["9\n2 3 1\n4 1 2\n2 1 3\n3 4 1\n5 3 2\n4 4 3\n2 4 1\n5 2 2\n3 5 3", "3\n1 1 1\n2 2 2\n3 3 3"] | 2 seconds | ["6", "3"] | NoteIn the first sample, it's possible to leave $$$6$$$ cells with indexes $$$1, 5, 6, 7, 8, 9$$$.In the second sample, it's possible to leave $$$3$$$ cells with indexes $$$1, 2, 3$$$. | Java 11 | standard input | [
"binary search",
"implementation",
"sortings"
] | 1e9e504e6a2a9cef8d9946aae512a388 | The first line of the input contains a single integer $$$n$$$ — the number of the marked cells ($$$3 \leq n \le 10^5$$$, $$$n$$$ is divisible by 3). The $$$i$$$-th of the following $$$n$$$ lines contains three integers $$$x_i$$$, $$$y_i$$$, $$$c_i$$$ ($$$|x_i|,|y_i| \leq 10^9$$$; $$$1 \leq c_i \leq 3$$$), where $$$(x_i, y_i)$$$ are the coordinates of the $$$i$$$-th marked cell and $$$c_i$$$ is its color. It's guaranteed that all cells $$$(x_i, y_i)$$$ in the input are distinct, and that there are exactly $$$\frac{n}{3}$$$ cells of each color. | 2,800 | Output a single integer $$$k$$$ — the largest number of cells you can leave. | standard output | |
PASSED | 2ee71d5d1254bf1d3177a5780e33c967 | train_109.jsonl | 1639217100 | On an endless checkered sheet of paper, $$$n$$$ cells are chosen and colored in three colors, where $$$n$$$ is divisible by $$$3$$$. It turns out that there are exactly $$$\frac{n}{3}$$$ marked cells of each of three colors! Find the largest such $$$k$$$ that it's possible to choose $$$\frac{k}{3}$$$ cells of each color, remove all other marked cells, and then select three rectangles with sides parallel to the grid lines so that the following conditions hold: No two rectangles can intersect (but they can share a part of the boundary). In other words, the area of intersection of any two of these rectangles must be $$$0$$$. The $$$i$$$-th rectangle contains all the chosen cells of the $$$i$$$-th color and no chosen cells of other colors, for $$$i = 1, 2, 3$$$. | 256 megabytes | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.StringTokenizer;
import static java.lang.Math.max;
import static java.lang.Math.min;
public class s1608E {
int[][] C = {
{1, 2, 3},
{1, 3, 2},
{2, 1, 3},
{2, 3, 1},
{3, 1, 2},
{3, 2, 1},
};
int n;
int[] totalC = new int[4];
int minTotalC = 0;
void solve() {
n = cint();
P[] a = new P[n];
for (int i = 0; i < n; i++) {
a[i] = new P(cint(), cint(), (byte)cint());
totalC[a[i].c]++;
}
//viz(a);
minTotalC = min(min(totalC[1], totalC[2]), totalC[3]);
int k = 0;
k = max(k, solve(a));
k = max(k, solve(rotate(a)));
k = max(k, solve(rotate(a)));
k = max(k, solve(rotate(a)));
cout(k*3);
}
int solve(P[] a) {
int k = 0;
P[] b = Arrays.copyOf(a, n);
Arrays.sort(a, Comparator.comparingInt((P o) -> o.x));
Arrays.sort(b, Comparator.comparingInt((P o) -> o.y));
for (int[] c : C) {
k = max(k, solveHor(a, c));
k = max(k, solveT(a, b, c));
}
return k;
}
int solveHor(P[] a, int[] c) {
int[] m = new int[3];
m[1] = totalC[c[1]];
int k = 0;
for (int i = 0, j = n-1; i <= j;) {
if (m[0] < m[2]) {
do {
if (a[i].c == c[0]) {
m[0]++;
}
if (a[i].c == c[1]) {
m[1]--;
}
i++;
} while (i <= j && a[i-1].x == a[i].x);
} else {
do {
if (a[j].c == c[2]) {
m[2]++;
}
if (a[j].c == c[1]) {
m[1]--;
}
j--;
} while (i <= j && a[j+1].x == a[j].x);
}
k = max(k, min(min(m[0], m[1]), m[2]));
}
return k;
}
int solveT(P[] a, P[] b, int[] c) {
int low = 0;
int high = minTotalC;
while (low <= high) {
int mid = (low + high) / 2;
boolean midVal = checkSolveT(a, b, c, mid);
if (midVal) {
low = mid + 1;
} else {
high = mid - 1;
}
}
return low - 1;
}
boolean checkSolveT(P[] a, P[] b, int[] c, int k) {
int t0 = 0, x0 = 0;
for (int i = 0; i < n && t0 < k; i++) {
if (a[i].c == c[0]) {
t0++;
x0 = a[i].x;
}
}
if (t0 < k) {
return false;
}
int t1 = 0, t2 = 0;
for (int i = 0, j = n-1; i <= j;) {
if (t1 < t2) {
do {
if (b[i].c == c[1] && b[i].x > x0) {
t1++;
}
i++;
} while (i <= j && b[i-1].y == b[i].y);
} else {
do {
if (b[j].c == c[2] && b[j].x > x0) {
t2++;
}
j--;
} while (i <= j && b[j+1].y == b[j].y);
}
}
return t1 >= k && t2 >= k;
}
P[] rotate(P[] a) {
for (int i = 0; i < n; i++) {
a[i] = new P(a[i].y, -a[i].x, a[i].c);
}
return a;
}
class P {
final int x;
final int y;
final byte c;
public P(int x, int y, byte c) {
this.x = x;
this.y = y;
this.c = c;
}
}
public static void main(String... args) {
// int t = in.nextInt();
// for (int test = 0; test < t; test++) {
new s1608E().solve();
// }
out.flush();
}
//
// void viz(P[] a) {
// try {
// int w = 2020;
// BufferedImage img = new BufferedImage(w, w, 1);
// Graphics g = img.getGraphics();
// g.setColor(Color.WHITE);
// g.fillRect(0, 0, w-1, w-1);
// g.setColor(Color.BLACK);
// g.drawLine(0, 1000, 2000, 1000);
// g.drawLine(1000, 0, 1000, 2000);
// int index = 0;
// for (P p : a) {
// index++;
// g.setColor(p.c == 1 ? Color.RED : (p.c == 2 ? Color.GREEN : Color.BLUE));
// int x = p.x / 1_000_000 + 1000;
// int y = p.y / 1_000_000 + 1000;
// g.fillOval(x, y, 20, 20);
// g.drawString(String.valueOf(index), x, y);
// }
// ImageIO.write(img, "png", new File("s1608E.png"));
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
static final QuickReader in = new QuickReader(System.in);
static final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, 131_072));
static int cint() {
return in.nextInt();
}
static long clong() {
return in.nextLong();
}
static String cstr() {
return in.nextLine();
}
static int[] carr_int(int n) {
return in.nextInts(n);
}
static long[] carr_long(int n) {
return in.nextLongs(n);
}
static void cout(int... a) {
StringBuilder buf = new StringBuilder();
for (int i = 0; i < a.length; i++) {
if (i != 0) {
buf.append(' ');
}
buf.append(a[i]);
}
out.println(buf);
}
static void cout(long... a) {
StringBuilder buf = new StringBuilder();
for (int i = 0; i < a.length; i++) {
if (i != 0) {
buf.append(' ');
}
buf.append(a[i]);
}
out.println(buf);
}
static void cout(Object o) {
out.println(o);
}
static class QuickReader {
BufferedReader in;
StringTokenizer token;
public QuickReader(InputStream ins) {
in = new BufferedReader(new InputStreamReader(ins));
token = new StringTokenizer("");
}
public boolean hasNext() {
while (!token.hasMoreTokens()) {
try {
String s = in.readLine();
if (s == null) {
return false;
}
token = new StringTokenizer(s);
} catch (IOException e) {
throw new InputMismatchException();
}
}
return true;
}
public String next() {
hasNext();
return token.nextToken();
}
public String nextLine() {
try {
String s = in.readLine();
token = new StringTokenizer("");
return s;
} catch (IOException e) {
throw new InputMismatchException();
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public int[] nextInts(int n) {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = nextInt();
}
return res;
}
public long nextLong() {
return Long.parseLong(next());
}
public long[] nextLongs(int n) {
long[] res = new long[n];
for (int i = 0; i < n; i++) {
res[i] = nextLong();
}
return res;
}
}
}
| Java | ["9\n2 3 1\n4 1 2\n2 1 3\n3 4 1\n5 3 2\n4 4 3\n2 4 1\n5 2 2\n3 5 3", "3\n1 1 1\n2 2 2\n3 3 3"] | 2 seconds | ["6", "3"] | NoteIn the first sample, it's possible to leave $$$6$$$ cells with indexes $$$1, 5, 6, 7, 8, 9$$$.In the second sample, it's possible to leave $$$3$$$ cells with indexes $$$1, 2, 3$$$. | Java 11 | standard input | [
"binary search",
"implementation",
"sortings"
] | 1e9e504e6a2a9cef8d9946aae512a388 | The first line of the input contains a single integer $$$n$$$ — the number of the marked cells ($$$3 \leq n \le 10^5$$$, $$$n$$$ is divisible by 3). The $$$i$$$-th of the following $$$n$$$ lines contains three integers $$$x_i$$$, $$$y_i$$$, $$$c_i$$$ ($$$|x_i|,|y_i| \leq 10^9$$$; $$$1 \leq c_i \leq 3$$$), where $$$(x_i, y_i)$$$ are the coordinates of the $$$i$$$-th marked cell and $$$c_i$$$ is its color. It's guaranteed that all cells $$$(x_i, y_i)$$$ in the input are distinct, and that there are exactly $$$\frac{n}{3}$$$ cells of each color. | 2,800 | Output a single integer $$$k$$$ — the largest number of cells you can leave. | standard output | |
PASSED | 98d216b03d5d94c0754e1adb3d8dfad6 | train_109.jsonl | 1639217100 | On an endless checkered sheet of paper, $$$n$$$ cells are chosen and colored in three colors, where $$$n$$$ is divisible by $$$3$$$. It turns out that there are exactly $$$\frac{n}{3}$$$ marked cells of each of three colors! Find the largest such $$$k$$$ that it's possible to choose $$$\frac{k}{3}$$$ cells of each color, remove all other marked cells, and then select three rectangles with sides parallel to the grid lines so that the following conditions hold: No two rectangles can intersect (but they can share a part of the boundary). In other words, the area of intersection of any two of these rectangles must be $$$0$$$. The $$$i$$$-th rectangle contains all the chosen cells of the $$$i$$$-th color and no chosen cells of other colors, for $$$i = 1, 2, 3$$$. | 256 megabytes | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.StringTokenizer;
import static java.lang.Math.max;
import static java.lang.Math.min;
/**
__ __
( _) ( _)
/ / \\ / /\_\_
/ / \\ / / | \ \
/ / \\ / / |\ \ \
/ / , \ , / / /| \ \
/ / |\_ /| / / / \ \_\
/ / |\/ _ '_| \ / / / \ \\
| / |/ 0 \0\ / | | \ \\
| |\| \_\_ / / | \ \\
| | |/ \.\ o\o) / \ | \\
\ | /\\`v-v / | | \\
| \/ /_| \\_| / | | \ \\
| | /__/_ `-` / _____ | | \ \\
\| [__] \_/ |_________ \ | \ ()
/ [___] ( \ \ |\ | | //
| [___] |\| \| / |/
/| [____] \ |/\ / / ||
( \ [____ / ) _\ \ \ \| | ||
\ \ [_____| / / __/ \ / / //
| \ [_____/ / / \ | \/ //
| / '----| /=\____ _/ | / //
__ / / | / ___/ _/\ \ | ||
(/-(/-\) / \ (/\/\)/ | / | /
(/\/\) / / //
_________/ / /
\____________/ (
@author KhanhNguyenn
*/
/* Interesting problem, ideas from machine learning model SVM, using bondary to do
segmentation for plane to do classification. There will be 2 shape
|a|b|c| | a |
----------
| b | c |
*/
public class s1608E {
int[][] C = {
{1, 2, 3},
{1, 3, 2},
{2, 1, 3},
{2, 3, 1},
{3, 1, 2},
{3, 2, 1},
};
int n;
int[] totalC = new int[4];
int minTotalC = 0;
void solve() {
n = cint();
P[] a = new P[n];
for (int i = 0; i < n; i++) {
a[i] = new P(cint(), cint(), (byte)cint());
totalC[a[i].c]++;
}
//viz(a);
minTotalC = min(min(totalC[1], totalC[2]), totalC[3]);
int k = 0;
k = max(k, solve(a));
k = max(k, solve(rotate(a)));
k = max(k, solve(rotate(a)));
k = max(k, solve(rotate(a)));
cout(k*3);
}
int solve(P[] a) {
int k = 0;
P[] b = Arrays.copyOf(a, n);
Arrays.sort(a, Comparator.comparingInt((P o) -> o.x));
Arrays.sort(b, Comparator.comparingInt((P o) -> o.y));
for (int[] c : C) {
k = max(k, solveHor(a, c));
k = max(k, solveT(a, b, c));
}
return k;
}
int solveHor(P[] a, int[] c) {
int[] m = new int[3];
m[1] = totalC[c[1]];
int k = 0;
for (int i = 0, j = n-1; i <= j;) {
if (m[0] < m[2]) {
do {
if (a[i].c == c[0]) {
m[0]++;
}
if (a[i].c == c[1]) {
m[1]--;
}
i++;
} while (i <= j && a[i-1].x == a[i].x);
} else {
do {
if (a[j].c == c[2]) {
m[2]++;
}
if (a[j].c == c[1]) {
m[1]--;
}
j--;
} while (i <= j && a[j+1].x == a[j].x);
}
k = max(k, min(min(m[0], m[1]), m[2]));
}
return k;
}
int solveT(P[] a, P[] b, int[] c) {
int low = 0;
int high = minTotalC;
while (low <= high) {
int mid = (low + high) / 2;
boolean midVal = checkSolveT(a, b, c, mid);
if (midVal) {
low = mid + 1;
} else {
high = mid - 1;
}
}
return low - 1;
}
boolean checkSolveT(P[] a, P[] b, int[] c, int k) {
int t0 = 0, x0 = 0;
for (int i = 0; i < n && t0 < k; i++) {
if (a[i].c == c[0]) {
t0++;
x0 = a[i].x;
}
}
if (t0 < k) {
return false;
}
int t1 = 0, t2 = 0;
for (int i = 0, j = n-1; i <= j;) {
if (t1 < t2) {
do {
if (b[i].c == c[1] && b[i].x > x0) {
t1++;
}
i++;
} while (i <= j && b[i-1].y == b[i].y);
} else {
do {
if (b[j].c == c[2] && b[j].x > x0) {
t2++;
}
j--;
} while (i <= j && b[j+1].y == b[j].y);
}
}
return t1 >= k && t2 >= k;
}
P[] rotate(P[] a) {
for (int i = 0; i < n; i++) {
a[i] = new P(a[i].y, -a[i].x, a[i].c);
}
return a;
}
class P {
final int x;
final int y;
final byte c;
public P(int x, int y, byte c) {
this.x = x;
this.y = y;
this.c = c;
}
}
public static void main(String... args) {
// int t = in.nextInt();
// for (int test = 0; test < t; test++) {
new s1608E().solve();
// }
out.flush();
}
static final QuickReader in = new QuickReader(System.in);
static final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, 131_072));
static int cint() {
return in.nextInt();
}
static long clong() {
return in.nextLong();
}
static String cstr() {
return in.nextLine();
}
static int[] carr_int(int n) {
return in.nextInts(n);
}
static long[] carr_long(int n) {
return in.nextLongs(n);
}
static void cout(int... a) {
StringBuilder buf = new StringBuilder();
for (int i = 0; i < a.length; i++) {
if (i != 0) {
buf.append(' ');
}
buf.append(a[i]);
}
out.println(buf);
}
static void cout(long... a) {
StringBuilder buf = new StringBuilder();
for (int i = 0; i < a.length; i++) {
if (i != 0) {
buf.append(' ');
}
buf.append(a[i]);
}
out.println(buf);
}
static void cout(Object o) {
out.println(o);
}
static class QuickReader {
BufferedReader in;
StringTokenizer token;
public QuickReader(InputStream ins) {
in = new BufferedReader(new InputStreamReader(ins));
token = new StringTokenizer("");
}
public boolean hasNext() {
while (!token.hasMoreTokens()) {
try {
String s = in.readLine();
if (s == null) {
return false;
}
token = new StringTokenizer(s);
} catch (IOException e) {
throw new InputMismatchException();
}
}
return true;
}
public String next() {
hasNext();
return token.nextToken();
}
public String nextLine() {
try {
String s = in.readLine();
token = new StringTokenizer("");
return s;
} catch (IOException e) {
throw new InputMismatchException();
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public int[] nextInts(int n) {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = nextInt();
}
return res;
}
public long nextLong() {
return Long.parseLong(next());
}
public long[] nextLongs(int n) {
long[] res = new long[n];
for (int i = 0; i < n; i++) {
res[i] = nextLong();
}
return res;
}
}
}
| Java | ["9\n2 3 1\n4 1 2\n2 1 3\n3 4 1\n5 3 2\n4 4 3\n2 4 1\n5 2 2\n3 5 3", "3\n1 1 1\n2 2 2\n3 3 3"] | 2 seconds | ["6", "3"] | NoteIn the first sample, it's possible to leave $$$6$$$ cells with indexes $$$1, 5, 6, 7, 8, 9$$$.In the second sample, it's possible to leave $$$3$$$ cells with indexes $$$1, 2, 3$$$. | Java 11 | standard input | [
"binary search",
"implementation",
"sortings"
] | 1e9e504e6a2a9cef8d9946aae512a388 | The first line of the input contains a single integer $$$n$$$ — the number of the marked cells ($$$3 \leq n \le 10^5$$$, $$$n$$$ is divisible by 3). The $$$i$$$-th of the following $$$n$$$ lines contains three integers $$$x_i$$$, $$$y_i$$$, $$$c_i$$$ ($$$|x_i|,|y_i| \leq 10^9$$$; $$$1 \leq c_i \leq 3$$$), where $$$(x_i, y_i)$$$ are the coordinates of the $$$i$$$-th marked cell and $$$c_i$$$ is its color. It's guaranteed that all cells $$$(x_i, y_i)$$$ in the input are distinct, and that there are exactly $$$\frac{n}{3}$$$ cells of each color. | 2,800 | Output a single integer $$$k$$$ — the largest number of cells you can leave. | standard output | |
PASSED | 10fd891603ef0bc32b62c17a228f43cb | train_109.jsonl | 1639217100 | On an endless checkered sheet of paper, $$$n$$$ cells are chosen and colored in three colors, where $$$n$$$ is divisible by $$$3$$$. It turns out that there are exactly $$$\frac{n}{3}$$$ marked cells of each of three colors! Find the largest such $$$k$$$ that it's possible to choose $$$\frac{k}{3}$$$ cells of each color, remove all other marked cells, and then select three rectangles with sides parallel to the grid lines so that the following conditions hold: No two rectangles can intersect (but they can share a part of the boundary). In other words, the area of intersection of any two of these rectangles must be $$$0$$$. The $$$i$$$-th rectangle contains all the chosen cells of the $$$i$$$-th color and no chosen cells of other colors, for $$$i = 1, 2, 3$$$. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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;
FastScanner in = new FastScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskE solver = new TaskE();
solver.solve(1, in, out);
out.close();
}
static class TaskE {
public void solve(int testNumber, FastScanner in, PrintWriter out) {
int n = in.nextInt();
int[] x = new int[n];
int[] y = new int[n];
int[] col = new int[n];
for (int i = 0; i < n; i++) {
x[i] = in.nextInt();
y[i] = in.nextInt();
col[i] = in.nextInt() - 1;
}
Point[] p = new Point[n];
for (int i = 0; i < n; i++) {
p[i] = new Point(x[i], y[i], col[i], i);
}
int[] byX = new int[n];
Arrays.sort(p, (u, v) -> (Integer.compare(u.x, v.x)));
for (int i = 0; i < n; i++) {
byX[i] = p[i].id;
}
int[] byY = new int[n];
Arrays.sort(p, (u, v) -> (Integer.compare(u.y, v.y)));
for (int i = 0; i < n; i++) {
byY[i] = p[i].id;
}
Arrays.sort(p, (u, v) -> (Integer.compare(u.id, v.id)));
int[][] perm3 = {
{0, 1, 2},
{0, 2, 1},
{1, 0, 2},
{1, 2, 0},
{2, 0, 1},
{2, 1, 0},
};
int l = 0;
int r = n / 3 + 1;
int[] nByX = new int[n];
int[] nByY = new int[n];
while (r - l > 1) {
int m = (l + r) / 2;
boolean ok = false;
outer:
for (int[] perm : perm3) {
for (int rot = 0; rot < 4; rot++) {
if (can(p, byX, byY, perm, m)) {
ok = true;
break outer;
}
for (int i = 0; i < n; i++) {
nByX[i] = byY[n - 1 - i];
nByY[i] = byX[i];
p[i].rotate90();
}
int[] t = byX;
byX = nByX;
nByX = t;
t = byY;
byY = nByY;
nByY = t;
}
}
if (ok) {
l = m;
} else {
r = m;
}
}
out.println(3 * l);
}
private boolean can(Point[] p, int[] byX, int[] byY, int[] perm, int k) {
return can0(p, byX, byY, perm, k) || can1(p, byX, byY, perm, k);
}
private boolean can0(Point[] p, int[] byX, int[] byY, int[] perm, int k) {
// One to the left, one to the right, one in-between.
int borderX = Integer.MIN_VALUE;
int cur = 0;
for (int i : byX) {
if (p[i].col == perm[0]) {
++cur;
if (cur == k) {
borderX = p[i].x;
break;
}
}
}
int newBorderX = Integer.MIN_VALUE;
cur = 0;
for (int i : byX) {
if (p[i].col == perm[1] && p[i].x > borderX) {
++cur;
if (cur == k) {
newBorderX = p[i].x;
break;
}
}
}
if (cur < k) {
return false;
}
cur = 0;
for (int i = 0; i < p.length; i++) {
if (p[i].col == perm[2] && p[i].x > newBorderX) {
++cur;
if (cur == k) {
return true;
}
}
}
return false;
}
private boolean can1(Point[] p, int[] byX, int[] byY, int[] perm, int k) {
// One to the left, two to the right on top one another.
int borderX = Integer.MIN_VALUE;
int cur = 0;
for (int i : byX) {
if (p[i].col == perm[0]) {
++cur;
if (cur == k) {
borderX = p[i].x;
break;
}
}
}
int borderY = Integer.MIN_VALUE;
cur = 0;
for (int i : byY) {
if (p[i].col == perm[1] && p[i].x > borderX) {
++cur;
if (cur == k) {
borderY = p[i].y;
break;
}
}
}
if (cur < k) {
return false;
}
cur = 0;
for (int i = 0; i < p.length; i++) {
if (p[i].col == perm[2] && p[i].x > borderX && p[i].y > borderY) {
++cur;
if (cur == k) {
return true;
}
}
}
return false;
}
class Point {
int x;
int y;
int col;
int id;
public Point(int x, int y, int col, int id) {
this.x = x;
this.y = y;
this.col = col;
this.id = id;
}
public void rotate90() {
int nx = -y;
int ny = x;
x = nx;
y = ny;
}
}
}
static class FastScanner {
private BufferedReader in;
private StringTokenizer st;
public FastScanner(InputStream stream) {
try {
in = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
} catch (Exception e) {
throw new AssertionError();
}
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
String rl = in.readLine();
if (rl == null) {
return null;
}
st = new StringTokenizer(rl);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["9\n2 3 1\n4 1 2\n2 1 3\n3 4 1\n5 3 2\n4 4 3\n2 4 1\n5 2 2\n3 5 3", "3\n1 1 1\n2 2 2\n3 3 3"] | 2 seconds | ["6", "3"] | NoteIn the first sample, it's possible to leave $$$6$$$ cells with indexes $$$1, 5, 6, 7, 8, 9$$$.In the second sample, it's possible to leave $$$3$$$ cells with indexes $$$1, 2, 3$$$. | Java 8 | standard input | [
"binary search",
"implementation",
"sortings"
] | 1e9e504e6a2a9cef8d9946aae512a388 | The first line of the input contains a single integer $$$n$$$ — the number of the marked cells ($$$3 \leq n \le 10^5$$$, $$$n$$$ is divisible by 3). The $$$i$$$-th of the following $$$n$$$ lines contains three integers $$$x_i$$$, $$$y_i$$$, $$$c_i$$$ ($$$|x_i|,|y_i| \leq 10^9$$$; $$$1 \leq c_i \leq 3$$$), where $$$(x_i, y_i)$$$ are the coordinates of the $$$i$$$-th marked cell and $$$c_i$$$ is its color. It's guaranteed that all cells $$$(x_i, y_i)$$$ in the input are distinct, and that there are exactly $$$\frac{n}{3}$$$ cells of each color. | 2,800 | Output a single integer $$$k$$$ — the largest number of cells you can leave. | standard output | |
PASSED | c3629a0e13549979b6acd2904f0af950 | train_109.jsonl | 1639217100 | On an endless checkered sheet of paper, $$$n$$$ cells are chosen and colored in three colors, where $$$n$$$ is divisible by $$$3$$$. It turns out that there are exactly $$$\frac{n}{3}$$$ marked cells of each of three colors! Find the largest such $$$k$$$ that it's possible to choose $$$\frac{k}{3}$$$ cells of each color, remove all other marked cells, and then select three rectangles with sides parallel to the grid lines so that the following conditions hold: No two rectangles can intersect (but they can share a part of the boundary). In other words, the area of intersection of any two of these rectangles must be $$$0$$$. The $$$i$$$-th rectangle contains all the chosen cells of the $$$i$$$-th color and no chosen cells of other colors, for $$$i = 1, 2, 3$$$. | 256 megabytes | import java.io.*;
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class E {
static long[][][][] cells;
static long[][] lims;
public static boolean check(int mid, int mask) {
if (mask == 7)
return true;
// System.out.println(Arrays.deepToString(lims) + " " + mid+" "+Integer.toBinaryString(mask));
boolean ans = false;
int bitc = Integer.bitCount(mask);
boolean first = true;
for (int i = 0; i < 3; i++) {
if ((mask & (1 << i)) != 0) {
continue;
}
if (bitc != 0 && !first)
break;
first = false;
for (int j = 0; j < 2; j++) {
int rem = mid;
int idx = 0;
long[] lastCell = null;
while (rem > 0 && idx < cells[i][j].length) {
if (isValid(cells[i][j][idx])) {
lastCell = cells[i][j][idx];
rem--;
}
idx++;
}
if (rem != 0) {
continue;
}
long old = lims[j][0];
lims[j][0] = Math.max(lims[j][0], lastCell[j] + 1);
ans = ans || check(mid, mask | (1 << i));
lims[j][0] = old;
rem = mid;
idx = cells[i][j].length - 1;
lastCell = null;
while (rem > 0 && idx < cells[i][j].length) {
if (isValid(cells[i][j][idx])) {
lastCell = cells[i][j][idx];
rem--;
}
idx--;
}
if (rem != 0) {
continue;
}
old = lims[j][1];
lims[j][1] = Math.min(lims[j][1], lastCell[j] - 1);
ans = ans || check(mid, mask | (1 << i));
lims[j][1] = old;
}
}
return ans;
}
private static boolean isValid(long[] cell) {
boolean ans = true;
for (int j = 0; j < 2; j++) {
ans &= lims[j][0] <= cell[j] && cell[j] <= lims[j][1];
}
// System.out.println(Arrays.deepToString(lims) + " " + Arrays.toString(cell) +" " +ans);
return ans;
}
public static void main(String[] args) throws IOException {
Reader sc = new Reader();
PrintWriter pw = new PrintWriter(System.out);
int n = sc.nextInt();
int lo = 1;
int hi = n / 3;
cells = new long[3][2][n / 3][2];
int[] size = new int[3];
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
int clr = sc.nextInt() - 1;
cells[clr][0][size[clr]][0] = x;
cells[clr][0][size[clr]][1] = y;
cells[clr][1][size[clr]][0] = x;
cells[clr][1][size[clr]++][1] = y;
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
int jj = j;
Arrays.sort(cells[i][j], (u, v) -> Long.compare(u[jj], v[jj]));
}
}
long INF = (long) 1e10;
int ans = 1;
while (lo <= hi) {
int mid = lo + hi >> 1;
lims = new long[][]{{-INF, INF}, {-INF, INF}};
if (check(mid, 0)) {
ans = mid;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
pw.println(ans * 3);
pw.close();
}
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') {
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 char nextChar() throws IOException {
byte c = read();
while (c != '.' && c != '*') {
c = read();
}
return (char) c;
}
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 | ["9\n2 3 1\n4 1 2\n2 1 3\n3 4 1\n5 3 2\n4 4 3\n2 4 1\n5 2 2\n3 5 3", "3\n1 1 1\n2 2 2\n3 3 3"] | 2 seconds | ["6", "3"] | NoteIn the first sample, it's possible to leave $$$6$$$ cells with indexes $$$1, 5, 6, 7, 8, 9$$$.In the second sample, it's possible to leave $$$3$$$ cells with indexes $$$1, 2, 3$$$. | Java 8 | standard input | [
"binary search",
"implementation",
"sortings"
] | 1e9e504e6a2a9cef8d9946aae512a388 | The first line of the input contains a single integer $$$n$$$ — the number of the marked cells ($$$3 \leq n \le 10^5$$$, $$$n$$$ is divisible by 3). The $$$i$$$-th of the following $$$n$$$ lines contains three integers $$$x_i$$$, $$$y_i$$$, $$$c_i$$$ ($$$|x_i|,|y_i| \leq 10^9$$$; $$$1 \leq c_i \leq 3$$$), where $$$(x_i, y_i)$$$ are the coordinates of the $$$i$$$-th marked cell and $$$c_i$$$ is its color. It's guaranteed that all cells $$$(x_i, y_i)$$$ in the input are distinct, and that there are exactly $$$\frac{n}{3}$$$ cells of each color. | 2,800 | Output a single integer $$$k$$$ — the largest number of cells you can leave. | standard output | |
PASSED | 1df920d8ac29add164f9f7b93951ca14 | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | import java.io.*;
import java.util.*;
public class MainClass{
public static void main(String[] args) throws IOException{
if (System.getProperty("ONLINE_JUDGE") == null) {
PrintStream ps = new PrintStream(new File("output.txt"));
InputStream is = new FileInputStream("input.txt");
System.setIn(is);
System.setOut(ps);
}
Scanner scn = new Scanner(System.in);
int tt = scn.nextInt();
// int tt = 1;
while(tt-- > 0){
int n = scn.nextInt();
int[] arr = new int[n];
for(int i = 0 ; i < arr.length ; i++){
arr[i] = scn.nextInt();
}
int[] parr = new int[n];
parr[0] = arr[0];
for(int i = 1 ; i < parr.length ; i++){
parr[i] = arr[i] + parr[i-1];
}
int check = 0;
for(int i = 1 ; i < arr.length ; i++){
int k = parr[i] - parr[i-1];
int cn = parr[i-1]-k;
if(cn >= 0 && k != 0){
check = 1;
break;
}
}
if(check == 1) System.out.println(-1);
else printarray(parr);
}
}
public static void debug(String a , int b){
// System.out.println(a + " " + b);
}
public static void debug(String a , long b){
// System.out.println(a + " " + b);
}
public static void printarray(int[] arr){
for(int i = 0 ; i < arr.length ; i++){
System.out.print(arr[i]+ " ");
}
System.out.println();
}
} | Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | cdd400fa3fec527649575be779d22796 | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;
public class A {
static FastScanner fs = new FastScanner();
public static void main(String[] args) {
// int tc = 1;
int tc = fs.nextInt();
while (tc-- > 0) {
solve();
}
}
//ans[i] = ans[i - 1] + arr[i];
public static void solve() {
int n = fs.nextInt();
int[] arr = fs.readArray(n);
int[] ans = new int[n];
int prev = arr[0];
ans[0] = prev;
for (int i = 1; i < n; i++) {
if (prev >= arr[i] && arr[i] != 0) {
System.out.println(-1);
return;
}
prev = prev + arr[i];
ans[i] = prev;
}
for (int i = 0; i < n; i++) {
System.out.print(ans[i] + " ");
}
System.out.println();
}
// ----------------------------------------------------------------------------------//
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());
}
char nextChar() {
return next().charAt(0);
}
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());
}
}
static class Debug {
public static void debug(long a) {
System.out.println("--> " + a);
}
public static void debug(long a, long b) {
System.out.println("--> " + a + " + " + b);
}
public static void debug(char a, char b) {
System.out.println("--> " + a + " + " + b);
}
public static void debug(int[] array) {
System.out.print("Array--> ");
System.out.println(Arrays.toString(array));
}
public static void debug(char[] array) {
System.out.print("Array--> ");
System.out.println(Arrays.toString(array));
}
public static void debug(HashMap<Integer, Integer> map) {
System.out.print("Map--> " + map.toString());
}
}
} | Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | 2bc0f30cc7454637c03df4268066a24a | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | /*package whatever //do not write package name here */
import java.util.*;
import java.lang.*;
import java.io.*;
public class codeforces {
static Scanner sc=new Scanner(System.in);
static void solve(){
int n=sc.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
int[] out=new int[n];
out[0]=arr[0];
for(int i=1;i<n;i++){
if(arr[i]<=out[i-1]&&arr[i]!=0){
System.out.println("-1");
return;
}
out[i]=out[i-1]+arr[i];
}
for(int i:out){
System.out.print(i+" ");
}System.out.println("");
}
public static void main(String[] args) {
int t=sc.nextInt();
while(t-->0){
solve();
}
}
} | Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | dcef68d0f1623643c0c5fe268860dc9d | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t-->0){
int n = s.nextInt();
int[] d = new int[n];
int[] a = new int[n];
for(int i=0;i<n;i++){
d[i] = s.nextInt();
}
a[0] = d[0];
boolean f=true;
for(int i=1;i<n;i++){
int add = (a[i-1] + d[i]);
int sub = (a[i-1] - d[i]);
// System.out.println(i+" "+add+" "+sub);
if(d[i]==0)a[i] = a[i-1];
else if( (add>=0 && sub>=0 && add!=sub)){
f=false;
break;
}
a[i] = a[i-1]+d[i];
}
if(!f) System.out.println(-1);
else {
for(int i=0;i<n;i++) System.out.print(a[i]+" ");
System.out.println();
}
}
}
}
| Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | 3082c42324be14937d8313889f352687 | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | /*
⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿
⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿
⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿
⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿
⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿
⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺
⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘
⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆
⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇
⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇
⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇
⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇
⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇
⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀
⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀
⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸
⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼
⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿
⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿
⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿
⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿
*/
import java.util.*;
public class Ex3 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int oo = 0; oo < t; oo++){
int n = in.nextInt();
int arr[] = new int[n];
boolean k = true;
StringBuilder scc = new StringBuilder();
for(int i = 0; i < n; i++){
arr[i] = in.nextInt();
}
for(int i = 1; i < arr.length; i++){
if(arr[i] <= arr[i-1] && arr[i] != 0){
k = false;
break;
}else {
arr[i] = arr[i]+arr[i-1];
}
}
if( k == false){
System.out.println(-1);
}else {
for (int i = 0; i < arr.length; i++) {
scc.append(arr[i]+ " ");
}
System.out.println(scc.toString());
}
}
}
public class ListNode<E> {
private E value;
private ListNode next;
public ListNode(E newVal, ListNode<E> newNext) {
value = newVal;
next = newNext;
}
public E getValue() {
return value;
}
public ListNode<E> getNext() {
return next;
}
public void setValue(E newValue) {
value = newValue;
}
public void setNext(ListNode<E> newNext) {
next = newNext;
}
}
} | Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | e1b83cb6be75936e2d481d4772615c1d | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes |
import java.util.ArrayList;
import java.util.Scanner;
public class ArrayRecovery {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
int size = scanner.nextInt();
int[] arr = new int[size];
ArrayList<Integer> newArr = new ArrayList<>();
for (int j = 0; j < size; j++) {
arr[j] = scanner.nextInt();
}
int lastValue = -arr[0];
boolean isBreaking = false;
newArr.add(arr[0]);
for (int j = 1; j < size; j++) {
int val = Math.abs(lastValue - arr[j]);
newArr.add(val);
int current = newArr.get(j - 1) - arr[j];
if (current >= 0 && current != val) {
isBreaking = true;
break;
}
lastValue = lastValue - arr[j];
}
if (isBreaking) {
System.out.println(-1);
continue;
}
for (int j = 0; j < size; j++) {
System.out.print(newArr.get(j) + " ");
}
System.out.println();
}
}
}
| Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | 4a977dd12046b2a44808e46c41f044dd | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | // package CODEFORCES;
import java.lang.reflect.Array;
import java.util.*;
public class ChienThan {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
int t = sc.nextInt();
outer : for(int k=0;k<t;k++){
int n= sc.nextInt();
int [] d= new int [n+10];
for(int i=0;i<n;i++){
d[i]= sc.nextInt();
}
if(d[0] < 0){
System.out.println(-1);
continue outer;
}
int [] a= new int [n+10];
a[0]= d[0];
for(int i=1;i<n;i++){
int ans = a[i-1] + d[i];
if(ans != a[i-1] - d[i]){
if(a[i-1] - d[i]>=0){
System.out.println(-1);
continue outer;
}
}
a[i]= ans ;
}
for(int i=0;i<n;i++){
System.out.print(a[i] + " ");
}
System.out.println("");
}
}
}
| Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | bc71d6465fc797a80989e2a34aae3d88 | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | import java.util.Scanner;
public class Restore {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int i = 0; i < t; i++) {
int n = in.nextInt();
int[] d = new int[n];
for (int j = 0; j < n; j++) {
d[j] = in.nextInt();
}
boolean two_or_more = false;
for (int j = 1; j < n; j++) {
if (d[j - 1] >= d[j] && d[j] != 0) {
two_or_more = true;
break;
} else {
d[j] += d[j - 1];
}
}
// Print output
if (two_or_more) {
System.out.println("-1");
} else {
System.out.print(d[0]);
for (int j = 1; j < n; j++) {
System.out.print(" " + d[j]);
}
System.out.println();
}
}
}
} | Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | f9449e32066efe1dfb6a011618f30853 | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Robot3 {
public static void main(String[] args) {
Scanner ss = new Scanner(System.in);
int n = ss.nextInt();
outer: for (int i = 0; i <n ; i++) {
int leng = ss.nextInt();
int[]a = new int[leng];
for (int j = 0; j <a.length ; j++) {a[j]=ss.nextInt();}
int[]b = a.clone();
for (int j = 1; j <a.length ; j++) {
a[j]=a[j-1]+a[j];
}
for (int j = 0; j < a.length-1; j++) {
if (b[j+1]!=0) {
if (a[j] - b[j + 1] >= 0) {
System.out.println(-1);
continue outer;
}
}
}
for (int j = 0; j < a.length; j++) {
System.out.print(a[j]+" ");
}
System.out.println();
}
}
} | Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | e04cbef19654f178d5f8ff5856feba65 | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Robot3 {
public static void main(String[] args) {
Scanner ss = new Scanner(System.in);
int n = ss.nextInt();
outer: for (int i = 0; i <n ; i++) {
int leng = ss.nextInt();
int[]a = new int[leng];
for (int j = 0; j <a.length ; j++) {a[j]=ss.nextInt();}
int[]b = a.clone();
for (int j = 1; j <a.length ; j++) {
a[j]=a[j-1]+a[j];
}
for (int j = 0; j < a.length-1; j++) {
if (b[j+1]!=0) {
if (a[j] - b[j + 1] >= 0) {
System.out.println(-1);
continue outer;
}
}
}
for (int j = 0; j < a.length; j++) {
System.out.print(a[j]+" ");
}
System.out.println();
}
}
} | Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | ace09abbdec937dbef4106eafac8a2e0 | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Robot3 {
public static void main(String[] args) {
Scanner ss = new Scanner(System.in);
int n = ss.nextInt();
outer: for (int i = 0; i <n ; i++) {
int leng = ss.nextInt();
int[]a = new int[leng];
for (int j = 0; j <a.length ; j++) {a[j]=ss.nextInt();}
int[]b = a.clone();
for (int j = 1; j <a.length ; j++) {
a[j]=a[j-1]+a[j];
}
for (int j = 0; j < a.length-1; j++) {
if (b[j+1]!=0) {
if (a[j] - b[j + 1] >= 0) {
System.out.println(-1);
continue outer;
}
}
}
for (int j = 0; j < a.length; j++) {
System.out.print(a[j]+" ");
}
System.out.println();
}
}
} | Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | c6c69af031a405b485a6519b4ce0da89 | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | import java.util.*;
import java.io.*;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.math.BigInteger;
public class Main{
static class P {
String g;
int x , y;
P(String g,int x ,int y) {
this.x = x;
this.y = y;
this.g = g;
}
}
static class Node {
long sum, pre;
Node(long a, long b) {
this.sum = a;
this.pre = b;
}
}
static class SegmentTree {
int l , r; // range responsible for
SegmentTree left , right;
int val;
SegmentTree(int l,int r,int a[]) {
this.l = l;
this.r = r;
if(l == r) {
this.val = a[l];
return;
}
int mid = l + (r-l)/2;
this.left = new SegmentTree(l ,mid , a);
this.right = new SegmentTree(mid + 1 , r,a);
this.val = this.left.val + this.right.val;
}
public int query(int left ,int right) {
if(this.l > right || this.r < left) return 0;
if(this.l >= left && this.r <= right) return this.val;
return this.left.query(left , right) + this.right.query(left , right);
}
// public void pointUpdate(int index ,long val) {
// if(this.l > index || this.r < index) return;
// if(this.l == this.r && this.l == index) {
// this.val = val;
// }
// this.left.pointUpdate(index ,val );
// this.right.pointUpdate(index , val);
// this.val = (this.left.val + this.right.val)%this.mod;
// }
public void rangeUpdate(int left , int right) {
if(this.l > right || this.r < left) return;
if(this.l >= left && this.r <= right) {
this.val += this.r-this.l + 1;
System.out.println(" now " + this.val);
return ;
}
this.left.rangeUpdate(left , right );
this.right.rangeUpdate(left , right );
this.val = this.left.val + this.right.val;
}
// public long valueAtK(int k) {
// if(this.l > k || this.r < k) return 0;
// if(this.l == this.r && this.l == k) {
// return this.val;
// }
// return join(this.left.valueAtK(k) , this.right.valueAtK(k));
// }
public int join(int a ,int b) {
return a + b;
}
}
static class Hash {
long hash[] ,mod = (long)1e9 + 7 , powT[] , prime , inverse[];
Hash(char []s) {
prime = 131;
int n = s.length;
powT = new long[n];
hash = new long[n];
inverse = new long[n];
powT[0] = 1;
inverse[n-1] = pow(pow(prime , n-1 ,mod), mod-2 , mod);
for(int i = 1;i < n; i++ ) {
powT[i] = (powT[i-1]*prime)%mod;
}
for(int i = n-2; i>= 0;i-=1) {
inverse[i] = (inverse[i+1]*prime)%mod;
}
hash[0] = (s[0] - 'a' + 1);
for(int i = 1; i < n;i++ ) {
hash[i] = hash[i-1] + ((s[i]-'a' + 1)*powT[i])%mod;
hash[i] %= mod;
}
}
public long hashValue(int l , int r) {
if(l == 0) return hash[r]%mod;
long ans = hash[r] - hash[l-1] +mod;
ans %= mod;
// System.out.println(inverse[l] + " " + pow(powT[l], mod- 2 , mod));
ans *= inverse[l];
ans %= mod;
return ans;
}
}
static class ConvexHull {
Stack<Integer>stack;
Stack<Integer>stack1;
int n;
Point arr[];
ConvexHull(Point arr[]) {
n = arr.length;
this.arr = arr;
Arrays.sort(arr , (a , b)-> {
if(a.x == b.x) return (int)(b.y-a.y);
return (int)(a.x-b.x);
});
Point min = arr[0];
stack = new Stack<>();
stack1 = new Stack<>();
stack.push(0);
stack1.push(0);
Point ob = new Point(2,2);
for(int i =1;i < n;i++) {
if(stack.size() < 2) stack.push(i);
else {
while(stack.size() >= 2) {
int a = stack.pop() , b = stack.pop() ,c = i;
int dir = ob.cross(arr[b] , arr[a] , arr[c]);
if(dir < 0) {
stack.push(b);
stack.push(a);
stack.push(c);
break;
}
stack.push(b);
}
if(stack.size() < 2) {
stack.push(i);
}
}
}
for(int i =1;i < n;i++) {
if(stack1.size() < 2) stack1.push(i);
else {
while(stack1.size() >= 2) {
int a = stack1.pop() , b = stack1.pop() ,c = i;
int dir = ob.cross(arr[b] , arr[a] , arr[c]);
if(dir > 0) {
stack1.push(b);
stack1.push(a);
stack1.push(c);
break;
}
stack1.push(b);
}
if(stack1.size() < 2) {
stack1.push(i);
}
}
}
}
public List<Point> getPoints() {
boolean vis[] = new boolean[n];
List<Point> list = new ArrayList<>();
// for(int x : stack) {
// list.add(arr[x]);
// vis[x] = true;
// }
for(int x : stack1) {
// if(vis[x]) continue;
list.add(arr[x]);
}
return list;
}
}
public static class Suffix implements Comparable<Suffix> {
int index;
int rank;
int next;
public Suffix(int ind, int r, int nr) {
index = ind;
rank = r;
next = nr;
}
public int compareTo(Suffix s) {
if (rank != s.rank) return Integer.compare(rank, s.rank);
return Integer.compare(next, s.next);
}
}
static class Point {
long x , y;
Point(long x , long y) {
this.x = x;
this.y = y;
}
public Point sub(Point a,Point b) {
return new Point(a.x - b.x , a.y-b.y);
}
public int cross(Point a ,Point b , Point c) {
Point g = sub(b,a) , l = sub(c, b);
long ans = g.y*l.x - g.x*l.y;
if(ans == 0) return 0;
if(ans < 0) return -1;
return 1;
}
}
static class Kattio extends PrintWriter {
private BufferedReader r;
private StringTokenizer st;
// standard input
public Kattio() { this(System.in, System.out); }
public Kattio(InputStream i, OutputStream o) {
super(o);
r = new BufferedReader(new InputStreamReader(i));
}
// USACO-style file input
public Kattio(String problemName) throws IOException {
super(new FileWriter(problemName + ".out"));
r = new BufferedReader(new FileReader(problemName + ".in"));
}
// returns null if no more input
public String next() {
try {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(r.readLine());
return st.nextToken();
} catch (Exception e) { }
return null;
}
public int nextInt() { return Integer.parseInt(next()); }
public double nextDouble() { return Double.parseDouble(next()); }
public long nextLong() { return Long.parseLong(next()); }
}
static HashMap<Integer ,List<int[]>> graph;
static Kattio sc = new Kattio();
static long mod = 998244353l;
static String endl = "\n" , gap = " ";
static HashMap<Integer , Long> value;
static int size[];
static int parent[];
static long fac[];
static long inv[];
static boolean vis[];
static int answer;
static HashSet<String> guess;
static long primePow[];
static int N;
static int dis[];
static int height[];
static long p[];
static int endTime[];
static int time;
static Boolean dp[][];
static HashMap<String , Long> dmap;
static long dirpair[][];
static HashSet<String> not;
static SegmentTree tree;
public static void main(String[] args)throws IOException {
long t = ri();
// int max = (int)1e5 + 10;
// fac = new long[max];
// fac[0] = 1;
// inv = new long[max];
// inv[0]= inverse(fac[0] ,mod);
// long mod = (long)1e9 + 7;
// for(int i = 1;i < max;i++) {
// fac[i] = i*fac[i-1];
// fac[i] %= mod;
// inv[i]= inverse(fac[i] ,mod);
// }
// List<Integer> list = new ArrayList<>();
// int MAX = (int)4e4;
// for(int i =1;i<=MAX;i++) {
// if(isPalindrome(i + "")) list.add(i);
// }
// // System.out.println(list);
// long dp[] = new long[MAX +1];
// dp[0] = 1;
// long mod = (long)(1e9+7);
// for(int x : list) {
// for(int i =1;i<=MAX;i++) {
// if(i >= x) {
// dp[i] += dp[i-x];
// dp[i] %= mod;
// }
// }
// }
// int MAK = (int)1e5 + 1;
// boolean seive[] = new boolean[MAK];
// Arrays.fill(seive , true);
// seive[1] = false;
// seive[0] = false;
// for (int i = 1; i < MAK; i++) {
// if(seive[i]) {
// for (int j = i+i; j < MAK; j+=i) {
// seive[j] = false;
// }
// }
// }
// // TreeSet<Long>primeSet = new TreeSet<>();
// // for(long i = 2;i <= (long)1e6;i++) {
// // if(seive[(int)i])primeSet.add(i);
// // }
// int MAX = (int)1e5 + 1;
// ArrayList<Integer> a[] = new ArrayList[MAX];
// for(int i =0;i < a.length;i++) a[i] = new ArrayList<>();
// boolean notPrime[] = new boolean[MAX];
// for(int i = 2;i<MAX;i++){
// if(notPrime[i]) continue;
// for(int j = i;j<MAX;j+=i){
// notPrime[j] = true;
// a[j].add(i);
// }
// }
int test_case = 1;
while(t-->0) {
// sc.print("Case #"+(test_case++)+": ");
solve();
}
sc.close();
}
public static int get(int x,int tree[]) {
int index = x;
int ans =0;
while(index > 0) {
ans += tree[index];
index -= index&(-index);
}
return ans;
}
static List<Integer> res[];
public static void solve() throws IOException {
int n = ri();
int a[] = rai(n);
int last = a[0];
for(int i = 1;i < n;i++) {
int t = a[i-1] - a[i] , t2 = a[i-1] + a[i];
if(t2 != t && t >= 0 && t2 >= 0) {
System.out.println(-1);
return ;
}
a[i] = t2;
}
for(int x : a) {
System.out.print(x + " ");
}
System.out.println();
}
public static boolean solve(int i , int last,int a[]) {
if(i >= a.length) return true;
if(dp[i][last] != null) return dp[i][last];
boolean one = solve(i + 1 , last + a[i] , a);
boolean k = one;
if(one) {
res[i].add(last + a[i]);
}
if(last - a[i]>=0) {
boolean two = solve(i + 1 , last - a[i] , a);
k|= two;
if(two) res[i].add(last-a[i]);
}
return dp[i][last] = k;
}
public static long lcm(long x , long y) {
return x/gcd(x , y)*y;
}
public static long ncr(int a , int b,long mod) {
if(a == b) return 1l;
return (((fac[a]*inv[b])%mod)*inv[a-b])%mod;
}
static long turnOffK(long n, long k) {
return (n & ~(1l << (k)));
}
public static void swap(int i,int j,int arr[]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static long max(long ...a) {
return maxArray(a);
}
public static void swap(int i,int j,long arr[]) {
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void swap(int i,int j,char arr[]) {
char temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static String slope(Point a , Point b) {
if((a.x-b.x) == 0) return "inf";
long n = a.y- b.y;
if(n == 0) return "0";
long m = a.x-b.x;
boolean neg = (n*m < 0?true:false);
n = Math.abs(n);
m = Math.abs(m);
long g = gcd(Math.abs(n),Math.abs(m));
n /= g;
m /= g;
String ans = n+"/"+m;
if(neg) ans = "-" + ans;
return ans;
}
public static int lis(int A[], int size) {
int[] tailTable = new int[size];
int len;
tailTable[0] = A[0];
len = 1;
for (int i = 1; i < size; i++) {
if (A[i] < tailTable[0]) tailTable[0] = A[i];
else if (A[i] > tailTable[len - 1]) tailTable[len++] = A[i];
else tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i];
}
return len;
}
public static int CeilIndex(int A[], int l, int r, int key) {
while (r - l > 1) {
int m = l + (r - l) / 2;
if (A[m] >= key) r = m;
else l = m;
}
return r;
}
public static int lcs(char a[] , char b[]) {
int n = a.length , m = b.length;
int dp[][] = new int[n + 1][m + 1];
for(int i =1;i <= n;i++) {
for(int j =1;j <= m;j++) {
if(a[i-1] == b[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
else dp[i][j] = Math.max(dp[i-1][j] , dp[i][j-1]);
}
}
return dp[n][m];
}
public static int find(int node) {
if(node == parent[node]) return node;
return parent[node] = find(parent[node]);
}
public static void merge(int a ,int b ) {
a = find(a);
b = find(b);
if(a == b) return;
if(size[a] >= size[b]) {
parent[b] = a;
size[a] += size[b];
// primePow[a] += primePow[b];
// primePow[b] = 0;
}
else {
parent[a] = b;
size[b] += size[a];
// primePow[b] += primePow[a];
// primePow[a] = 0;
}
}
public static void processPowerOfP(long arr[]) {
int n = arr.length;
arr[0] = 1;
long mod = (long)1e9 + 7;
for(int i =1;i<n;i++) {
arr[i] = arr[i-1]*51;
arr[i] %= mod;
}
}
public static long hashValue(char s[]) {
int n = s.length;
long powerOfP[] = new long[n];
processPowerOfP(powerOfP);
long ans =0;
long mod = (long)1e9 + 7;
for(int i =0;i<n;i++) {
ans += (s[i]-'a'+1)*powerOfP[i];
ans %= mod;
}
return ans;
}
public static void dfs(int r,int c,char arr[][]) {
int n = arr.length , m = arr[0].length;
arr[r][c] = '#';
for(int i =0;i<4;i++) {
int nr = r + colx[i] , nc = c + coly[i];
if(nr < 0 || nc < 0 || nc >= m || nr>=n) continue;
if(arr[nr][nc] == '#') continue;
dfs(nr,nc,arr);
}
}
public static double getSlope(int a , int b,int x,int y) {
if(a-x == 0) return Double.MAX_VALUE;
if(b-y == 0) return 0.0;
return ((double)b-(double)y)/((double)a-(double)x);
}
public static boolean collinearr(long a[] , long b[] , long c[]) {
return (b[1]-a[1])*(b[0]-c[0]) == (b[0]-a[0])*(b[1]-c[1]);
}
public static boolean isSquare(long sum) {
long root = (int)Math.sqrt(sum);
return root*root == sum;
}
public static int[] suffixArray(String s) {
int n = s.length();
Suffix[] su = new Suffix[n];
for (int i = 0; i < n; i++) {
su[i] = new Suffix(i, s.charAt(i) - '$', 0);
}
for (int i = 0; i < n; i++)
su[i].next = (i + 1 < n ? su[i + 1].rank : -1);
Arrays.sort(su);
int[] ind = new int[n];
for (int length = 4; length < 2 * n; length <<= 1) {
int rank = 0, prev = su[0].rank;
su[0].rank = rank;
ind[su[0].index] = 0;
for (int i = 1; i < n; i++) {
if (su[i].rank == prev && su[i].next == su[i - 1].next) {
prev = su[i].rank;
su[i].rank = rank;
}
else {
prev = su[i].rank;
su[i].rank = ++rank;
}
ind[su[i].index] = i;
}
for (int i = 0; i < n; i++) {
int nextP = su[i].index + length / 2;
su[i].next = nextP < n ?
su[ind[nextP]].rank : -1;
}
Arrays.sort(su);
}
int[] suf = new int[n];
for (int i = 0; i < n; i++)
suf[i] = su[i].index;
return suf;
}
public static boolean isPalindrome(String s) {
int i =0 , j = s.length() -1;
while(i <= j && s.charAt(i) == s.charAt(j)) {
i++;
j--;
}
return i>j;
}
// digit dp hint;
public static long callfun(String num , int N, int last ,int secondLast ,int bound ,long dp[][][][]) {
if(N == 1) {
if(last == -1 || secondLast == -1) return 0;
long answer = 0;
int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9;
for(int i = 0;i<=max;i++) {
if(last > secondLast && last > i) {
answer++;
}
if(last < secondLast && last < i) {
answer++;
}
}
return answer;
}
if(secondLast == -1 || last == -1 ){
long answer = 0l;
int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9;
for(int i =0;i<=max;i++) {
int nl , nsl , newbound = bound==0?0:i==max?1:0;
if(last == - 1&& secondLast == -1 && i == 0) {
nl = -1 ; nsl = -1;
}
else {
nl = i;nsl = last;
}
long temp = callfun(num , N-1 , nl , nsl ,newbound, dp);
answer += temp;
if(last != -1 && secondLast != -1 &&((last > secondLast && last > i)||(last < secondLast && last < i))) answer++;
}
return answer;
}
if(dp[N][last][secondLast][bound] != -1) return dp[N][last][secondLast][bound];
long answer = 0l;
int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9;
for(int i =0;i<=max;i++) {
int nl , nsl , newbound = bound==0?0:i==max?1:0;
if(last == - 1&& secondLast == -1 && i == 0) {
nl = -1 ; nsl = -1;
}
else {
nl = i;nsl = last;
}
long temp = callfun(num , N-1 , nl , nsl ,newbound,dp);
answer += temp;
if(last != -1 && secondLast != -1 &&((last > secondLast && last > i)||(last < secondLast && last < i))) answer++;
}
return dp[N][last][secondLast][bound] = answer;
}
public static Long callfun(int index ,int pair,int arr[],Long dp[][]) {
long mod = 998244353l;
if(index >= arr.length) return 1l;
if(dp[index][pair] != null) return dp[index][pair];
Long sum = 0l , ans = 0l;
if(arr[index]%2 == pair) {
return dp[index][pair] = callfun(index + 1,pair^1 , arr,dp)%mod + callfun(index + 1 ,pair , arr , dp)%mod;
}
else {
return dp[index][pair] = callfun(index + 1,pair , arr,dp)%mod;
}
// for(int i =index;i<arr.length;i++) {
// sum += arr[i];
// if(sum%2 == pair) {
// ans = ans + callfun(i + 1,pair^1,arr , dp)%mod;
// ans%=mod;
// }
// }
// return dp[index][pair] = ans;
}
public static boolean callfun(int index , int n,int neg , int pos , String s) {
if(neg < 0 || pos < 0) return false;
if(index >= n) return true;
if(s.charAt(0) == 'P') {
if(neg <= 0) return false;
return callfun(index + 1,n , neg-1 , pos , s.charAt(1) + "N");
}
else {
if(pos <= 0) return false;
return callfun(index + 1 , n , neg , pos-1 , s.charAt(1) + "P");
}
}
public static void getPerm(int n , char arr[] , String s ,List<String>list) {
if(n == 0) {
list.add(s);
return;
}
for(char ch : arr) {
getPerm(n-1 , arr , s+ ch,list);
}
}
public static int getLen(int i ,int j , char s[]) {
while(i >= 0 && j < s.length && s[i] == s[j]) {
i--;
j++;
}
i++;
j--;
if(i>j) return 0;
return j-i + 1;
}
public static int getMaxCount(String x) {
char s[] = x.toCharArray();
int max = 0;
int n = s.length;
for(int i =0;i<n;i++) {
max = Math.max(max,Math.max(getLen(i , i,s) , getLen(i ,i+1,s)));
}
return max;
}
public static double getDis(int arr[][] , int x, int y) {
double ans = 0.0;
for(int a[] : arr) {
int x1 = a[0] , y1 = a[1];
ans += Math.sqrt((x-x1)*(x-x1) + (y-y1)*(y-y1));
}
return ans;
}
public static boolean valid(String x ) {
if(x.length() == 0) return true;
if(x.length() == 1) return false;
char s[] = x.toCharArray();
if(x.length() == 2) {
if(s[0] == s[1]) {
return false;
}
return true;
}
int r = 0 , b = 0;
for(char ch : x.toCharArray()) {
if(ch == 'R') r++;
else b++;
}
return (r >0 && b >0);
}
public static void primeDivisor(HashMap<Long , Long >cnt , long num) {
for(long i = 2;i*i<=num;i++) {
while(num%i == 0) {
cnt.put(i ,(cnt.getOrDefault(i,0l) + 1));
num /= i;
}
}
if(num > 2) {
cnt.put(num ,(cnt.getOrDefault(num,0l) + 1));
}
}
public static boolean isSubsequene(char a[], char b[] ) {
int i =0 , j = 0;
while(i < a.length && j <b.length) {
if(a[i] == b[j]) {
j++;
}
i++;
}
return j >= b.length;
}
public static long fib(int n ,long M) {
if (n == 0) {
return 0;
} else if (n == 1) {
return 1;
} else {
long[][] mat = {{1, 1}, {1, 0}};
mat = pow(mat, n-1 , M);
return mat[0][0];
}
}
public static long[][] pow(long[][] mat, int n ,long M) {
if (n == 1) return mat;
else if (n % 2 == 0) return pow(mul(mat, mat , M), n/2 , M);
else return mul(pow(mul(mat, mat,M), n/2,M), mat , M);
}
static long[][] mul(long[][] p, long[][] q,long M) {
long a = (p[0][0]*q[0][0] + p[0][1]*q[1][0])%M;
long b = (p[0][0]*q[0][1] + p[0][1]*q[1][1])%M;
long c = (p[1][0]*q[0][0] + p[1][1]*q[1][0])%M;
long d = (p[1][0]*q[0][1] + p[1][1]*q[1][1])%M;
return new long[][] {{a, b}, {c, d}};
}
public static long[] kdane(long arr[]) {
int n = arr.length;
long dp[] = new long[n];
dp[0] = arr[0];
long ans = dp[0];
for(int i = 1;i<n;i++) {
dp[i] = Math.max(dp[i-1] + arr[i] , arr[i]);
ans = Math.max(ans , dp[i]);
}
return dp;
}
public static void update(int low , int high , int l , int r, int val , int treeIndex ,int tree[]) {
if(low > r || high < l || high < low) return;
if(l <= low && high <= r) {
System.out.println("At " +low + " and " + high + " ans ttreeIndex " + treeIndex);
tree[treeIndex] += val;
return;
}
int mid = low + (high - low)/2;
update(low , mid , l , r , val , treeIndex*2 + 1, tree);
update(mid + 1 , high , l , r , val , treeIndex*2 + 2 , tree);
}
// static int colx[] = {1 ,1, -1,-1 , 2,2,-2,-2};
// static int coly[] = {-2 ,2, 2,-2,1,-1,1,-1};
static int colx[] = {1 ,-1, 0,0 , 1,1,-1,-1};
static int coly[] = {0 ,0, 1,-1,1,-1,1,-1};
public static void reverse(char arr[]) {
int i =0 , j = arr.length-1;
while(i < j) {
swap(i , j , arr);
i++;
j--;
}
}
public static void reverse(long arr[]) {
int i =0 , j = arr.length-1;
while(i < j) {
swap(i , j , arr);
i++;
j--;
}
}
public static void reverse(int arr[]) {
int i =0 , j = arr.length-1;
while(i < j) {
swap(i , j , arr);
i++;
j--;
}
}
public static long inverse(long x , long mod) {
return pow(x , mod -2 , mod);
}
public static int maxArray(int arr[]) {
int ans = arr[0] , n = arr.length;
for(int i =1;i<n;i++) {
ans = Math.max(ans , arr[i]);
}
return ans;
}
public static long maxArray(long arr[]) {
long ans = arr[0];
int n = arr.length;
for(int i =1;i<n;i++) {
ans = Math.max(ans , arr[i]);
}
return ans;
}
public static int minArray(int arr[]) {
int ans = arr[0] , n = arr.length;
for(int i =0;i<n;i++ ) {
ans = Math.min(ans ,arr[i]);
}
return ans;
}
public static long minArray(long arr[]) {
long ans = arr[0];
int n = arr.length;
for(int i =0;i<n;i++ ) {
ans = Math.min(ans ,arr[i]);
}
return ans;
}
public static int sumArray(int arr[]) {
int ans = 0;
for(int x : arr) {
ans += x;
}
return ans;
}
public static long sumArray(long arr[]) {
long ans = 0;
for(long x : arr) {
ans += x;
}
return ans;
}
public static long rl() {
return sc.nextLong();
}
public static char[] rac() {
return sc.next().toCharArray();
}
public static String rs() {
return sc.next();
}
public static char rc() {
return sc.next().charAt(0);
}
public static int [] rai(int n) {
int ans[] = new int[n];
for(int i =0;i<n;i++) {
ans[i] = sc.nextInt();
}
return ans;
}
public static long [] ral(int n) {
long ans[] = new long[n];
for(int i =0;i<n;i++) {
ans[i] = sc.nextLong();
}
return ans;
}
public static int ri() {
return sc.nextInt();
}
public static int getValue(int num ) {
int ans = 0;
while(num > 0) {
ans++;
num = num&(num-1);
}
return ans;
}
public static boolean isValid(int x ,int y , int n,char arr[][],boolean visited[][][][]) {
return x>=0 && x<n && y>=0 && y <n && !(arr[x][y] == '#');
}
// public static Pair join(Pair a , Pair b) {
// Pair res = new Pair(Math.min(a.min , b.min) , Math.max(a.max , b.max) , a.count + b.count);
// return res;
// }
// segment tree query over range
// public static int query(int node,int l , int r,int a,int b ,Pair tree[] ) {
// if(tree[node].max < a || tree[node].min > b) return 0;
// if(l > r) return 0;
// if(tree[node].min >= a && tree[node].max <= b) {
// return tree[node].count;
// }
// int mid = l + (r-l)/2;
// int ans = query(node*2 ,l , mid ,a , b , tree) + query(node*2 +1,mid + 1, r , a , b, tree);
// return ans;
// }
// // segment tree update over range
// public static void update(int node, int i , int j ,int l , int r,long value, long arr[] ) {
// if(l >= i && j >= r) {
// arr[node] += value;
// return;
// }
// if(j < l|| r < i) return;
// int mid = l + (r-l)/2;
// update(node*2 ,i ,j ,l,mid,value, arr);
// update(node*2 +1,i ,j ,mid + 1,r, value , arr);
// }c
public static long pow(long a , long b , long mod) {
if(b == 1) return a;
if(b == 0) return 1;
long ans = pow(a , b/2 , mod)%mod;
if(b%2 == 0) {
return (ans*ans)%mod;
}
else {
return ((ans*ans)%mod*a)%mod;
}
}
public static long pow(long a , long b ) {
if(b == 1) return a;
if(b == 0) return 1;
long ans = pow(a , b/2);
if(b%2 == 0) {
return (ans*ans);
}
else {
return ((ans*ans)*a);
}
}
public static boolean isVowel(char ch) {
if(ch == 'a' || ch == 'e'||ch == 'i' || ch == 'o' || ch == 'u') return true;
if((ch == 'A' || ch == 'E'||ch == 'I' || ch == 'O' || ch == 'U')) return true;
return false;
}
// public static int getFactor(int num) {
// if(num==1) return 1;
// int ans = 2;
// int k = num/2;
// for(int i = 2;i<=k;i++) {
// if(num%i==0) ans++;
// }
// return Math.abs(ans);
// }
public static int[] readarr()throws IOException {
int n = sc.nextInt();
int arr[] = new int[n];
for(int i =0;i<n;i++) {
arr[i] = sc.nextInt();
}
return arr;
}
public static boolean isPowerOfTwo (long x) {
return x!=0 && ((x&(x-1)) == 0);
}
public static boolean isPrime(long num) {
if(num==1) return false;
if(num<=3) return true;
if(num%2==0||num%3==0) return false;
for(long i =5;i*i<=num;i+=6) {
if(num%i==0 || num%(i+2) == 0) return false;
}
return true;
}
public static boolean isPrime(int num) {
// System.out.println("At pr " + num);
if(num==1) return false;
if(num<=3) return true;
if(num%2==0||num%3==0) return false;
for(int i =5;i*i<=num;i+=6) {
if(num%i==0 || num%(i+2) == 0) return false;
}
return true;
}
// public static boolean isPrime(long num) {
// if(num==1) return false;
// if(num<=3) return true;
// if(num%2==0||num%3==0) return false;
// for(int i =5;i*i<=num;i+=6) {
// if(num%i==0) return false;
// }
// return true;
// }
public static void allMultiple() {
// int MAX = 0 , n = nums.length;
// for(int x : nums) MAX = Math.max(MAX ,x);
// int cnt[] = new int[MAX + 1];
// int ans[] = new int[MAX + 1];
// for (int i = 0; i < n; ++i) cnt[nums[i]]++;
// for (int i = 1; i <= MAX; ++i) {
// for (int j = i; j <= MAX; j += i) ans[i] += cnt[j];
// }
}
public static long gcd(long a , long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static int gcd(int a , int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static int get_gcd(int a , int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static long get_gcd(long a , long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
// public static long fac(long num) {
// long ans = 1;
// int mod = (int)1e9+7;
// for(long i = 2;i<=num;i++) {
// ans = (ans*i)%mod;
// }
// return ans;
// }
} | Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | 1ed422bb97edb65aef5ef497445d0334 | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | import com.sun.security.jgss.GSSUtil;
import com.sun.source.tree.ModuleTree;
import org.w3c.dom.ls.LSOutput;
import java.io.*;
import java.security.spec.RSAOtherPrimeInfo;
import java.sql.Array;
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 boolean func(long x,long k){
return (k-((x*x)+(x)+1))%(2*x)==0;
}
public static void gg(int [] arr, int l, int r, int count , int[] ans){
if(r<l){
return;
}
if(r==l){
ans[l]=count;
return;
}
int m=l;
for(int i=l+1;i<=r;i++){
if(arr[i]>arr[m]){
m=i;
}
}
ans[m]=count;
gg(arr,l,m-1,count+1,ans);
gg(arr,m+1,r,count+1,ans);
}
public static void main(String[] args) {
//RSRRSRSSSR
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];
int [] mnb=new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
mnb[i]=arr[i];
}
boolean temp=false;
int gfg=0;
for(int i=1;i<n;i++){
if(arr[i]==0) {
arr[i]=arr[i-1];
gfg=arr[i];
}
else if(arr[i]>arr[i-1]){
arr[i]=arr[i]+arr[i-1];
}else{
temp=true;
break;
}
}
if(temp){
System.out.println(-1);
}else{
System.out.print(mnb[0]+" ");
int gg=mnb[0];
for(int i=1;i<n;i++){
System.out.print((gg+mnb[i])+" ");
gg=gg+mnb[i];
}
System.out.println();
}
}
}catch(Exception e){
return;
}
}
public static void gffg(int n,int [] bit){
int count=31;
while(n>0){
if((n&1)==1){
bit[count]+=1;
}
count--;
n=n>>1;
}
}
public static void bit(int n,int[][] one){
int count=31;
int m=n;
while(n>0){
if((n&1)==1){
one[m][count]=one[m-1][count]+1;
}
else{
one[m][count]=one[m-1][count];
}
count--;
n=n>>1;
}
}
private static char get(StringBuilder sb, int i,char ff,char ss) {
if(i==sb.length()-1){
for(int f = 0; f<26; f++){
if((char)('a'+f)!=ff ){
return (char) ('a'+ f);
}
}
}
else if(i==sb.length()-2){
for(int f = 0; f<26; f++){
if((char)('a'+f)!=ff && (char)('a'+f)!=ss && (char)('a'+f)!=sb.charAt(i+1) ){
return (char) ('a'+ f);
}
}
}else{
for(int f = 0; f<26; f++){
if((char)('a'+f)!=ff && (char)('a'+f)!=ss && (char)('a'+f)!=sb.charAt(i+1) && (char)('a'+f)!=sb.charAt(i+2)){
return (char) ('a'+ f);
}
}
}
return 'l';
}
public static int gg(int num){
int count=0;
while(num>0){
count++;
num=(num>>1);
}
return count;
}
private static void swap(int[] arr, int i, int ii) {
int 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 | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | bbf6b5220062a17694b3a0139492b003 | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static Scanner obj = new Scanner(System.in);
public static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) {
int len = obj.nextInt();
while (len-- != 0) {
int n=obj.nextInt();
int[] a=new int[n];
int[] ans=new int[n];
for(int i=0;i<n;i++)a[i]=obj.nextInt();
ans[0]=a[0];
boolean tell=true;
for(int i=1;i<n;i++)
{
int val=ans[i-1];
int v1=val+a[i];
int v2=val-a[i];
if(v2>=0 && v1!=v2)tell=false;
ans[i]=val+a[i];
}
if(!tell)out.println(-1);
else
{
for(int i=0;i<n;i++)out.print(ans[i]+" ");
out.println();
}
}
out.flush();
}
} | Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | 51fba63a09437c30a2b39dea190dfdb5 | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | import java.util.*;
public class ProblemA {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int[] d = new int[n];
for(int i=0;i<n;i++){
d[i] = sc.nextInt();
}
int[] ans = new int[n];
ans[0] = d[0];
boolean flag = true;
boolean f = false;
for(int i=0;i<n;i++){
if(d[i] != 0){
f = true;
break;
}
}
for(int i=1;i<n;i++){
if(ans[i-1] - d[i] >= 0 && ans[i-1]+d[i] != ans[i-1] - d[i] && f == true){
System.out.print(-1);
flag = false;
break;
}
ans[i] = d[i]+ans[i-1];
}
if(flag == true){
for(int i=0;i<ans.length;i++){
System.out.print(ans[i] + " ");
}
}
System.out.println();
}
}
}
| Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | 787a3b0c5487c4b29e04fdaeecd6467d | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | import java.io.*;
import java.util.*;
public class cf {
public static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
public static boolean isok(long x, long h, long k) {
long sum = 0;
if (h > k) {
long t1 = h - k;
long t = t1 * k;
sum += (k * (k + 1)) / 2;
sum += t - (t1 * (t1 + 1) / 2);
} else {
sum += (h * (h + 1)) / 2;
}
if (sum < x) {
return true;
}
return false;
}
public static boolean binary_search(long[] a, long k) {
long low = 0;
long high = a.length - 1;
long mid = 0;
while (low <= high) {
mid = low + (high - low) / 2;
if (a[(int) mid] == k) {
return true;
} else if (a[(int) mid] < k) {
low = mid + 1;
} else {
high = mid - 1;
}
}
return false;
}
public static long lowerbound(long a[], long ddp) {
long low = 0;
long high = a.length;
long mid = 0;
while (low < high) {
mid = low + (high - low) / 2;
if (a[(int) mid] == ddp) {
return mid;
}
if (a[(int) mid] < ddp) {
low = mid + 1;
} else {
high = mid;
}
}
// if(low + 1 < a.length && a[(int)low + 1] <= ddp){
// low++;
// }
if (low == a.length && low != 0) {
low--;
return low;
}
if (a[(int) low] > ddp && low != 0) {
low--;
}
return low;
}
public static long upperbound(long a[], long ddp) {
long low = 0;
long high = a.length;
long mid = 0;
while (low < high) {
mid = low + (high - low) / 2;
if (a[(int) mid] <= ddp) {
low = mid + 1;
} else {
high = mid;
}
}
if (low == a.length) {
return a.length - 1;
}
return low;
}
// public static class pair implements Comparable<pair> {
// long w;
// long h;
// public pair(long w, long h) {
// this.w = w;
// this.h = h;
// }
// public int compareTo(pair b) {
// if (this.w != b.w)
// return (int) (this.w - b.w);
// else
// return (int) (this.h - b.h);
// }
// }
public static class pair {
long w;
long h;
public pair(long w, long h) {
this.w = w;
this.h = h;
}
}
public static class trinary {
long a;
long b;
long c;
public trinary(long a, long b, long c) {
this.a = a;
this.b = b;
this.c = c;
}
}
public static long lowerboundforpairs(pair a[], double pr) {
long low = 0;
long high = a.length;
long mid = 0;
while (low < high) {
mid = low + (high - low) / 2;
if (a[(int) mid].w <= pr) {
low = mid + 1;
} else {
high = mid;
}
}
// if(low + 1 < a.length && a[(int)low + 1] <= ddp){
// low++;
// }
// if(low == a.length && low != 0){
// low--;
// return low;
// }
// if(a[(int)low].w > pr && low != 0){
// low--;
// }
return low;
}
public static pair[] sortpair(pair[] a) {
Arrays.sort(a, new Comparator<pair>() {
public int compare(pair p1, pair p2) {
if (p1.w != p2.w) {
return (int) (p1.w - p2.w);
}
return (int) (p1.h - p2.h);
}
});
return a;
}
public static trinary[] sortpair(trinary[] a) {
Arrays.sort(a, new Comparator<trinary>() {
public int compare(trinary p1, trinary p2) {
if (p1.b != p2.b) {
return (int) (p1.b - p2.b);
} else if (p1.c != p2.c) {
return (int) (p1.c - p2.c);
}
return (int) (p1.a - p2.a);
}
});
return a;
}
public static boolean ispalindrome(String s) {
long i = 0;
long j = s.length() - 1;
boolean is = false;
while (i < j) {
if (s.charAt((int) i) == s.charAt((int) j)) {
is = true;
i++;
j--;
} else {
is = false;
return is;
}
}
return is;
}
public static void sort(long[] arr) {
ArrayList<Long> a = new ArrayList<>();
for (long i : arr) {
a.add(i);
}
Collections.sort(a);
for (int i = 0; i < a.size(); i++) {
arr[i] = a.get(i);
}
}
public static void sortForObjecttypes(pair[] arr) {
ArrayList<pair> a = new ArrayList<>();
for (pair i : arr) {
a.add(i);
}
Collections.sort(a, new Comparator<pair>() {
@Override
public int compare(pair a, pair b) {
return (int) (a.h - b.h);
}
});
for (int i = 0; i < a.size(); i++) {
arr[i] = a.get(i);
}
}
public static long power(long base, long pow, long mod) {
long result = base;
long temp = 1;
while (pow > 1) {
if (pow % 2 == 0) {
result = ((result % mod) * (result % mod)) % mod;
pow /= 2;
} else {
temp = temp * base;
pow--;
}
}
result = ((result % mod) * (temp % mod));
// System.out.println(result);
return result;
}
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;
}
void readArr(int[] ar, int n) {
for (int i = 0; i < n; i++) {
ar[i] = nextInt();
}
}
}
public static int bSearchDiff(long[] a, int low, int high) {
int mid = low + ((high - low) / 2);
int hight = high;
int lowt = low;
while (lowt < hight) {
mid = lowt + (hight - lowt) / 2;
if (a[high] - a[mid] <= 5) {
hight = mid;
} else {
lowt = mid + 1;
}
}
return lowt;
}
public static boolean is[] = new boolean[1000001];
public static Vector<Integer> seiveOfEratosthenes() {
Vector<Integer> listA = new Vector<>();
int a[] = new int[1000001];
for (int i = 2; i * i <= a.length; i++) {
if (a[i] != 1) {
for (long j = i * i; j < a.length; j += i) {
a[(int) j] = 1;
}
}
}
for (int i = 2; i < a.length; i++) {
if (a[i] == 0) {
is[i] = true;
listA.add(i);
}
}
return listA;
}
// public static Vector<Integer> ans = seiveOfEratosthenes();
public static long lowerbound(long a[], long ddp, long factor) {
long low = 0;
long high = a.length;
long mid = 0;
while (low < high) {
mid = low + (high - low) / 2;
if ((a[(int) mid] + (mid * factor)) == ddp) {
return mid;
}
if ((a[(int) mid] + (mid * factor)) < ddp) {
low = mid + 1;
} else {
high = mid;
}
}
// if(low + 1 < a.length && a[(int)low + 1] <= ddp){
// low++;
// }
if (low == a.length && low != 0) {
low--;
return low;
}
if (a[(int) low] > ddp - (low * factor) && low != 0) {
low--;
}
return low;
}
public static void solve(FastReader sc, PrintWriter w, StringBuilder sb) throws Exception {
int n = sc.nextInt();
int d[] = new int[n];
int a[] = new int[n];
for(int i = 0;i < n;i++){
d[i] = sc.nextInt();
}
a[0] = d[0];
if(n == 1){
sb.append(a[0] + "\n");
return;
}
boolean is = false;
for(int i = 1;i < n;i++){
if(a[i - 1] == 0){
is = true;
a[i] = d[i];
}else if(d[i] == 0){
is = true;
a[i] = a[i - 1];
}else if(a[i - 1] < d[i]){
is = true;
a[i] = a[i - 1] + d[i];
}else{
is = false;
break;
}
// if(a[i - 1] == 0 && d[i] == 0){
// is = true;
// a[i] = 0;
// }else if(d[i] == 0){
// is = true;
// a[i] = a[i - 1];
// }else if(a[i - 1] < d[i]){
// is = true;
// a[i] = d[i] + a[i - 1];
// }else{
// is = false;
// break;
// }
}
if(is){
for(int i = 0;i < n;i++){
sb.append(a[i] + " ");
}
sb.append("\n");
}else{
sb.append(-1 + "\n");
}
}
public static void main(String[] args) throws Exception {
FastReader sc = new FastReader();
PrintWriter w = new PrintWriter(System.out);
StringBuilder sb = new StringBuilder();
long o = sc.nextLong();
while (o > 0) {
solve(sc, w, sb);
o--;
}
System.out.print(sb.toString());
w.close();
}
} | Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | 23e65f4f720875e255614cf18c17e67e | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public final class Solution
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner n1;
try {
n1 = new Scanner(new FileReader("./input.txt"));
} catch (Exception e) {
n1 = new Scanner(System.in);
}
PrintWriter output = new PrintWriter(System.out);
int xt = n1.nextInt();
while(xt-->0)
{
//int m = n1.nextInt();
int n = n1.nextInt();
int[] arr = new int[n];
for(int i= 0; i<n; i++) arr[i] = n1.nextInt();
solve(arr, n, output);
}
output.flush();
}
static void solve(int[] arr, int n, PrintWriter out) throws Exception
{
ArrayList<Integer> res = new ArrayList<>();
res.add(arr[0]);
for(int i = 1; i<n; i++)
{
if(arr[i]!=0 && arr[i]<=res.get(i-1))
{
out.println(-1);
return;
}
res.add(Math.abs(arr[i]+res.get(i-1)));
}
for(int i = 0; i<n-1; i++)
{
out.print(res.get(i)+" ");
}
out.println(res.get(n-1));
}
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;
}
}
}
| Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | 3adf82f70500f462ad79f29c666970b9 | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 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;
O : while(t-->0)
{
int n = sc.nextInt();
int a[] = sc.readArray(n);
ArrayList<Integer> list = new ArrayList<>();
list.add(a[0]);
for(int i=1;i<n;i++){
list.add(list.get(list.size()-1)+a[i]);
}
for(int i=list.size()-1;i>0;i--){
int diff = list.get(i) - list.get(i-1);
if(list.get(i-1) - diff >= 0 && diff != 0){
System.out.println(-1);
continue O;
}
}
for(int i=0;i<list.size();i++){
System.out.print(list.get(i)+ " ");
}
System.out.println();
}
out.flush();
}
static void printN()
{
System.out.println("NO");
}
static void printY()
{
System.out.println("YES");
}
static int findfrequencies(int a[],int n)
{
int count=0;
for(int i=0;i<a.length;i++)
{
if(a[i]==n)
{
count++;
}
}
return count;
}
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;
}
}
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;
}
static int[] EvenOddArragement(int nums[])
{
int i1=0,i2=nums.length-1;
while(i1<i2){
while(nums[i1]%2==0 && i1<i2){
i1++;
}
while(nums[i2]%2!=0 && i2>i1){
i2--;
}
int temp=nums[i1];
nums[i1]=nums[i2];
nums[i2]=temp;
}
return nums;
}
static int gcd(int a, int b) {
while (b != 0) {
int t = a;
a = b;
b = t % b;
}
return a;
}
static int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
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 int DigitSum(int n)
{
int r=0,sum=0;
while(n>=0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
return sum;
}
static boolean checkPerfectSquare(int number)
{
double sqrt=Math.sqrt(number);
return ((sqrt - Math.floor(sqrt)) == 0);
}
static boolean isPowerOfTwo(int n)
{
if(n==0)
return false;
return (int)(Math.ceil((Math.log(n) / Math.log(2)))) == (int)(Math.floor(((Math.log(n) / Math.log(2)))));
}
static boolean isPrime2(int n)
{
if (n <= 1)
{
return false;
}
if (n == 2)
{
return true;
}
if (n % 2 == 0)
{
return false;
}
for (int i = 3; i <= Math.sqrt(n) + 1; i = i + 2)
{
if (n % i == 0)
{
return false;
}
}
return true;
}
static String minLexRotation(String str)
{
int n = str.length();
String arr[] = new String[n];
String concat = str + str;
for(int i=0;i<n;i++)
{
arr[i] = concat.substring(i, i + n);
}
Arrays.sort(arr);
return arr[0];
}
static String maxLexRotation(String str)
{
int n = str.length();
String arr[] = new String[n];
String concat = str + str;
for (int i = 0; i < n; i++)
{
arr[i] = concat.substring(i, i + n);
}
Arrays.sort(arr);
return arr[arr.length-1];
}
static class P implements Comparable<P> {
int i, j;
public P(int i, int j) {
this.i=i;
this.j=j;
}
public int compareTo(P o) {
return Integer.compare(i, o.i);
}
}
static class pair{
int i,j;
pair(int x,int y){
i=x;
j=y;
}
}
static int binary_search(int a[],int value)
{
int start=0;
int end=a.length-1;
int mid=start+(end-start)/2;
while(start<=end)
{
if(a[mid]==value)
{
return mid;
}
if(a[mid]>value)
{
end=mid-1;
}
else
{
start=mid+1;
}
mid=start+(end-start)/2;
}
return -1;
}
} | Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | bb1080abfd131c69b0c9e94096f600ba | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 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 String getArr(int[] d){
String exit = "";
String summer = Integer.toString(d[0]);
int sum = d[0];
for (int i = 1;i<d.length;i++){
if ((sum-d[i]<0 || (sum-d[i]) == (sum+d[i]) )&& sum+d[i]>=0){
sum = sum +d[i];
summer = summer + " "+Integer.toString(sum);
}else{
exit = "-1";
break;
}
}
if (exit.equals("-1")){
return exit;
}else{
return summer;
}
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int iteration = scan.nextInt();
for (int i = 0;i<iteration;i++){
int input = scan.nextInt();
int[] d = new int[input];
for (int j = 0;j<input;j++){
d[j] = scan.nextInt();
}
System.out.println(getArr(d));
}
}
}
| Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | 66f8ce98d211e85c4d577228de319d63 | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | import java.util.Iterator;
import java.util.Scanner;
public class CF1739B {
abstract class ASolver<R> {
protected IResult<R> mresultCallBack;
protected R ans;
public void solve(Object... data) {
mresultCallBack = (IResult<R>)data[0];
}
public void getAnswer() {
mresultCallBack.resultCallback(ans);
}
}
interface IResult<R> {
void resultCallback(R res);
}
// =============================================================================
// TODO: do the code below
public static void main(String[] args) {
new CF1739B().solve();
}
void solve() {
Scanner scanner = new Scanner(System.in);
int t;
t = scanner.nextInt();
Solver[] sols = new Solver[t];
for(int i = 0; i < t; ++i) {
sols[i] = new Solver();
int n = scanner.nextInt();
int[] d = new int[n];
for(int j = 0; j < n; ++j) {
d[j] = scanner.nextInt();
}
sols[i].solve(new IResult<Integer[]>() {
@Override
public void resultCallback(Integer[] res) {
for (int k = 0; k < res.length; k++) {
System.out.print(res[k]+" ");
}
System.out.println();
}
}, n, d);
}
for(int i = 0; i < t; ++i)
sols[i].getAnswer();
}
class Solver extends ASolver<Integer[]>{
int n;
int[] d;
@Override
public void solve(Object... data) {
super.solve(data);
n = (int)data[1];
d = (int[])data[2];
ans = new Integer[n];
ans[0] = d[0];
for (int i = 1; i < n; i++) {
int v1 = d[i] + ans[i - 1];
int v2 = (d[i] - ans[i - 1]) *-1;
int fv1 = v1 - ans[i - 1];
int fv2 = Math.abs(Math.abs(v2) - ans[i - 1]);
// System.out.println(v1+","+v2+"\t"+fv1+","+fv2);
ans[i] = fv1 == d[i] ? v1 : v2;
if(fv1 == fv2 && Math.abs(v2) == v1)
{
continue;
}
else
if(fv1 == fv2) {
ans = new Integer[] { -1 };
break;
}
}
//
}
}
}
| Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | a6a04ee4ff36f760b7797948764a9156 | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | import java.util.*;
public class codeforces_solution{
public static void main(String []args){
try (var 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();
}
// if(n==1)System.out.println(-1);
boolean check=false;
for (int i = 1; i < n; i++) {
if(arr[i]!=0 && arr[i]<=arr[i-1]){
check=true; break;
}else{
arr[i]+=arr[i-1];
}
}
if(check == false){
for (int i = 0; i < n; i++) {
System.out.print(arr[i]+" ");
}
System.out.println();
}else{
System.out.println(-1);
}
}
}
}
}
/*
System.out.print();
Collections.sort(stor, (r,l) -> s.charAt(l-1)-s.charAt(r-1));
// to sort numbers aphabetically
*/ | Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output | |
PASSED | b98a5f8588c24a1833b869115c3a9e8d | train_109.jsonl | 1664462100 | For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays. | 256 megabytes | import java.util.*;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(;t>0;t--) {
int n=sc.nextInt();
int[] a = new int[n];
for(int i=0;i<n;i++) a[i]=sc.nextInt();
boolean stop=false;
for(int i=1;i<n && !stop;i++) {
if(a[i]<=a[i-1] && a[i]!=0 ) stop=true;
else {
a[i] += a[i-1];
}
}
if(stop) System.out.println(-1);
else {
System.out.print(a[0]);
for(int i=1;i<n;i++) System.out.print(" "+a[i]);
System.out.println();
}
}
}
} | Java | ["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"] | 2 seconds | ["1 1 3 8\n-1\n0 0 0 0 0"] | NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$. | Java 11 | standard input | [
"constructive algorithms",
"greedy",
"math"
] | f4b790bef9a6cbcd5d1f9235bcff7c8f | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints. | 1,100 | For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.