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 | e33be4ab9c9e6609fd39ea912a62d68c | train_004.jsonl | 1419951600 | New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1βΓβn board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of nβ-β1 positive integers a1,βa2,β...,βanβ-β1. For every integer i where 1ββ€βiββ€βnβ-β1 the condition 1ββ€βaiββ€βnβ-βi holds. Next, he made nβ-β1 portals, numbered by integers from 1 to nβ-β1. The i-th (1ββ€βiββ€βnβ-β1) portal connects cell i and cell (iβ+βai), and one can travel from cell i to cell (iβ+βai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (iβ+βai) to cell i using the i-th portal. It is easy to see that because of condition 1ββ€βaiββ€βnβ-βi one can't leave the Line World using portals.Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system. | 256 megabytes | import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int t=in.nextInt();
int a[]=new int[n];
for(int i=0;i<n-1;i++) a[i]=in.nextInt();
int sum=0;
int i=1;
while(true)
{
//System.out.println(i);
if(i==t){System.out.println("YES"); return;}
if(i>t) {System.out.println("NO"); return;}
i+=a[i-1];
}
}
}
| Java | ["8 4\n1 2 1 2 1 2 1", "8 5\n1 2 1 2 1 1 1"] | 2 seconds | ["YES", "NO"] | NoteIn the first sample, the visited cells are: 1,β2,β4; so we can successfully visit the cell 4.In the second sample, the possible cells to visit are: 1,β2,β4,β6,β7,β8; so we can't visit the cell 5, which we want to visit. | Java 7 | standard input | [
"implementation",
"dfs and similar",
"graphs"
] | 9ee3d548f93390db0fc2f72500d9eeb0 | The first line contains two space-separated integers n (3ββ€βnββ€β3βΓβ104) and t (2ββ€βtββ€βn) β the number of cells, and the index of the cell which I want to go to. The second line contains nβ-β1 space-separated integers a1,βa2,β...,βanβ-β1 (1ββ€βaiββ€βnβ-βi). It is guaranteed, that using the given transportation system, one cannot leave the Line World. | 1,000 | If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO". | standard output | |
PASSED | 14b7233d6b3f1784b3cef040414aa9a0 | train_004.jsonl | 1419951600 | New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1βΓβn board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of nβ-β1 positive integers a1,βa2,β...,βanβ-β1. For every integer i where 1ββ€βiββ€βnβ-β1 the condition 1ββ€βaiββ€βnβ-βi holds. Next, he made nβ-β1 portals, numbered by integers from 1 to nβ-β1. The i-th (1ββ€βiββ€βnβ-β1) portal connects cell i and cell (iβ+βai), and one can travel from cell i to cell (iβ+βai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (iβ+βai) to cell i using the i-th portal. It is easy to see that because of condition 1ββ€βaiββ€βnβ-βi one can't leave the Line World using portals.Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system. | 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 Main
{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int t = Integer.parseInt(s[1]);
String s1 = br.readLine();
StringTokenizer st = new StringTokenizer(s1);
int[] arr = new int[n+1];
for(int i=1; i<n; i++)
{
arr[i] = Integer.parseInt(st.nextToken());
//System.out.println(arr[i]);
}
int x=1;
int flag=0;
while(x<=t && flag!=1)
{
x+=arr[x];
if(x==t)
{
flag=1;
}
else
flag=0;
}
if(flag==1)
System.out.println("YES");
else
System.out.println("NO");
}
} | Java | ["8 4\n1 2 1 2 1 2 1", "8 5\n1 2 1 2 1 1 1"] | 2 seconds | ["YES", "NO"] | NoteIn the first sample, the visited cells are: 1,β2,β4; so we can successfully visit the cell 4.In the second sample, the possible cells to visit are: 1,β2,β4,β6,β7,β8; so we can't visit the cell 5, which we want to visit. | Java 7 | standard input | [
"implementation",
"dfs and similar",
"graphs"
] | 9ee3d548f93390db0fc2f72500d9eeb0 | The first line contains two space-separated integers n (3ββ€βnββ€β3βΓβ104) and t (2ββ€βtββ€βn) β the number of cells, and the index of the cell which I want to go to. The second line contains nβ-β1 space-separated integers a1,βa2,β...,βanβ-β1 (1ββ€βaiββ€βnβ-βi). It is guaranteed, that using the given transportation system, one cannot leave the Line World. | 1,000 | If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO". | standard output | |
PASSED | 25269552d9c24b56a6b7172321029633 | train_004.jsonl | 1419951600 | New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1βΓβn board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of nβ-β1 positive integers a1,βa2,β...,βanβ-β1. For every integer i where 1ββ€βiββ€βnβ-β1 the condition 1ββ€βaiββ€βnβ-βi holds. Next, he made nβ-β1 portals, numbered by integers from 1 to nβ-β1. The i-th (1ββ€βiββ€βnβ-β1) portal connects cell i and cell (iβ+βai), and one can travel from cell i to cell (iβ+βai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (iβ+βai) to cell i using the i-th portal. It is easy to see that because of condition 1ββ€βaiββ€βnβ-βi one can't leave the Line World using portals.Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class NewYearTransportation {
public NewYearTransportation() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] split = br.readLine().split(" ");
int t = Integer.parseInt(split[1]);
split = br.readLine().split(" ");
br.close();
String canGo = "NO";
for (int i = 1; i <= t; i += Integer.parseInt(split[i - 1]))
if (i == t) {
canGo = "YES";
break;
}
System.out.println(canGo);
}
public static void main(String[] args) throws IOException {
new NewYearTransportation();
}
}
| Java | ["8 4\n1 2 1 2 1 2 1", "8 5\n1 2 1 2 1 1 1"] | 2 seconds | ["YES", "NO"] | NoteIn the first sample, the visited cells are: 1,β2,β4; so we can successfully visit the cell 4.In the second sample, the possible cells to visit are: 1,β2,β4,β6,β7,β8; so we can't visit the cell 5, which we want to visit. | Java 7 | standard input | [
"implementation",
"dfs and similar",
"graphs"
] | 9ee3d548f93390db0fc2f72500d9eeb0 | The first line contains two space-separated integers n (3ββ€βnββ€β3βΓβ104) and t (2ββ€βtββ€βn) β the number of cells, and the index of the cell which I want to go to. The second line contains nβ-β1 space-separated integers a1,βa2,β...,βanβ-β1 (1ββ€βaiββ€βnβ-βi). It is guaranteed, that using the given transportation system, one cannot leave the Line World. | 1,000 | If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO". | standard output | |
PASSED | a244b3d4302bcf9de88d9bfd448b4caa | train_004.jsonl | 1419951600 | New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1βΓβn board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of nβ-β1 positive integers a1,βa2,β...,βanβ-β1. For every integer i where 1ββ€βiββ€βnβ-β1 the condition 1ββ€βaiββ€βnβ-βi holds. Next, he made nβ-β1 portals, numbered by integers from 1 to nβ-β1. The i-th (1ββ€βiββ€βnβ-β1) portal connects cell i and cell (iβ+βai), and one can travel from cell i to cell (iβ+βai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (iβ+βai) to cell i using the i-th portal. It is easy to see that because of condition 1ββ€βaiββ€βnβ-βi one can't leave the Line World using portals.Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system. | 256 megabytes | import java.util.*;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int t=sc.nextInt();
int array[]=new int[n];
int i;
for(i=0;i<n-1;i++){
array[i]=sc.nextInt();
}
int m,flag=0;
i=1;
while(i<t){
i=i+array[i-1];
}
if(i==t){
System.out.print("YES");
}
else{
System.out.print("NO");
}
}
}
| Java | ["8 4\n1 2 1 2 1 2 1", "8 5\n1 2 1 2 1 1 1"] | 2 seconds | ["YES", "NO"] | NoteIn the first sample, the visited cells are: 1,β2,β4; so we can successfully visit the cell 4.In the second sample, the possible cells to visit are: 1,β2,β4,β6,β7,β8; so we can't visit the cell 5, which we want to visit. | Java 7 | standard input | [
"implementation",
"dfs and similar",
"graphs"
] | 9ee3d548f93390db0fc2f72500d9eeb0 | The first line contains two space-separated integers n (3ββ€βnββ€β3βΓβ104) and t (2ββ€βtββ€βn) β the number of cells, and the index of the cell which I want to go to. The second line contains nβ-β1 space-separated integers a1,βa2,β...,βanβ-β1 (1ββ€βaiββ€βnβ-βi). It is guaranteed, that using the given transportation system, one cannot leave the Line World. | 1,000 | If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO". | standard output | |
PASSED | c3a7f5e1f8058a6addcc9340a5d00533 | train_004.jsonl | 1419951600 | New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1βΓβn board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of nβ-β1 positive integers a1,βa2,β...,βanβ-β1. For every integer i where 1ββ€βiββ€βnβ-β1 the condition 1ββ€βaiββ€βnβ-βi holds. Next, he made nβ-β1 portals, numbered by integers from 1 to nβ-β1. The i-th (1ββ€βiββ€βnβ-β1) portal connects cell i and cell (iβ+βai), and one can travel from cell i to cell (iβ+βai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (iβ+βai) to cell i using the i-th portal. It is easy to see that because of condition 1ββ€βaiββ€βnβ-βi one can't leave the Line World using portals.Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system. | 256 megabytes | import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class BFSTest {
static boolean visited[][]=null;
public static void BFS(int [] arr,int target)
{
Queue<Integer> s=new LinkedList<>();
s.add(0);
boolean f=false;
while(s.peek()!=null){
int next= s.peek();
s.poll();
//System.out.println( next.i+","+next.j);
if(next+1==target){
f=true;
break;
}
else
if(next<arr.length)
s.add(next+arr[next]);
}
System.out.println((f)?"YES":"NO");
}
public static void main(String[] args) {
Scanner scan =new Scanner(System.in);
int m=scan.nextInt();
int t=scan.nextInt();
int arr[]=new int[m-1];
for(int i=0;i<m-1;i++)
arr[i]=scan.nextInt();
BFS(arr, t);
//System.out.println(visited[1]);
}
}
class Nodee{
int i,j;
public Nodee(int a,int b) {
i=a;
j=b;
}
}
| Java | ["8 4\n1 2 1 2 1 2 1", "8 5\n1 2 1 2 1 1 1"] | 2 seconds | ["YES", "NO"] | NoteIn the first sample, the visited cells are: 1,β2,β4; so we can successfully visit the cell 4.In the second sample, the possible cells to visit are: 1,β2,β4,β6,β7,β8; so we can't visit the cell 5, which we want to visit. | Java 7 | standard input | [
"implementation",
"dfs and similar",
"graphs"
] | 9ee3d548f93390db0fc2f72500d9eeb0 | The first line contains two space-separated integers n (3ββ€βnββ€β3βΓβ104) and t (2ββ€βtββ€βn) β the number of cells, and the index of the cell which I want to go to. The second line contains nβ-β1 space-separated integers a1,βa2,β...,βanβ-β1 (1ββ€βaiββ€βnβ-βi). It is guaranteed, that using the given transportation system, one cannot leave the Line World. | 1,000 | If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO". | standard output | |
PASSED | 7e41e2313627c7be7d814a68a0dd9eb0 | train_004.jsonl | 1419951600 | New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1βΓβn board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of nβ-β1 positive integers a1,βa2,β...,βanβ-β1. For every integer i where 1ββ€βiββ€βnβ-β1 the condition 1ββ€βaiββ€βnβ-βi holds. Next, he made nβ-β1 portals, numbered by integers from 1 to nβ-β1. The i-th (1ββ€βiββ€βnβ-β1) portal connects cell i and cell (iβ+βai), and one can travel from cell i to cell (iβ+βai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (iβ+βai) to cell i using the i-th portal. It is easy to see that because of condition 1ββ€βaiββ€βnβ-βi one can't leave the Line World using portals.Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution1 {
public void solve() throws IOException {
int n = in.nextInt();
int t = in.nextInt();
int i = 1;
while (i < t) {
int a = in.nextInt();
i += a;
for (int j = 1; j < a; j++) {
int z = in.nextInt();
}
}
System.out.println((i == t) ? "YES" : "NO");
}
public static String fileName = "";
public PrintWriter out;
MyScanner in;
public void run() throws IOException {
in = new MyScanner();
out = new PrintWriter(System.out);
solve();
in.close();
out.close();
}
public class MyScanner {
private BufferedReader br;
private StringTokenizer st;
public MyScanner() throws IOException {
this.br = new BufferedReader(new InputStreamReader(System.in));
}
public MyScanner(String fileTitle) throws IOException {
this.br = new BufferedReader(new FileReader(fileTitle));
}
public String nextLine() throws IOException {
String s = br.readLine();
return s == null ? "-1" : s;
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String s = br.readLine();
if (s == null) {
return "-1";
}
st = new StringTokenizer(s);
}
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(this.next());
}
public long nextLong() throws IOException {
return Long.parseLong(this.next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public void close() throws IOException {
this.br.close();
}
}
public static void main(String[] args) throws IOException {
Locale.setDefault(Locale.US);
new Solution1().run();
}
} | Java | ["8 4\n1 2 1 2 1 2 1", "8 5\n1 2 1 2 1 1 1"] | 2 seconds | ["YES", "NO"] | NoteIn the first sample, the visited cells are: 1,β2,β4; so we can successfully visit the cell 4.In the second sample, the possible cells to visit are: 1,β2,β4,β6,β7,β8; so we can't visit the cell 5, which we want to visit. | Java 7 | standard input | [
"implementation",
"dfs and similar",
"graphs"
] | 9ee3d548f93390db0fc2f72500d9eeb0 | The first line contains two space-separated integers n (3ββ€βnββ€β3βΓβ104) and t (2ββ€βtββ€βn) β the number of cells, and the index of the cell which I want to go to. The second line contains nβ-β1 space-separated integers a1,βa2,β...,βanβ-β1 (1ββ€βaiββ€βnβ-βi). It is guaranteed, that using the given transportation system, one cannot leave the Line World. | 1,000 | If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO". | standard output | |
PASSED | 052db674e2154d4df3f3249cc743d178 | train_004.jsonl | 1419951600 | New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1βΓβn board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of nβ-β1 positive integers a1,βa2,β...,βanβ-β1. For every integer i where 1ββ€βiββ€βnβ-β1 the condition 1ββ€βaiββ€βnβ-βi holds. Next, he made nβ-β1 portals, numbered by integers from 1 to nβ-β1. The i-th (1ββ€βiββ€βnβ-β1) portal connects cell i and cell (iβ+βai), and one can travel from cell i to cell (iβ+βai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (iβ+βai) to cell i using the i-th portal. It is easy to see that because of condition 1ββ€βaiββ€βnβ-βi one can't leave the Line World using portals.Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system. | 256 megabytes | import java.util.Scanner;
public class NewYearTransportation {
static Scanner in = new Scanner(System.in);
static int n = in.nextInt();
static int t = in.nextInt();
static int[] arr = new int[n + 1];
public static void main(String[] args) {
// TODO Auto-generated method stub
for(int i = 1; i < n; i++)
{
arr[i] = i + in.nextInt();
}
System.out.println(dfs(1));
}
static String dfs(int i)
{
if(i == n && arr[i] != t)
{
return "NO";
}
else if(arr[i] == t)
{
return "YES";
}
return dfs(arr[i]);
}
}
| Java | ["8 4\n1 2 1 2 1 2 1", "8 5\n1 2 1 2 1 1 1"] | 2 seconds | ["YES", "NO"] | NoteIn the first sample, the visited cells are: 1,β2,β4; so we can successfully visit the cell 4.In the second sample, the possible cells to visit are: 1,β2,β4,β6,β7,β8; so we can't visit the cell 5, which we want to visit. | Java 7 | standard input | [
"implementation",
"dfs and similar",
"graphs"
] | 9ee3d548f93390db0fc2f72500d9eeb0 | The first line contains two space-separated integers n (3ββ€βnββ€β3βΓβ104) and t (2ββ€βtββ€βn) β the number of cells, and the index of the cell which I want to go to. The second line contains nβ-β1 space-separated integers a1,βa2,β...,βanβ-β1 (1ββ€βaiββ€βnβ-βi). It is guaranteed, that using the given transportation system, one cannot leave the Line World. | 1,000 | If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO". | standard output | |
PASSED | dcf8279bf0a1d00c56cf2d032e5510ce | train_004.jsonl | 1419951600 | New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1βΓβn board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of nβ-β1 positive integers a1,βa2,β...,βanβ-β1. For every integer i where 1ββ€βiββ€βnβ-β1 the condition 1ββ€βaiββ€βnβ-βi holds. Next, he made nβ-β1 portals, numbered by integers from 1 to nβ-β1. The i-th (1ββ€βiββ€βnβ-β1) portal connects cell i and cell (iβ+βai), and one can travel from cell i to cell (iβ+βai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (iβ+βai) to cell i using the i-th portal. It is easy to see that because of condition 1ββ€βaiββ€βnβ-βi one can't leave the Line World using portals.Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Reza
*/
public class A {
static int pset[];
static int size[];
static int setsNum;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer strt = new StringTokenizer(br.readLine());
int n = Integer.parseInt(strt.nextToken());
int t = Integer.parseInt(strt.nextToken()) - 1;
StringTokenizer stt = new StringTokenizer(br.readLine());
pset = new int[n];
size = new int[n];
initSet();
for (int i = 0; i < n - 1; i++) {
int y = i + Integer.parseInt(stt.nextToken());
if (y <= t) {
unionSet(i, y);
}
}
if (isSame(0, t)) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
public static void initSet() {
setsNum = pset.length;
for (int i = 0; i < pset.length; i++) {
pset[i] = i;
}
Arrays.fill(size, 1);
}
public static int findSet(int i) {
return (pset[i] == i) ? i : (pset[i] = findSet(pset[i]));
}
public static void unionSet(int i, int j) {
if (findSet(i) != findSet(j)) {
pset[findSet(i)] = findSet(j);
setsNum--;
}
}
public static boolean isSame(int i, int j) {
if (findSet(i) == findSet(j)) {
return true;
}
return false;
}
}
| Java | ["8 4\n1 2 1 2 1 2 1", "8 5\n1 2 1 2 1 1 1"] | 2 seconds | ["YES", "NO"] | NoteIn the first sample, the visited cells are: 1,β2,β4; so we can successfully visit the cell 4.In the second sample, the possible cells to visit are: 1,β2,β4,β6,β7,β8; so we can't visit the cell 5, which we want to visit. | Java 7 | standard input | [
"implementation",
"dfs and similar",
"graphs"
] | 9ee3d548f93390db0fc2f72500d9eeb0 | The first line contains two space-separated integers n (3ββ€βnββ€β3βΓβ104) and t (2ββ€βtββ€βn) β the number of cells, and the index of the cell which I want to go to. The second line contains nβ-β1 space-separated integers a1,βa2,β...,βanβ-β1 (1ββ€βaiββ€βnβ-βi). It is guaranteed, that using the given transportation system, one cannot leave the Line World. | 1,000 | If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO". | standard output | |
PASSED | cb82d95231d21f08312b79a4585a4ab1 | train_004.jsonl | 1419951600 | New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1βΓβn board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of nβ-β1 positive integers a1,βa2,β...,βanβ-β1. For every integer i where 1ββ€βiββ€βnβ-β1 the condition 1ββ€βaiββ€βnβ-βi holds. Next, he made nβ-β1 portals, numbered by integers from 1 to nβ-β1. The i-th (1ββ€βiββ€βnβ-β1) portal connects cell i and cell (iβ+βai), and one can travel from cell i to cell (iβ+βai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (iβ+βai) to cell i using the i-th portal. It is easy to see that because of condition 1ββ€βaiββ€βnβ-βi one can't leave the Line World using portals.Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Reza
*/
public class A2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer strt = new StringTokenizer(br.readLine());
int n = Integer.parseInt(strt.nextToken());
int t = Integer.parseInt(strt.nextToken());
StringTokenizer stt = new StringTokenizer(br.readLine());
int ary[] = new int[n - 1];
for (int i = 0; i < n - 1; i++) {
ary[i] = Integer.parseInt(stt.nextToken());
}
int index = 1;
boolean b = true;
while (index <= t && b) {
if (index == t) {
System.out.println("YES");
b = false;
} else {
index += ary[index - 1];
}
}
if (b) {
System.out.println("NO");
}
}
}
| Java | ["8 4\n1 2 1 2 1 2 1", "8 5\n1 2 1 2 1 1 1"] | 2 seconds | ["YES", "NO"] | NoteIn the first sample, the visited cells are: 1,β2,β4; so we can successfully visit the cell 4.In the second sample, the possible cells to visit are: 1,β2,β4,β6,β7,β8; so we can't visit the cell 5, which we want to visit. | Java 7 | standard input | [
"implementation",
"dfs and similar",
"graphs"
] | 9ee3d548f93390db0fc2f72500d9eeb0 | The first line contains two space-separated integers n (3ββ€βnββ€β3βΓβ104) and t (2ββ€βtββ€βn) β the number of cells, and the index of the cell which I want to go to. The second line contains nβ-β1 space-separated integers a1,βa2,β...,βanβ-β1 (1ββ€βaiββ€βnβ-βi). It is guaranteed, that using the given transportation system, one cannot leave the Line World. | 1,000 | If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO". | standard output | |
PASSED | 0e1aaf37c3c0b9da06bea136bf1d01db | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
static class FastScanner {
BufferedReader s;
StringTokenizer st;
public FastScanner(InputStream InputStream) {
st = new StringTokenizer("");
s = new BufferedReader(new InputStreamReader(InputStream));
}
public FastScanner(File f) throws FileNotFoundException {
st = new StringTokenizer("");
s = new BufferedReader(new FileReader(f));
}
public int nextInt() throws IOException {
if (st.hasMoreTokens())
return Integer.parseInt(st.nextToken());
else {
st = new StringTokenizer(s.readLine());
return nextInt();
}
}
public BigInteger big() throws IOException {
if (st.hasMoreTokens())
return new BigInteger(st.nextToken());
else {
st = new StringTokenizer(s.readLine());
return big();
}
}
public double nextDouble() throws IOException {
if (st.hasMoreTokens())
return Double.parseDouble(st.nextToken());
else {
st = new StringTokenizer(s.readLine());
return nextDouble();
}
}
public long nextLong() throws IOException {
if (st.hasMoreTokens())
return Long.parseLong(st.nextToken());
else {
st = new StringTokenizer(s.readLine());
return nextLong();
}
}
public String next() throws IOException {
if (st.hasMoreTokens())
return st.nextToken();
else {
st = new StringTokenizer(s.readLine());
return next();
}
}
public String nextLine() throws IOException {
return s.readLine();
}
public void close() throws IOException {
s.close();
}
}
public static void main(String[] args) throws java.lang.Exception {
FastScanner in = new FastScanner(System.in);
int test = in.nextInt();
StringBuilder sb = new StringBuilder("");
while(test-- > 0) {
int n = in.nextInt();
int[] arr = new int[n];
int xor = 0;
int[] dp = new int[32];
for(int x = 0; x < n; x++) {
arr[x] = in.nextInt();
xor ^= arr[x];
for(int i = 0; i < 32; i++) {
if((arr[x] & (1 << i)) != 0)
dp[i]++;
}
}
if(xor == 0) {
sb.append("DRAW\n");
continue;
}
for(int x = 31; x >= 0; x--) {
if((dp[x] & 1) == 1) {
if(((dp[x]/2 + 1) & 1) == 1) {
sb.append("WIN\n");
} else {
int zero = n - dp[x];
if((zero & 1) == 1) {
sb.append("WIN\n");
} else
sb.append("LOSE\n");
}
break;
}
}
}
System.out.print(sb);
}
} | Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | fcd86029c1066c8b6ff0892f399fb0dc | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.lang.*;
import java.util.*;
import java.io.*;
public class Main {
static class Elem {
int val, bit = 0;
Elem(int val, int bit) {
this.val = val;
this.bit = bit;
}
}
public static int high(int a) {
int p = 0;
while (a > 0) {
++p;
a >>= 1;
}
return p;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
int[] a = new int[n];
int x = 0;
for (int i = 0; i < n; ++i) {
a[i] = in.nextInt();
x ^= a[i];
}
if (x == 0) {
System.out.println("DRAW");
continue;
}
for (int k = 30; k >= 0; --k) {
if (((x >> k) & 1) != 0) {
int nr0 = 0, nr1 = 0;
for (int it : a) {
if (((it >> k) & 1) != 0)
++nr1;
else
++nr0;
}
if (nr1 % 4 == 3 && nr0 % 2 == 0)
System.out.println("LOSE");
else
System.out.println("WIN");
break;
}
}
}
}
}
| Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | fa858e5b834ce7caac9187f26a27bd00 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.util.*;
import java.io.*;
public class a{
public static void main( String [] args) throws IOException{
BufferInput sc=new BufferInput();
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int [] a=sc.nextIntArray(n);
int xor=a[0];
for(int i=1;i<n;i++)xor=xor^a[i];
if(xor==0){
System.out.println("DRAW");
continue;
}
for(int i=31;i>=0;i--){
int zero=0,one=0;
for(int x : a){
if(((x>>i)&1)==1)one++;
else zero++;
}
if(one%2!=0){
if(one%4==3 && zero%2==0){
System.out.println("LOSE");
}
else{
System.out.println("WIN");
}
break;
}
}
}
}
}
class BufferInput{
private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public BufferInput() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public BufferInput( 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];
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public String next() throws IOException{
byte c = read();
while(Character.isWhitespace(c)){
c = read();
}
StringBuilder builder = new StringBuilder();
builder.append((char)c);
c = read();
while(!Character.isWhitespace(c)){
builder.append((char)c);
c = read();
}
return builder.toString();
}
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 int[] nextIntArray( int n) throws IOException {
int arr[] = new int[n];
for(int i = 0; i < n; i++){
arr[i] = nextInt();
}
return arr;
}
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 long[] nextLongArray( int n) throws IOException {
long arr[] = new long[n];
for(int i = 0; i < n; i++){
arr[i] = nextLong();
}
return arr;
}
public char nextChar() throws IOException{
byte c = read();
while(Character.isWhitespace(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;
}
public double[] nextDoubleArray( int n) throws IOException {
double arr[] = new double[n];
for(int i = 0; i < n; i++){
arr[i] = nextDouble();
}
return arr;
}
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\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | ea8dd5acc4626d8a854c128d276d3288 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes |
import java.io.*;
import java.util.*;
public class Main {
static BufferedReader br;
static int in() throws Exception
{
return Integer.valueOf(br.readLine());
}
static int[] split() throws Exception
{
String[] cmd=br.readLine().split(" ");
int[] ans=new int[cmd.length];
for(int i=0;i<cmd.length;i++)
{
ans[i]=Integer.valueOf(cmd[i]);
}
return ans;
}
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
br=new BufferedReader(new InputStreamReader(System.in));
String[] cmd=br.readLine().split(" ");
int cases=Integer.valueOf(cmd[0]);
while(cases!=0)
{
cases--;
int n=in();
int[] d=split();
boolean b=true;
for(int i=30;i>=0;i--)
{
int ones=0;
int zeros=0;
for(int j=0;j<n;j++)
{
if((d[j]&(1<<i))!=0)
ones++;
else
zeros++;
}
if(ones%2==0)
continue;
b=false;
int rem=ones%4;
if(rem==1)
System.out.println("WIN");
else
{
if(zeros%2==0)
System.out.println("LOSE");
else
System.out.println("WIN");
}
break;
}
if(b)
System.out.println("DRAW");
}
}
}
| Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | 469d1602a924827c3287a16f3c668f42 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main implements Runnable{
FastScanner sc;
PrintWriter pw;
final class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
e.printStackTrace();
}
}
public long nlo() {
return Long.parseLong(next());
}
public String next() {
if (st.hasMoreTokens()) return st.nextToken();
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
e.printStackTrace();
}
return st.nextToken();
}
public int ni() {
return Integer.parseInt(next());
}
public String nli() {
String line = "";
if (st.hasMoreTokens()) line = st.nextToken();
else try {
return br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
while (st.hasMoreTokens()) line += " " + st.nextToken();
return line;
}
public double nd() {
return Double.parseDouble(next());
}
}
public static void main(String[] args) throws Exception
{
new Thread(null,new Main(),"codeforces",1<<28).start();
}
public void run()
{
sc=new FastScanner();
pw=new PrintWriter(System.out);
solve();
pw.flush();
pw.close();
}
public long gcd(long a,long b)
{
return b==0L?a:gcd(b,a%b);
}
public long ppow(long a,long b,long mod)
{
if(b==0L)
return 1L;
long tmp=1;
while(b>1L)
{
if((b&1L)==1)
tmp*=a;
a*=a;
a%=mod;
tmp%=mod;
b>>=1;
}
return (tmp*a)%mod;
}
public int gcd(int x,int y)
{
return y==0?x:gcd(y,x%y);
}
public class Pair implements Comparable<Pair>{
int x;
int val;
Pair(int a,int b)
{
x=a;
val=b;
}
public int compareTo(Pair b)
{
return this.val-b.val;
}
public Pair clone(Pair b)
{
return new Pair(b.x,b.val);
}
}
//////////////////////////////////
///////////// LOGIC ///////////
////////////////////////////////
public void solve() {
int t=sc.ni();
while(t-->0)
{
int n=sc.ni();
int[] arr=new int[n];
for(int i=0;i<n;i++)
arr[i]=sc.ni();
boolean res=false;
for(int i=30;i>=0;i--)
{
int tmp=0;
for(int j=0;j<n;j++)
if((arr[j]&(1<<i))!=0)
tmp++;
if(tmp%2==1)
{
res=true;
if(tmp==1||tmp%4==1)
pw.println("WIN");
else if((n-tmp)%2==0)
pw.println("LOSE");
else
pw.println("WIN");
break;
}
}
if(!res)
pw.println("DRAW");
}
}
} | Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | c1f46055f7221587a3d60c224d508117 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | // package Div2_659;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class ProblemD {
public static void main(String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringBuilder print=new StringBuilder();
StringTokenizer st;
int test=Integer.parseInt(br.readLine());
while(test--!=0){
int n=Integer.parseInt(br.readLine());
int bit[]=new int[32];
int a[]=new int[n+1];
st=new StringTokenizer(br.readLine());
for(int i=1;i<=n;i++){
a[i]=Integer.parseInt(st.nextToken());
for(int j=0;j<32;j++){
int t=1<<j;
if((t&a[i])!=0){
bit[j]++;
}
}
}
int flag=0;
for(int i=31;i>=0;i--){
int set=bit[i];
int unset=n-set;
if(set%2==0)
continue;
if(set%4==3&&unset%2==0){
flag=2;
}
else{
flag=1;
}
break;
}
if(flag==0){
print.append("DRAW\n");
}
else if(flag==1){
print.append("WIN\n");
}
else{
print.append("LOSE\n");
}
}
System.out.print(print.toString());
}
}
| Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | 1b06ca603cba89ae84ca2996a0caa432 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Solution {
static final FS sc = new FS();
static final PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args) {
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int[] a = new int[n];
int x = 0;
for (int i = 0;i < n;i++) {
a[i] = sc.nextInt();
x ^= a[i];
}
if (x == 0) {
pw.println("DRAW");
continue;
}
for (int k = 30;k >= 0;k--) {
if (((x >> k) & 1) == 1) {
int[] count = new int[2];
for (int num : a) {
count[num >> k & 1]++;
}
if (count[1] % 4 == 3 && count[0] % 2 == 0) {
pw.println("LOSE");
} else {
pw.println("WIN");
}
break;
}
}
}
pw.flush();
}
static class FS {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while(!st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch(Exception ignored) {}
}
return st.nextToken();
}
int[] nextArray(int n) {
int[] a = new int[n];
for(int i = 0;i < n;i++) {
a[i] = nextInt();
}
return a;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | e70618e07bbeb859c14680bf2d956e7f | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
public class Main {
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
public static Reader sc = new Reader();
public static List<Integer>[] edges;
public static int[][][] bit;
public static int[][] parent;
public static int col = 20;
public static int[] a;
public static void main(String[] args) throws IOException {
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
int[] ones = new int[32];
for(int i=0;i<n;++i) {
int x = sc.nextInt();
int[] bit = convert(Integer.toBinaryString(x));
for(int j=0;j<32;++j) {
ones[j]+=bit[j];
}
}
// for(int i=0;i<ones.length;++i) out.print(ones[i]+" ");
int state = 0;
for(int i=0;i<32;++i) {
int o = ones[i];
int z = n-o;
if(o%2 == 0) continue;
//out.println("z : "+z+" "+i);
if((o-1)%4 == 0) {
state = 1;
break;
}else {
if(z%2 != 0) {
state = 1;
}else state = -1;
break;
}
}
//out.println("s : "+state);
if(state == 0) out.println("DRAW");
else if(state == 1) out.println("WIN");
else out.println("LOSE");
}
out.close();
}
private static int[] convert(String s) {
// convert to 32 bit then insert it
int[] bits = new int[32];
int j = s.length()-1;
for(int i=31;i>=0 && j>=0;--i,--j) {
bits[i] = s.charAt(j)-'0';
}
return bits;
}
} | Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | 6d4a3b2367f0b1bbef6f4415ef66767f | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.util.*;
public class D_659{
public static void main(String[] args)
{
Scanner omkar = new Scanner(System.in);
int cases = omkar.nextInt();
int[] arr;
long sum;
long temp;
int ones;
int zeros;
for(int i = 0; i < cases; i++)
{
arr = new int[omkar.nextInt()];
for(int j = 0; j < arr.length; j++)
{
arr[j] = omkar.nextInt();
}
sum = 0;
for(int j = 0; j < arr.length; j++)
{
sum = sum ^ arr[j];
}
if(sum == 0)
{
System.out.println("DRAW");
}
else
{
temp = 1<<((int)(Math.log(sum)/Math.log(2)));
ones = 0;
zeros = 0;
for(int j = 0; j < arr.length; j++)
{
if(arr[j]/temp % 2 == 1)
{
ones++;
}
else
{
zeros++;
}
}
if(ones % 4 == 1)
{
System.out.println("WIN");
}
else if(zeros % 2 == 1)
{
System.out.println("WIN");
}
else
{
System.out.println("LOSE");
}
}
}
}
}
| Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | 37e3c9589845d5352e2525eb23d788e1 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | //package codeforces.round.n659;
import java.util.Scanner;
/**
* @author nayix
* @date 2020/7/25 0:25
*/
public class GameGame {
private static final String DRAW = "DRAW";
private static final String WIN = "WIN";
private static final String LOSE = "LOSE";
private int n;
private int[] times;
public GameGame(Scanner in) {
n = in.nextInt();
times = new int[55];
for (int i = 0; i < n; i++) {
long x = in.nextLong();
for (int j = 0; x > 0; j++) {
if ((x & 1) == 1) {
times[j]++;
}
x >>= 1;
}
}
}
public String solve() {
n &= 1;
for (int i = 40; i >= 0; i--) {
if (times[i] % 2 != 0) {
if (n == 1) {
return (times[i] >> 1) % 2 == 1? LOSE: WIN;
} else {
return WIN;
}
}
}
return DRAW;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
for (int t = in.nextInt(); t > 0; t--) {
GameGame gameGame = new GameGame(in);
System.out.println(gameGame.solve());
}
in.close();
}
}
| Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | dd07ef7e2b949436e2f9b4925949b3a4 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.util.*;
import java.io.*;
public class d {
public static void main(String[] args) throws IOException {
FastScanner sc = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int T = sc.nextInt();
tests: while(T-- > 0) {
int n = sc.nextInt();
int[] bits = new int[36];
for(int i = 0 ; i < n ; i++) {
int curr = sc.nextInt();
String str = Integer.toBinaryString(curr);
int ctr = 0;
for(int j = str.length()-1;j>=0 ;j--) {
if (str.charAt(j) == '1') {
bits[ctr]++;
}
ctr++;
}
}
for (int i = bits.length-1 ; i>=0 ; i--) {
if(bits[i]%2 == 0) {
continue;
}
if(bits[i]%4==1) {
out.println("WIN");
continue tests;
}
if(bits[i]%4 == 3) {
if(n%2 == 0) {
out.println("WIN");
} else {
out.println("LOSE");
}
continue tests;
}
}
out.println("DRAW");
}
out.close();
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream i) {
br = new BufferedReader(new InputStreamReader(i));
st = new StringTokenizer("");
}
public String next() throws IOException {
if(st.hasMoreTokens())
return st.nextToken();
else
st = new StringTokenizer(br.readLine());
return next();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
}
| Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | c955bb72e82acc8bce9a30c6ffd28f37 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main{
public static void main(String args[])throws IOException{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
StringBuffer ans=new StringBuffer();
int t=Integer.parseInt(br.readLine().trim());
outer:while(t-->0){
int n=Integer.parseInt(br.readLine().trim());
String inp[]=br.readLine().trim().split(" ");
int arr[]=new int[n];
for(int i =0;i<n;i++)
arr[i]=Integer.parseInt(inp[i]);
int x,y;
for(int i=31;i>=0;i--){
int mask = 1<<i;
x=y=0;
for(int num:arr){
if((mask&num) == 0)
y++;
else
x++;
}
if(x%2 == 0)
continue;
if(x%4 == 3 && y%2 ==0){
ans.append("LOSE\n");
continue outer;
}
else
ans.append("WIN\n");
continue outer;
}
ans.append("DRAW\n");
}
System.out.print(ans);
}
} | Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | 0f91e18da1135af2dc61914acabc3eec | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.util.*;
import java.io.*;
public class EdC {
public static void main(String[] args) throws Exception{
int num = 998244353;
// TODO Auto-generated method stub
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int t = Integer.parseInt(bf.readLine());
for(int i = 0;i<t;i++){
int n = Integer.parseInt(bf.readLine());
StringTokenizer st = new StringTokenizer(bf.readLine());
String[] array = new String[n];
int maxlength = 0;
for(int j=0;j<n;j++){
array[j] = Integer.toBinaryString(Integer.parseInt(st.nextToken()));
maxlength = Math.max(maxlength, array[j].length());
}
int onecount = 0;
int zerocount = 0;
for(int j = maxlength;j>=0;j--){
for(int k = 0;k<n;k++){
int checkindex = array[k].length()-1-j;
if (checkindex >=0 && array[k].charAt(checkindex) == '1')
onecount++;
else
zerocount++;
}
if (onecount%2 == 1)
break;
onecount = 0;
zerocount = 0;
}
if (onecount%2 == 0)
out.println("DRAW");
else if (onecount%4 == 1)
out.println("WIN");
else if (onecount%4 == 3){
if (zerocount%2 == 0)
out.println("LOSE");
else
out.println("WIN");
}
}
out.println();
out.close();
}
}
//StringJoiner sj = new StringJoiner(" ");
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is
| Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | be57501e979865c864bc002c2066e2c6 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class TaskA {
int t, n;
int[] as = new int[100005];
FastIO io = new FastIO("in.txt");
String solve(){
int x = 0;
for(int i=0; i<n; i++){
x = as[i] ^ x;
}
if(x == 0) return "DRAW";
int bn = 0;
while(x > 0){
bn++;
x = x >> 1;
}
bn--;
int n1 = 0, n0 =0;
for(int i=0; i<n; i++){
if((as[i] & (1<<bn)) == 0){
n0++;
}else{
n1++;
}
}
int s0 = n0 % 2, s1 = ((n1-1)/2)%2;
if(s1 == 0 || (s1 == 1 && s0 == 1)) return "WIN";
return "LOSE";
}
public void main() throws Exception {
t = io.nextInt();
while(t-- > 0){
n = io.nextInt();
for(int i=0; i<n; i++){
as[i] = io.nextInt();
}
io.out(solve() + "\n");
}
}
public static void main(String[] args) throws Exception {
TaskA sol = new TaskA();
sol.main();
}
}
class FastIO {
BufferedReader br;
StringTokenizer sk;
public FastIO(String fname){
try{
File f = new File(fname);
if(f.exists()) {
System.setIn(new FileInputStream(fname));
}
}catch (Exception e){
throw new IllegalArgumentException(e);
}
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastIO(){
br = new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(sk==null || !sk.hasMoreElements()){
try {
sk = new StringTokenizer(br.readLine());
}catch (Exception e){
throw new IllegalArgumentException(e);
}
}
return sk.nextToken();
}
public int nextInt(){
return Integer.parseInt(next());
}
public long nextLong(){
return Long.parseLong(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
public String nextLine(){
String str = "";
try {
str = br.readLine();
}catch (Exception e){
e.printStackTrace();
}
return str;
}
public void out(String v){
System.out.print(v);
}
public void out(int v) {
System.out.print(v);
}
public void out(long v){
System.out.print(v);
}
public void out(double v) {
System.out.print(v);
}
}
| Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | f52059495694eeea04074c8c65a1edd9 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
FastScanner sc = new FastScanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int tt = sc.nextInt();
StringBuilder sb = new StringBuilder();
for(int t = 0; t < tt; t++){
int n = sc.nextInt();
long[] a = sc.nextLongArray(n);
int[] bitCount = new int[40];
for(long v : a){
int j = 0;
while(v > 0){
bitCount[j] += v%2;
v >>= 1;
j++;
}
}
if(n % 2 != 0){
boolean isEnd = false;
for(int i = 39; i >= 0; i--){
if(bitCount[i] % 2 != 0){
if((bitCount[i]/2) % 2 == 0){
pw.println("WIN");
}else{
pw.println("LOSE");
}
isEnd = true;
break;
}
}
if(!isEnd){
pw.println("DRAW");
}
}else{
boolean isEnd = false;
for(int i = 39; i >= 0; i--){
if(bitCount[i] % 2 != 0){
if((n-bitCount[i]) % 2 == 1){
pw.println("WIN");
}else{
pw.println("LOSE");
}
isEnd = true;
break;
}
}
if(!isEnd){
pw.println("DRAW");
}
}
}
pw.flush();
}
}
class FastScanner {
private BufferedReader reader = null;
private StringTokenizer tokenizer = null;
public FastScanner(InputStream in) {
reader = new BufferedReader(new InputStreamReader(in));
tokenizer = null;
}
public String next() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public String nextLine() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken("\n");
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
}
| Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | d2d42430f406686065728b8e1e7687f0 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | // Main Code at the Bottom
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
public class Main{
//Fast IO class
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
boolean env=System.getProperty("ONLINE_JUDGE") != null;
if(!env) {
try {
br=new BufferedReader(new FileReader("src\\input.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
else br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static long MOD=1000000000+7;
//debug
static void debug(Object... o) {
System.out.println(Arrays.deepToString(o));
}
// Pair
static class pair{
long x,y;
pair(long a,long b){
this.x=a;
this.y=b;
}
public boolean equals(Object obj) {
if(obj == null || obj.getClass()!= this.getClass()) return false;
pair p = (pair) obj;
return (this.x==p.x && this.y==p.y);
}
public int hashCode() {
return Objects.hash(x,y);
}
}
static FastReader sc=new FastReader();
static PrintWriter out=new PrintWriter(System.out);
//Global variables and functions
//Main function(The main code starts from here)
public static void main (String[] args) throws java.lang.Exception {
int test=1;
test=sc.nextInt();
while(test-->0){
int n=sc.nextInt(),map[]=new int[31];
for(int i=0;i<n;i++) {
int a=sc.nextInt();
for(int bit=0;bit<31;bit++) {
map[bit]+=((a>>bit)&1);
}
}
String ans="DRAW";
for(int i=30;i>=0;i--) {
if(map[i]%2==0) continue;
int ones=map[i],zeroes=n-ones;
if(((ones+1)/2)%2==1 || zeroes%2==1) ans="WIN";
else ans="LOSE";
break;
}
out.println(ans);
}
out.flush();
out.close();
}
} | Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | c2f86944690c60c43b99a20fb2580ea2 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public static void main(String args[]) throws IOException {
InOut inout = new InOut();
Resolver resolver = new Resolver(inout);
resolver.solve();
inout.flush();
}
private static class Resolver {
final long LONG_INF = (long) 1e18;
final int INF = (int) (1e9 + 7);
final int MOD = 998244353;
long f[];
InOut inout;
Resolver(InOut inout) {
this.inout = inout;
}
void initF(int n) {
f = new long[n + 1];
f[1] = 1;
for (int i = 2; i <= n; i++) {
f[i] = (f[i - 1] * i) % MOD;
}
}
int d[] = {0, -1, 0, 1, 0};
boolean legal(int r, int c, int n, int m) {
return r >= 0 && r < n && c >= 0 && c < m;
}
private static class Tree {
int mx = 0;
int left;
int right;
Tree(int left, int right) {
this.left = left;
this.right = right;
}
static void updateUp(Map<Integer, Tree> lineTree, int k) {
lineTree.get(k).mx = Math.max(lineTree.get(k << 1).mx, lineTree.get(k << 1 | 1).mx);
}
static void build(int l, int r, Map<Integer, Tree> lineTree, int a[], int k) {
lineTree.put(k, new Tree(l, r));
if (l == r) {
lineTree.get(k).mx = a[l];
return;
}
int mid = l + (r - l) / 2;
build(l, mid, lineTree, a, k << 1);
build(mid + 1, r, lineTree, a, k << 1 | 1);
updateUp(lineTree, k);
}
static int query(int L, int R, int l, int r, Map<Integer, Tree> lineTree, int k) {
if (L <= l && r <= R) {
return lineTree.get(k).mx;
}
if (r < L || l > R) {
return 0;
}
int mid = l + (r - l) / 2;
return Math.max(query(L, R, l, mid, lineTree, k << 1),
query(L, R, mid + 1, r, lineTree, k << 1 | 1));
}
}
void solve() throws IOException {
int tt = 1;
boolean hvt = true;
if (hvt) {
tt = nextInt();
}
for (int cs = 1; cs <= tt; cs++) {
long rs = 0;
int n = nextInt();
int cnt[] = new int[31];
for (int i = 0; i < n; i++) {
int a = nextInt();
int idx = 0;
while (a > 0) {
cnt[idx++] += a % 2;
a >>= 1;
}
}
boolean win = false;
boolean lose = false;
for (int i = 30; i >= 0; i--) {
if (cnt[i] % 2 == 1) {
int lft = (n - cnt[i]) % 2;
if (cnt[i] % 4 == 1 || lft == 1 && cnt[i] % 4 == 3) {
win = true;
} else {
lose = true;
}
break;
}
}
if (win) {
format("WIN");
} else if (lose) {
format("LOSE");
} else {
format("DRAW");
}
// format("Case #%d: %d", cs, rs);
// format("%d:", rs);
if (cs < tt) {
format("\n");
}
// flush();
}
}
String next(int n) throws IOException {
return inout.next(n);
}
String nextLine() throws IOException {
return inout.nextLine();
}
int nextInt() throws IOException {
return inout.nextInt();
}
long nextLong(int n) throws IOException {
return inout.nextLong(n);
}
long[] anLong(int i, int j, int len) throws IOException {
long a[] = new long[j + 1];
for (int k = i; k <= j; k++) {
a[k] = nextLong(len);
}
return a;
}
void print(String s, boolean nextLine) {
inout.print(s, nextLine);
}
void format(String format, Object... obj) {
inout.format(format, obj);
}
void flush() {
inout.flush();
}
void swap(long a[], int i, int j) {
a[i] ^= a[j];
a[j] ^= a[i];
a[i] ^= a[j];
}
int getP(int x, int p[]) {
if (p[x] == 0 || p[x] == x) {
return x;
}
return p[x] = getP(p[x], p);
}
void union(int x, int y, int p[]) {
if (x < y) {
p[y] = x;
} else {
p[x] = y;
}
}
boolean topSort() {
int n = adj.length - 1;
int d[] = new int[n + 1];
for (int i = 1; i <= n; i++) {
for (int j = 0; j < adj[i].size(); j++) {
d[adj[i].get(j)[0]]++;
}
}
List<Integer> list = new ArrayList<>();
for (int i = 1; i <= n; i++) {
if (d[i] == 0) {
list.add(i);
}
}
for (int i = 0; i < list.size(); i++) {
for (int j = 0; j < adj[list.get(i)].size(); j++) {
int t = adj[list.get(i)].get(j)[0];
d[t]--;
if (d[t] == 0) {
list.add(t);
}
}
}
return list.size() == n;
}
class BinaryIndexedTree {
int n = 1;
long C[];
BinaryIndexedTree(int sz) {
while (n <= sz) {
n <<= 1;
}
C = new long[n];
}
int lowbit(int x) {
return x & -x;
}
void add(int x, long val) {
while (x < n) {
C[x] += val;
x += lowbit(x);
}
}
long getSum(int x) {
long res = 0;
while (x > 0) {
res += C[x];
x -= lowbit(x);
}
return res;
}
int binSearch(long sum) {
if (sum == 0) {
return 0;
}
int n = C.length;
int mx = 1;
while (mx < n) {
mx <<= 1;
}
int res = 0;
for (int i = mx / 2; i >= 1; i >>= 1) {
if (C[res + i] < sum) {
sum -= C[res + i];
res += i;
}
}
return res + 1;
}
}
//Binary tree
class TreeNode {
int val;
int tier = -1;
TreeNode parent;
TreeNode left;
TreeNode right;
TreeNode(int val) {
this.val = val;
}
}
//binary tree dfs
void tierTree(TreeNode root) {
if (null == root) {
return;
}
if (null != root.parent) {
root.tier = root.parent.tier + 1;
} else {
root.tier = 0;
}
tierTree(root.left);
tierTree(root.right);
}
//LCA start
TreeNode[][] lca;
TreeNode[] tree;
void lcaDfsTree(TreeNode root) {
if (null == root) {
return;
}
tree[root.val] = root;
TreeNode nxt = root.parent;
int idx = 0;
while (null != nxt) {
lca[root.val][idx] = nxt;
nxt = lca[nxt.val][idx];
idx++;
}
lcaDfsTree(root.left);
lcaDfsTree(root.right);
}
TreeNode lcaTree(TreeNode root, int n, TreeNode x, TreeNode y) throws IOException {
if (null == root) {
return null;
}
if (-1 == root.tier) {
tree = new TreeNode[n + 1];
tierTree(root);
}
if (null == lca) {
lca = new TreeNode[n + 1][31];
lcaDfsTree(root);
}
int z = Math.abs(x.tier - y.tier);
int xx = x.tier > y.tier ? x.val : y.val;
while (z > 0) {
final int zz = z;
int l = (int) binSearch(0, 31
, k -> zz < (1 << k));
xx = lca[xx][l].val;
z -= 1 << l;
}
int yy = y.val;
if (x.tier <= y.tier) {
yy = x.val;
}
while (xx != yy) {
final int xxx = xx;
final int yyy = yy;
int l = (int) binSearch(0, 31
, k -> (1 << k) <= tree[xxx].tier && lca[xxx][(int) k] != lca[yyy][(int) k]);
xx = lca[xx][l].val;
yy = lca[yy][l].val;
}
return tree[xx];
}
//LCA end
//graph
List<int[]> adj[];
void initGraph(int n, int m, boolean hasW, boolean directed) throws IOException {
adj = new List[n + 1];
for (int i = 1; i <= n; i++) {
adj[i] = new ArrayList<>();
}
for (int i = 0; i < m; i++) {
int f = nextInt();
int t = nextInt();
int w = hasW ? nextInt() : 0;
adj[f].add(new int[]{t, w});
if (!directed) {
adj[t].add(new int[]{f, w});
}
}
}
long binSearch(long l, long r, BinSearch sort) throws IOException {
while (l < r) {
long m = l + (r - l) / 2;
if (sort.binSearchCmp(m)) {
l = m + 1;
} else {
r = m;
}
}
return l;
}
void getDiv(Map<Integer, Integer> map, int n) {
int sqrt = (int) Math.sqrt(n);
for (int i = sqrt; i >= 2; i--) {
if (n % i == 0) {
getDiv(map, i);
getDiv(map, n / i);
return;
}
}
map.put(n, map.getOrDefault(n, 0) + 1);
}
boolean[] generatePrime(int n) {
boolean p[] = new boolean[n + 1];
p[2] = true;
for (int i = 3; i <= n; i += 2) {
p[i] = true;
}
for (int i = 3; i <= Math.sqrt(n); i += 2) {
if (!p[i]) {
continue;
}
for (int j = i * i; j <= n; j += i << 1) {
p[j] = false;
}
}
return p;
}
boolean isPrime(long n) { //determines if n is a prime number
int p[] = {2, 3, 5, 233, 331};
int pn = p.length;
long s = 0, t = n - 1;//n - 1 = 2^s * t
while ((t & 1) == 0) {
t >>= 1;
++s;
}
for (int i = 0; i < pn; ++i) {
if (n == p[i]) {
return true;
}
long pt = pow(p[i], t, n);
for (int j = 0; j < s; ++j) {
long cur = llMod(pt, pt, n);
if (cur == 1 && pt != 1 && pt != n - 1) {
return false;
}
pt = cur;
}
if (pt != 1) {
return false;
}
}
return true;
}
long llMod(long a, long b, long mod) {
return (a * b - (long) ((double) a / mod * b + 0.5) * mod + mod) % mod;
// long r = 0;
// a %= mod;
// b %= mod;
// while (b > 0) {
// if ((b & 1) == 1) {
// r = (r + a) % mod;
// }
// b >>= 1;
// a = (a << 1) % mod;
// }
// return r;
}
long pow(long a, long n) {
long ans = 1;
while (n > 0) {
if ((n & 1) == 1) {
ans = ans * a;
}
a = a * a;
n >>= 1;
}
return ans;
}
long pow(long a, long n, long mod) {
long ans = 1;
while (n > 0) {
if ((n & 1) == 1) {
ans = llMod(ans, a, mod);
}
a = llMod(a, a, mod);
n >>= 1;
}
return ans;
}
private long[][] initC(int n) {
long c[][] = new long[n][n];
for (int i = 0; i < n; i++) {
c[i][0] = 1;
}
for (int i = 1; i < n; i++) {
for (int j = 1; j <= i; j++) {
c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
}
}
return c;
}
/**
* ps: n >= m, choose m from n;
*/
private int cmn(long n, long m) {
if (m > n) {
n ^= m;
m ^= n;
n ^= m;
}
m = Math.min(m, n - m);
long top = 1;
long bot = 1;
for (long i = n - m + 1; i <= n; i++) {
top = (top * i) % MOD;
}
for (int i = 1; i <= m; i++) {
bot = (bot * i) % MOD;
}
return (int) ((top * pow(bot, MOD - 2, MOD)) % MOD);
}
long gcd(long a, long b) {
if (a < b) {
return gcd(b, a);
}
while (b != 0) {
long tmp = a % b;
a = b;
b = tmp;
}
return a;
}
boolean isEven(long n) {
return (n & 1) == 0;
}
interface BinSearch {
boolean binSearchCmp(long k) throws IOException;
}
}
private static class InOut {
private BufferedReader br;
private StreamTokenizer st;
private PrintWriter pw;
InOut() throws FileNotFoundException {
// System.setIn(new FileInputStream("resources/inout/in.text"));
// System.setOut(new PrintStream("resources/inout/out.text"));
br = new BufferedReader(new InputStreamReader(System.in));
st = new StreamTokenizer(br);
pw = new PrintWriter(new OutputStreamWriter(System.out));
st.ordinaryChar('\'');
st.ordinaryChar('\"');
st.ordinaryChar('/');
}
private long[] anLong(int n) throws IOException {
long a[] = new long[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
private String next(int len) throws IOException {
char ch[] = new char[len];
int cur = 0;
char c;
while ((c = (char) br.read()) == '\n' || c == '\r' || c == ' ' || c == '\t') ;
do {
ch[cur++] = c;
} while (!((c = (char) br.read()) == '\n' || c == '\r' || c == ' ' || c == '\t'));
return String.valueOf(ch, 0, cur);
}
private int nextInt() throws IOException {
st.nextToken();
return (int) st.nval;
}
private long nextLong(int n) throws IOException {
return Long.parseLong(next(n));
}
private double nextDouble() throws IOException {
st.nextToken();
return st.nval;
}
private String[] nextSS(String reg) throws IOException {
return br.readLine().split(reg);
}
private String nextLine() throws IOException {
return br.readLine();
}
private void print(String s, boolean newLine) {
if (null != s) {
pw.print(s);
}
if (newLine) {
pw.println();
}
}
private void format(String format, Object... obj) {
pw.format(format, obj);
}
private void flush() {
pw.flush();
}
}
} | Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | 170ffb06a8cb250a106db97e34eb8998 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | //created by Whiplash99
import java.io.*;
import java.util.*;
public class A
{
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,N;
int T=Integer.parseInt(br.readLine().trim());
StringBuilder sb=new StringBuilder();
next: while(T-->0)
{
N=Integer.parseInt(br.readLine().trim());
String[] s=br.readLine().trim().split(" ");
int a[]=new int[N];
for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);
int[] set=new int[35];
int[] unset=new int[35];
for(i=30;i>=0;i--)
{
int x=0,y=0;
for(int z:a)
{
if(((1<<i)&z)>0) x++;
else y++;
}
if(x%2==0) continue;
if(x%4==3&&y%2==0)sb.append("LOSE\n");
else sb.append("WIN\n");
continue next;
}
sb.append("DRAW\n");
}
System.out.println(sb);
}
} | Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | e85d3f53df50cef679315b21350729da | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | //created by Whiplash99
import java.io.*;
public class A
{
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,N;
int T=Integer.parseInt(br.readLine().trim());
StringBuilder sb=new StringBuilder();
next: while(T-->0)
{
N=Integer.parseInt(br.readLine().trim());
String[] s=br.readLine().trim().split(" ");
int[] a=new int[N];
for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);
for(i=30;i>=0;i--)
{
int x=0,y=0;
for(int z:a)
{
if(((1<<i)&z)>0) x++;
else y++;
}
if(x%2==0) continue;
if(x%4==3&&y%2==0)sb.append("LOSE\n");
else sb.append("WIN\n");
continue next;
}
sb.append("DRAW\n");
}
System.out.println(sb);
}
} | Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | 0beccf21ddba9c5f7f073ee04c9936cb | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes |
import java.util.*;
import org.ietf.jgss.GSSManager;
import java.awt.GridBagConstraints;
import java.awt.geom.AffineTransform;
import java.io.*;
import java.lang.reflect.Member;
public class Main {
public static void main(String[] args) throws Exception {
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int ans=0;
int[] a=sc.nextIntArray(n);
for(int i=0;i<n;i++) {
ans=ans^a[i];
}
if(Integer.bitCount(ans)==0) {
pw.println("DRAW");
}else {
int coun=Integer.highestOneBit(ans);
int num=0;
for(int i=0;i<n;i++) {
if((a[i]&coun)!=0) {
num++;
}
}
if(num%4==3&&(n)%2==1) {
pw.println("LOSE");
}else {
pw.println("WIN");
}
}
}
pw.close();
}
// public static class SegmentTree { // 1-based DS, OOP
//
// int N; //the number of elements in the array as a power of 2 (i.e. after padding)
// long[] array ;
// long[] sTree;
// long[] lazy;
//
// SegmentTree(long[] a)
// {
//
// int nn = a.length;
// int NN = 1; while(NN < nn) NN <<= 1; //padding
//
// long[] in = new long[NN + 1];
// for(int i = 1; i <= nn; i++)
// in[i] = a[i-1];
//
// array = in;
// N = in.length - 1;
// sTree = new long[N<<1]; //no. of nodes = 2*N - 1, we add one to cross out index zero
// lazy = new long[N<<1];
// build(1,1,N);
// }
// SegmentTree(int[] a)
// {
//
// int nn = a.length;
// int NN = 1; while(NN < nn) NN <<= 1; //padding
//
// long[] in = new long[NN + 1];
//
// for(int i = 1; i <= nn; i++)
// in[i] = a[i-1];
//
// array = in;
// N = in.length - 1;
// sTree = new long[N<<1]; //no. of nodes = 2*N - 1, we add one to cross out index zero
//
// lazy = new long[N<<1];
//
// build(1,1,N);
// }
//
// void build(int node, int b, int e) // O(n)
// {
// if(b == e) {
// sTree[node] = array[b];
//
// }
// else
// {
// int mid = b + e >> 1;
// build(node<<1,b,mid);
// build(node<<1|1,mid+1,e);
// sTree[node] = sTree[node<<1]+sTree[node<<1|1];
//
//
// }
// }
//
//
// void update_point(int index, long val) // O(log n)
// {
// index += N;
// sTree[index] = val;
// while(index>1)
// {
// index >>= 1;
// sTree[index] = sTree[index<<1] + sTree[index<<1|1];
//
// }
// }
//
//
// void update_range(int i, int j, long val) // O(log n)
// {
// update_range(1,1,N,i,j,val);
// }
//
// void update_range(int node, int b, int e, int i, int j, long val)
// {
// if(i > e || j < b)
// return;
// if(b >= i && e <= j)
// {
// sTree[node] += (e-b+1)*val;
// lazy[node] += val;
// }
// else
// {
// int mid = b + e >> 1;
// propagate(node, b, mid, e);
// update_range(node<<1,b,mid,i,j,val);
// update_range(node<<1|1,mid+1,e,i,j,val);
// sTree[node] = sTree[node<<1] + sTree[node<<1|1];
// }
//
// }
// void propagate(int node, int b, int mid, int e)
// {
// lazy[node<<1] += lazy[node];
// lazy[node<<1|1] += lazy[node];
// sTree[node<<1] += (mid-b+1)*lazy[node];
// sTree[node<<1|1] += (e-mid)*lazy[node];
// lazy[node] = 0;
// }
//
// long query(int i, int j)
// {
// return query(1,1,N,i+1,j+1);
// }
//
// long query(int node, int b, int e, int i, int j) // O(log n)
// {
// if(i>e || j <b)
// return 0;
// if(b>= i && e <= j)
// return sTree[node];
// int mid = b + e >> 1;
// propagate(node, b, mid, e);
// long q1 = query(node<<1,b,mid,i,j);
// long q2 = query(node<<1|1,mid+1,e,i,j);
// return q1 + q2;
//
//
// }
//
//
//
//
// }
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public long[] nextlongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public Long[] nextLongArray(int n) throws IOException {
Long[] a = new Long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
}
static class pair implements Comparable<pair> {
long x;
long y;
public pair(long x, long y) {
this.x = x;
this.y = y;
}
public String toString() {
return x + " " + y;
}
public boolean equals(Object o) {
if (o instanceof pair) {
pair p = (pair)o;
return p.x == x && p.y == y;
}
return false;
}
public int hashCode() {
return new Double(x).hashCode() * 31 + new Double(y).hashCode();
}
public int compareTo(pair other) {
if(this.x==other.x) {
return Long.compare(this.y, other.y);
}
return Long.compare(this.x, other.x);
}
}
static class tuble implements Comparable<tuble> {
int x;
int y;
int z;
public tuble(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public String toString() {
return x + " " + y + " " + z;
}
public int compareTo(tuble other) {
if (this.x == other.x) {
if(this.y==other.y) {
return this.z - other.z;
}
return this.y - other.y;
} else {
return this.x - other.x;
}
}
}
public static long GCD(long a, long b) {
if (b == 0)
return a;
if (a == 0)
return b;
return (a > b) ? GCD(a % b, b) : GCD(a, b % a);
}
public static long LCM(long a, long b) {
return a * b / GCD(a, b);
}
static long Pow(long a, long e, long mod) // O(log e)
{
a %= mod;
long res = 1l;
while (e > 0) {
if ((e & 1) == 1)
res = (res * a) % mod;
a = (a * a) % mod;
e >>= 1l;
}
return res;
}
public static long modinverse(long a,long mod) {
return Pow(a, mod-2, mod);
}
static long nc(int n, int r) {
if (n < r)
return 0;
long v = fac[n];
v *= Pow(fac[r], mod - 2, mod);
v %= mod;
v *= Pow(fac[n - r], mod - 2, mod);
v %= mod;
return v;
}
static long np(int n,int r) {
return (nc(n, r)*fac[r])%mod;
}
public static boolean isprime(long a) {
if (a == 0 || a == 1) {
return false;
}
if (a == 2) {
return true;
}
for (int i = 2; i < Math.sqrt(a) + 1; i++) {
if (a % i == 0) {
return false;
}
}
return true;
}
public static boolean isPal(String s) {
boolean t = true;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
t = false;
break;
}
}
return t;
}
public static long RandomPick(long[] a) {
int n = a.length;
int r = rn.nextInt(n);
return a[r];
}
public static int RandomPick(int[] a) {
int n = a.length;
int r = rn.nextInt(n);
return a[r];
}
static class hash {
int[]HashsArray;
boolean reverse;
int prelen;
public hash(String s, boolean r) {
prelen = s.length();
reverse=r;
HashsArray = new int[prelen + 1];
if (HashsArrayInd == 0) {
int[] mods = { 1173017693, 1173038827, 1173069731, 1173086977, 1173089783, 1173092147, 1173107093,
1173114391, 1173132347, 1173144367, 1173150103, 1173152611, 1173163993, 1173174127, 1173204679,
1173237343, 1173252107, 1173253331, 1173255653, 1173260183, 1173262943, 1173265439, 1173279091,
1173285331, 1173286771, 1173288593, 1173298123, 1173302129, 1173308827, 1173310451, 1173312383,
1173313571, 1173324371, 1173361529, 1173385729, 1173387217, 1173387361, 1173420799, 1173421499,
1173423077, 1173428083, 1173442159, 1173445549, 1173451681, 1173453299, 1173454729, 1173458401,
1173459491, 1173464177, 1173468943, 1173470041, 1173477947, 1173500677, 1173507869, 1173522919,
1173537359, 1173605003, 1173610253, 1173632671, 1173653623, 1173665447, 1173675577, 1173675787,
1173684683, 1173691109, 1173696907, 1173705257, 1173705523, 1173725389, 1173727601, 1173741953,
1173747577, 1173751499, 1173759449, 1173760943, 1173761429, 1173762509, 1173769939, 1173771233,
1173778937, 1173784637, 1173793289, 1173799607, 1173802823, 1173808003, 1173810919, 1173818311,
1173819293, 1173828167, 1173846677, 1173848941, 1173853249, 1173858341, 1173891613, 1173894053,
1173908039, 1173909203, 1173961541, 1173968989, 1173999193};
mod = RandomPick(mods);
int[] primes = { 59, 61, 67, 71, 73, 79, 83, 89, 97, 101 };
prime = RandomPick(primes);
prepow = new int[1000010];
prepow[0] = 1;
for (int i = 1; i < 1000010; i++) {
prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod);
}
}
if (!reverse) {
for (int i = 0; i < prelen; i++) {
if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z')
HashsArray[i + 1] = (int) ((1l * HashsArray[i]
+ ((1l * s.charAt(i) - 'a' + 1) *prepow[i]) % mod) % mod);
else
HashsArray[i + 1] = (int) ((1l * HashsArray[i]
+ ((1l * s.charAt(i) - 'A' + 27) * prepow[i]) % mod) % mod);
}
} else {
for (int i = 0; i < prelen; i++) {
if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z')
HashsArray[i + 1] = (int) ((1l * HashsArray[i]
+ ((1l * s.charAt(i) - 'a' + 1) * prepow[1000010 - 1 - i]) % mod) % mod);
else
HashsArray[i + 1] = (int) ((1l * HashsArray[i]
+ ((1l * s.charAt(i) - 'A' + 27) * prepow[1000010 - 1 - i]) % mod) % mod);
}
}
HashsArrayInd++;
}
public int PHV(int l, int r) {
if (l > r) {
return 0;
}
int val = (int) ((1l * HashsArray[r] + mod - HashsArray[l - 1]) % mod);
if (!reverse) {
// val = (int) ((1l * val * modinverse(prepow[l-1], mod)) % mod);
val = (int) ((1l * val * prepow[1000010 - l]) % mod);
} else {
// val = (int) ((1l * val * modinverse(prepow[prelen-r], mod)) % mod);
val = (int) ((1l * val * prepow[r - 1]) % mod);
}
return val;
}
}
public static void genprime(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) {
primes.put(i,primes.size());
primes2.put(primes2.size(),i);
}
}
}
public static long LSB(long x) {
return x&-x;
}
static class fenwick {
long[] arr;
public fenwick(PriorityQueue<Integer> a) {
PriorityQueue<Integer>q=new PriorityQueue<Integer>(a);
arr=new long[a.size()+1];
int i=1;
while(!q.isEmpty()) {
int z=q.poll();
arr[i]+=z;
if(i+LSB(i)<=a.size()) {
arr[(int) (i+LSB(i))]+=arr[i];
}
i++;
}
}
public fenwick(TreeSet<Integer> a) {
arr=new long[a.size()+1];
int i=1;
for(int h:a) {
arr[i]+=h;
if(i+LSB(i)<=a.size()) {
arr[(int) (i+LSB(i))]+=arr[i];
}
i++;
}
}
public fenwick(Integer a) {
arr=new long[a];
}
public fenwick(Integer[] a) {
arr=new long[a.length+1];
for(int i=1;i<=a.length;i++) {
arr[i]+=a[i-1];
if(i+LSB(i)<=a.length) {
arr[(int) (i+LSB(i))]+=arr[i];
}
}
}
public fenwick(int[] a) {
arr=new long[a.length+1];
for(int i=1;i<=a.length;i++) {
arr[i]+=a[i-1];
if(i+LSB(i)<=a.length) {
arr[(int) (i+LSB(i))]+=arr[i];
}
}
}public fenwick(long[] a) {
arr=new long[a.length+1];
for(int i=1;i<=a.length;i++) {
arr[i]+=a[i];
if(i+LSB(i)<=a.length) {
arr[(int) (i+LSB(i))]+=arr[i];
}
}
}
public void update(int ind,long x) {
int i=ind;
while(i<arr.length) {
arr[i]+=x;
i+=LSB(i);
}
}
public long PrefixSum(int ind) {
long sum=0;
int i=ind;
while(i>0) {
sum+=arr[i];
i=(int) (i-LSB(i));
}
return sum;
}
public long RangeQuerey(int l,int r) {
return this.PrefixSum(r+1)-this.PrefixSum(l);
}
public long maxConsecutiveValue(int k) {
long max=Long.MIN_VALUE;
for(int i=k-1;i<arr.length-1;i++) {
max= Math.max(max, this.RangeQuerey(i-k+1, i));
}
return max;
}
public long minConsecutiveValue(int k) {
long min=Long.MAX_VALUE;
for(int i=k-1;i<arr.length-1;i++) {
min= Math.min(min, this.RangeQuerey(i-k+1, i));
}
return min;
}
public long value(int ind) {
return arr[ind];
}
}
static void sieveLinear(int N)
{
ArrayList<Integer> primes = new ArrayList<Integer>();
lp = new int[N + 1]; //lp[i] = least prime divisor of i
for(int i = 2; i <= N; ++i)
{
if(lp[i] == 0)
{
primes.add(i);
lp[i] = i;
}
int curLP = lp[i];
for(int p: primes)//all primes smaller than or equal my lowest prime divisor
if(p > curLP || p * 1l * i > N)
break;
else
lp[p * i] = p;
}
}
public static void primefactorization(int n) {
int x=n;
while(x>1) {
int lowestDivisor=lp[x];
while(x%lowestDivisor==0) {
primefactors.add(lowestDivisor);
x/=lowestDivisor;
}
}
}
public static class SuffixArray {
int[] SA;
int[] AS;
String SS;
public SuffixArray(String S) //has a terminating character (e.g. '$')
{
SS=S;
char[] s=new char[S.length()+1];
for(int i=0;i<S.length();i++) {
s[i]=S.charAt(i);
}
s[S.length()]='$';
int n = s.length, RA[] = new int[n];
SA = new int[n];
for(int i = 0; i < n; ++i) { RA[i] = s[i]; SA[i] = i; }
for(int k = 1; k < n; k <<= 1)
{
sort(SA, RA, n, k);
sort(SA, RA, n, 0);
int[] tmp = new int[n];
for(int i = 1, r = 0, s1 = SA[0], s2; i < n; ++i)
{
s2 = SA[i];
tmp[s2] = RA[s1] == RA[s2] && RA[s1 + k] == RA[s2 + k] ? r : ++r;
s1 = s2;
}
for(int i = 0; i < n; ++i)
RA[i] = tmp[i];
if(RA[SA[n-1]] == n - 1)
break;
}
AS=new int[SA.length];
for(int i=0;i<SA.length;i++) {
AS[SA[i]]=i;
}
}
public String toString() {
return Arrays.toString(SA);
}
public int get(int n) {
return SA[n];
}
public int Substring(String s) { // log(n)*|s|
int low=0;
int high=SA.length;
int mid=(low+high)/2;
int ind=-1;
while(low<high-1) {
if(SS.length()-SA[mid]<s.length()) {
boolean less=false;
for(int i=SA[mid];i<SS.length();i++) {
if(SS.charAt(i)>s.charAt(i-SA[mid])) {
less=true;
break;
}
if(SS.charAt(i)<s.charAt(i-SA[mid])) {
less=false;
break;
}
}
if(!less) {
low=mid;
}else {
high=mid;
}
}else {
boolean less=true;
boolean equal=true;
for(int i=SA[mid];i<SA[mid]+s.length();i++) {
if(SS.charAt(i)<s.charAt(i-SA[mid])&&equal) {
less=false;
equal=false;
break;
}
if(SS.charAt(i)!=s.charAt(i-SA[mid])){
equal=false;
}
}
if(equal) {
ind=SA[mid];
}
if(!less) {
low=mid;
}else {
high=mid;
}
}
mid=(low+high)/2;
}
return ind;
}
public int LastSubstring(String s) { // log(n)*|s|
int low=0;
int high=SA.length;
int mid=(low+high)/2;
int ind=-1;
while(low<high-1) {
if(SS.length()-SA[mid]<s.length()) {
boolean less=true;
for(int i=SA[mid];i<SS.length();i++) {
if(SS.charAt(i)<s.charAt(i-SA[mid])) {
break;
}
if(SS.charAt(i)>s.charAt(i-SA[mid])) {
less=false;
break;
}
}
if(less) {
low=mid;
}else {
high=mid;
}
}else {
boolean less=true;
boolean equal=true;
for(int i=SA[mid];i<SA[mid]+s.length();i++) {
if(SS.charAt(i)>s.charAt(i-SA[mid])&&equal) {
less=false;
equal=false;
break;
}
if(SS.charAt(i)!=s.charAt(i-SA[mid])){
equal=false;
}
}
if(equal) {
ind=SA[mid];
}
if(less) {
low=mid;
}else {
high=mid;
}
}
mid=(low+high)/2;
}
return ind;
}
public int CountSubstring(String s) {
int z=LastSubstring(s);
if(z==-1)
return 0;
return AS[z]-AS[Substring(s)]+1;
}
public void sort(int[] SA, int[] RA, int n, int k)
{
int maxi = Math.max(256, n), c[] = new int[maxi];
for(int i = 0; i < n; ++i)
c[i + k < n ? RA[i + k] : 0]++;
for(int i = 0, sum = 0; i < maxi; ++i)
{
int t = c[i];
c[i] = sum;
sum += t;
}
int[] tmp = new int[n];
for(int i = 0; i < n; ++i)
{
int j = SA[i] + k;
tmp[c[j < n ? RA[j] : 0]++] = SA[i];
}
for(int i = 0; i < n; ++i)
SA[i] = tmp[i];
}
}
public static class UnionFind {
int[] p, rank, setSize;
int numSets;
public UnionFind(int N)
{
p = new int[numSets = N];
rank = new int[N];
setSize = new int[N];
for (int i = 0; i < N; i++) { p[i] = i; setSize[i] = 1; }
}
public int findSet(int i) { return p[i] == i ? i : (p[i] = findSet(p[i])); }
public boolean isSameSet(int i, int j) { return findSet(i) == findSet(j); }
public void unionSet(int i, int j)
{
if (isSameSet(i, j))
return;
numSets--;
int x = findSet(i), y = findSet(j);
if(rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
else
{ p[x] = y; setSize[y] += setSize[x];
if(rank[x] == rank[y]) rank[y]++;
}
}
public int numDisjointSets() { return numSets; }
public int sizeOfSet(int i) { return setSize[findSet(i)]; }
}
static LinkedList<Integer>primefactors=new LinkedList<>();
static TreeMap<Integer,Integer>primes=new TreeMap<Integer, Integer>();
static TreeMap<Integer,Integer>primes2=new TreeMap<Integer, Integer>();
static int[]lp;
static int HashsArrayInd = 0;
static int[] prepow;
static int prime = 61;
static long fac[];
static int mod = 1000000007;
static Random rn = new Random();
static Scanner sc = new Scanner(System.in);
static PrintWriter pw = new PrintWriter(System.out);
} | Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | 9f0cca4e31bbd84e10f2640614f1eb44 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
static void solve() throws Exception{
int n = sc.nextInt(), arr[] = new int[n];
for(int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int one = 0, zero = 0;
for(int bit = 30; bit >= 0; bit--) {
one = zero = 0;
for(int i = 0; i < n; i++) {
if((arr[i] & (1 << bit)) != 0) one++;
else zero++;
}
if(one % 2 != 0) break;
}
if(one % 2 == 0) {
out.println("DRAW");
return;
}
if(one % 4 == 1) {
out.println("WIN");
return;
}
out.println(zero % 2 == 0 ? "LOSE" : "WIN");
}
public static void main(String[] args) throws Exception {
int t = sc.nextInt();
while(t-- > 0) {
solve();
}
out.close();
}
}
class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
public Scanner(String file) throws Exception {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String nextLine() throws IOException {
return br.readLine();
}
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());
}
} | Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | 8785dd7f506006fcaf82a2f8be885ec3 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | // package CodeForces;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
public class Round659D {
public static void solve() {
int t = s.nextInt();
o : while(t-- > 0) {
int n = s.nextInt();
int[] arr = s.nextIntArray(n);
for(int i = 30; i >= 0; i--) {
int zeros = 0, ones = 0;
int number = 1<<i;
for(int j = 0; j < n; j++) {
if((arr[j]&number) > 0) {
ones++;
}else {
zeros++;
}
}
if(ones % 2 == 1 && zeros % 2 == 1) {
out.println("WIN");
continue o;
}else if(ones % 2 == 1 && zeros % 2 == 0) {
if(((ones - 1)/2) % 2 == 1) {
out.println("LOSE");
continue o;
}else {
out.println("WIN");
continue o;
}
}
}
out.println("DRAW");
}
}
public static void main(String[] args) {
new Thread(null, null, "Thread", 1 << 27) {
public void run() {
try {
out = new PrintWriter(new BufferedOutputStream(System.out));
s = new FastReader(System.in);
solve();
out.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}.start();
}
public static PrintWriter out;
public static FastReader s;
public static class FastReader {
private InputStream stream;
private byte[] buf = new byte[4096];
private int curChar, snumChars;
public FastReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (snumChars == -1) {
throw new InputMismatchException();
}
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException E) {
throw new InputMismatchException();
}
}
if (snumChars <= 0) {
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int number = 0;
do {
number *= 10;
number += c - '0';
c = read();
} while (!isSpaceChar(c));
return number * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
long sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long number = 0;
do {
number *= 10L;
number += (long) (c - '0');
c = read();
} while (!isSpaceChar(c));
return number * sgn;
}
public int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = this.nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = this.nextLong();
}
return arr;
}
public String next() {
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 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 boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public boolean isEndofLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
}
| Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | c6cc42daaa29a5f4fb683269a83054fa | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | // Utilities
import java.io.*;
import java.util.*;
public class Main {
static int T;
static int N;
static int[] a;
static int[] cnt;
static int zeroCnt;
public static void main(String[] args) throws IOException {
T = in.iscan();
outer : while (T-- > 0) {
N = in.iscan(); a = new int[N]; cnt = new int[32];
for (int i = 0; i < N; i++) {
a[i] = in.iscan();
for (int j = 0; j < 32; j++) {
if ((a[i] & (1 << j)) > 0) cnt[j]++;
}
}
for (int j = 31; j >= 0; j--) {
if (cnt[j] % 2 == 1) {
if (cnt[j] % 4 == 1) {
out.println("WIN");
}
else { // cnt[j] % 4 = 3
zeroCnt = N - cnt[j];
if (zeroCnt % 2 == 0) out.println("LOSE");
else out.println("WIN");
}
continue outer;
}
}
out.println("DRAW");
}
out.close();
}
static INPUT in = new INPUT(System.in);
static PrintWriter out = new PrintWriter(System.out);
private static class INPUT {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar, numChars;
public INPUT (InputStream stream) {
this.stream = stream;
}
public INPUT (String file) throws IOException {
this.stream = new FileInputStream (file);
}
public int cscan () throws IOException {
if (curChar >= numChars) {
curChar = 0;
numChars = stream.read (buf);
}
if (numChars == -1)
return numChars;
return buf[curChar++];
}
public int iscan () throws IOException {
int c = cscan (), sgn = 1;
while (space (c))
c = cscan ();
if (c == '-') {
sgn = -1;
c = cscan ();
}
int res = 0;
do {
res = (res << 1) + (res << 3);
res += c - '0';
c = cscan ();
}
while (!space (c));
return res * sgn;
}
public String sscan () throws IOException {
int c = cscan ();
while (space (c))
c = cscan ();
StringBuilder res = new StringBuilder ();
do {
res.appendCodePoint (c);
c = cscan ();
}
while (!space (c));
return res.toString ();
}
public double dscan () throws IOException {
int c = cscan (), sgn = 1;
while (space (c))
c = cscan ();
if (c == '-') {
sgn = -1;
c = cscan ();
}
double res = 0;
while (!space (c) && c != '.') {
if (c == 'e' || c == 'E')
return res * UTILITIES.fast_pow (10, iscan ());
res *= 10;
res += c - '0';
c = cscan ();
}
if (c == '.') {
c = cscan ();
double m = 1;
while (!space (c)) {
if (c == 'e' || c == 'E')
return res * UTILITIES.fast_pow (10, iscan ());
m /= 10;
res += (c - '0') * m;
c = cscan ();
}
}
return res * sgn;
}
public long lscan () throws IOException {
int c = cscan (), sgn = 1;
while (space (c))
c = cscan ();
if (c == '-') {
sgn = -1;
c = cscan ();
}
long res = 0;
do {
res = (res << 1) + (res << 3);
res += c - '0';
c = cscan ();
}
while (!space (c));
return res * sgn;
}
public boolean space (int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
public static class UTILITIES {
static final double EPS = 10e-6;
public static int lower_bound (int[] arr, int x) {
int low = 0, high = arr.length, mid = -1;
while (low < high) {
mid = (low + high) / 2;
if (arr[mid] >= x)
high = mid;
else
low = mid + 1;
}
return low;
}
public static int upper_bound (int[] arr, int x) {
int low = 0, high = arr.length, mid = -1;
while (low < high) {
mid = (low + high) / 2;
if (arr[mid] > x)
high = mid;
else
low = mid + 1;
}
return low;
}
public static int gcd (int a, int b) {
return b == 0 ? a : gcd (b, a % b);
}
public static int lcm (int a, int b) {
return a * b / gcd (a, b);
}
public static long fast_pow_mod (long b, long x, int mod) {
if (x == 0) return 1;
if (x == 1) return b;
if (x % 2 == 0) return fast_pow_mod (b * b % mod, x / 2, mod) % mod;
return b * fast_pow_mod (b * b % mod, x / 2, mod) % mod;
}
public static int fast_pow (int b, int x) {
if (x == 0) return 1;
if (x == 1) return b;
if (x % 2 == 0) return fast_pow (b * b, x / 2);
return b * fast_pow (b * b, x / 2);
}
public static long choose (long n, long k) {
k = Math.min (k, n - k);
long val = 1;
for (int i = 0; i < k; ++i)
val = val * (n - i) / (i + 1);
return val;
}
public static long permute (int n, int k) {
if (n < k) return 0;
long val = 1;
for (int i = 0; i < k; ++i)
val = (val * (n - i));
return val;
}
}
} | Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | 46c46c4c1bff109d3d4110f67374b871 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.*;
import java.math.BigInteger;
public class GameGame{
public static FastReader fs = new FastReader();
static PrintWriter out = new PrintWriter(System.out);
static void solve() {
StringBuffer output = new StringBuffer();
int n = fs.nextInt();
int bit [] = new int [32];
for(int i = 0; i<n; i++) {
int x = fs.nextInt();
for(int j = 0; j<32; j++)bit[j] += ((x & (1 << j)) == 0 ? 0 : 1);
}
for(int i = 31; i>=0; i--) {
if(bit[i]%2 == 1) {
int x = bit[i];
if(((x+1)/2)%2 == 1) {
out.println("WIN");
return;
}
else {
if((n-x)%2 == 1)out.println("WIN");
else out.println("LOSE");
return;
}
}
}
out.println("DRAW");
}
public static void main(String[] args) {
int t = 1;
t = fs.nextInt();
for(int cs = 1; cs <= t; cs++) {
solve();
}
out.close();
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static int ceil(int x,int y) {
return (x % y == 0 ? x / y : (x / y +1));
}
static long ceil(long x,long y) {
return (x % y == 0 ? x / y : (x / y +1));
}
static int max(int x,int y) {
return Math.max(x, y);
}
static int min(int x,int y) {
return Math.min(x, y);
}
static long max(long x,long y) {
return Math.max(x, y);
}
static long min(long x,long y) {
return Math.min(x, y);
}
static int min(int a []) {
int x = 1_000_000_00_9;
for(int i = 0; i<a.length; i++)x = min(x,a[i]);
return x;
}
static int max(int a []) {
int x = -1_000_000_00_9;
for(int i = 0; i<a.length; i++)x = max(x,a[i]);
return x;
}
static long min(long a []) {
long x = (long)3e18;
for(int i = 0; i<a.length; i++)x = min(x,a[i]);
return x;
}
static long max(long a []) {
long x = -(long)3e18;
for(int i = 0; i<a.length; i++)x = max(x,a[i]);
return x;
}
static int power(int x,int y) {
int res = 1;
while(y > 0) {
if( y % 2 == 1)res = (res * x);
y >>= 1;
x = (x * x);
}
return res;
}
static long power(long x,long y) {
long res = 1;
while(y > 0) {
if( y % 2 == 1)res = (res * x);
y >>= 1;
x = (x * x);
}
return res;
}
static long power(long x,long y,long mod) {
long res = 1;
x %= mod;
while(y > 0) {
if( y % 2 == 1)res = (res * x) % mod;
y >>= 1;
x = (x * x) % mod;
}
return res;
}
static void intsort(int [] a) {
List<Integer> temp = new ArrayList<Integer>();
for(int i = 0; i<a.length; i++)temp.add(a[i]);
Collections.sort(temp);
for(int i = 0; i<a.length; i++)a[i] = temp.get(i);
}
static void longsort(long [] a) {
List<Long> temp = new ArrayList<Long>();
for(int i = 0; i<a.length; i++)temp.add(a[i]);
Collections.sort(temp);
for(int i = 0; i<a.length; i++)a[i] = temp.get(i);
}
static void reverseintsort(int [] a) {
List<Integer> temp = new ArrayList<Integer>();
for(int i = 0; i<a.length; i++)temp.add(a[i]);
Collections.sort(temp);
Collections.reverseOrder();
for(int i = 0; i<a.length; i++)a[i] = temp.get(i);
}
static void reverselongsort(long [] a) {
List<Long> temp = new ArrayList<Long>();
for(int i = 0; i<a.length; i++)temp.add(a[i]);
Collections.sort(temp);
Collections.reverseOrder();
for(int i = 0; i<a.length; i++)a[i] = temp.get(i);
}
static void intpairsort(intpair [] a) {
List<intpair> temp = new ArrayList<intpair>();
for(int i = 0; i<a.length; i++)temp.add(a[i]);
Collections.sort(temp,(p1,p2) -> {
if(p1.x == p2.x) return p1.y >= p2.y ? -1 : 1;
else return p1.x > p2.x ? -1 : 1;
});
for(int i = 0; i<a.length; i++)a[i] = temp.get(i);
}
static void longpairsort(longpair [] a) {
List<longpair> temp = new ArrayList<longpair>();
for(int i = 0; i<a.length; i++)temp.add(a[i]);
Collections.sort(temp,(p1,p2) -> {
if(p1.x == p2.x) return p1.y >= p2.y ? -1 : 1;
else return p1.x > p2.x ? -1 : 1;
});
for(int i = 0; i<a.length; i++)a[i] = temp.get(i);
}
static class intpair{
public int x;
public int y;
intpair(int a,int b){
this.x = a;
this.y = b;
}
intpair(){}
}
static class longpair{
public long x;
public long y;
longpair(long a,long b){
this.x = a;
this.y = b;
}
longpair(){}
}
static class data{
public long sum;
data(long val){
this.sum = val;
}
data(){}
data combine(data l, data r) {
data res = new data();
res.sum = l.sum + r.sum;
return res;
}
}
static class Seg_Tree extends data{
public int n;
data [] seg;
Seg_Tree(int sz){
this.n = sz;
seg = new data[4*n+4];
}
void build(long a[], int v, int tl, int tr) {
if (tl == tr) {
seg[v] = new data(a[tl]);
} else {
int tm = (tl + tr) / 2;
build(a, v*2, tl, tm);
build(a, v*2+1, tm+1, tr);
seg[v] = combine(seg[v*2],seg[v*2+1]);
}
}
void update(int v, int tl, int tr, int pos, long new_val) {
if (tl == tr) {
seg[v] = new data(new_val);
} else {
int tm = (tl + tr) / 2;
if (pos <= tm)
update(v*2, tl, tm, pos, new_val);
else
update(v*2+1, tm+1, tr, pos, new_val);
seg[v] = combine(seg[v*2],seg[v*2+1]);
}
}
data query(int v, int tl, int tr, int l, int r) {
if (l > r)
return new data(0);
if (l == tl && r == tr)
return seg[v];
int tm = (tl + tr) / 2;
return combine(query(v*2, tl, tm, l, min(r, tm)),query(v*2+1, tm+1, tr, max(l, tm+1), r));
}
}
static class Bit_Tree{
static int n;
static int [] bit;
Bit_Tree(int sz){
Bit_Tree.n = sz;
Bit_Tree.bit = new int[n+1];
}
static int child(int x) {
return x + (x & (-x));
}
static int parent(int x) {
return x - (x & (-x));
}
static void build(int [] a) {
for(int i = 0; i<a.length; i++) {
int start = i+1;
while(start <= n) {
bit[start] += a[i];
start = child(start);
}
}
}
static void update(int idx,int new_val) {
idx += 1;
while(idx <= n) {
bit[idx] += new_val;
idx = child(idx);
}
}
static int query(int right) {
int res = 0;
while(right > 0) {
res += bit[right];
right = parent(right);
}
return res;
}
static int query(int left,int right) {
return query(right) - query(left-1);
}
}
public static int gcd(int a, int b)
{
BigInteger b1 = BigInteger.valueOf(a);
BigInteger b2 = BigInteger.valueOf(b);
BigInteger gcd = b1.gcd(b2);
return gcd.intValue();
}
public static long gcd(long a, long b)
{
BigInteger b1 = BigInteger.valueOf(a);
BigInteger b2 = BigInteger.valueOf(b);
BigInteger gcd = b1.gcd(b2);
return gcd.longValue();
}
} | Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | 5ed86fa115fd581e0ea19e49ff9d20ca | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class d1384 implements Runnable{
public static void main(String[] args) {
try{
new Thread(null, new d1384(), "process", 1<<26).start();
}
catch(Exception e){
System.out.println(e);
}
}
public void run() {
FastReader scan = new FastReader();
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
//PrintWriter out = new PrintWriter("file.out");
Task solver = new Task();
int t = scan.nextInt();
//int t = 1;
for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
out.close();
}
static class Task {
static final int inf = Integer.MAX_VALUE;
public void solve(int testNumber, FastReader sc, PrintWriter out) {
int N = sc.nextInt();
long[] arr = new long[N];
for(int i = 0; i < N; i++) {
arr[i] = sc.nextLong();
}
for(int i = 30; i >= 0; i--) {
long count = 0;
for(int j = 0; j < N; j++) {
if((arr[j] & (1 << i)) == (1 << i)) {
count++;
arr[j] -= (1 << i);
}
}
if(count % 2 == 1) {
if(((count+1)/2) % 2 == 0 && (N - count) % 2 == 0) {
out.println("LOSE");
return;
} else {
out.println("WIN");
return;
}
}
}
out.println("DRAW");
}
}
static long binpow(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 void sort(int[] x){
shuffle(x);
Arrays.sort(x);
}
static void sort(long[] x){
shuffle(x);
Arrays.sort(x);
}
static class tup implements Comparable<tup>, Comparator<tup>{
int a, b;
tup(int a,int b){
this.a=a;
this.b=b;
}
public tup() {
}
@Override
public int compareTo(tup o){
return Integer.compare(b,o.b);
}
@Override
public int compare(tup o1, tup o2) {
return Integer.compare(o1.b, o2.b);
}
@Override
public int hashCode() {
return Objects.hash(a, b);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
tup other = (tup) obj;
return a==other.a && b==other.b;
}
@Override
public String toString() {
return a + " " + b;
}
}
static void shuffle(int[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
int temp = a[i];
a[i] = a[r];
a[r] = temp;
}
}
static void shuffle(long[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
long temp = a[i];
a[i] = a[r];
a[r] = temp;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws FileNotFoundException {
br = new BufferedReader(new FileReader(new File(s)));
}
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\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | a2148d9724eec5a9f6facb8886c71129 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class D {
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 FastReader s = new FastReader();
static PrintWriter out = new PrintWriter(System.out);
private static int[] rai(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = s.nextInt();
}
return arr;
}
private static int[][] rai(int n, int m) {
int[][] arr = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = s.nextInt();
}
}
return arr;
}
private static long[] ral(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = s.nextLong();
}
return arr;
}
private static long[][] ral(int n, int m) {
long[][] arr = new long[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = s.nextLong();
}
}
return arr;
}
private static int ri() {
return s.nextInt();
}
private static long rl() {
return s.nextLong();
}
private static String rs() {
return s.next();
}
static int gcd(int a,int b)
{
if(b==0)
{
return a;
}
return gcd(b,a%b);
}
static boolean isPrime(int n) {
//check if n is a multiple of 2
if (n % 2 == 0) return false;
//if not, then just check the odds
for (int i = 3; i <= Math.sqrt(n); i += 2) {
if (n % i == 0)
return false;
}
return true;
}
public static void main(String[] args) {
StringBuilder ans = new StringBuilder();
int t = ri();
// int t=1;
while (t-- > 0) {
int n=ri();
int[] arr=rai(n);
int[] count=new int[33];
for(int i:arr)
{
for(int j=0;j<=32;j++)
{
if((i&(1L<<j))==(1L<<j))
{
count[j]++;
}
}
}
int val=-1;
for(int i=32;i>=0;i--)
{
if(count[i]%2==1)
{
val=i;
break;
}
}
if(val==-1)
{
ans.append("DRAW\n");
continue;
}
int left=n-count[val];
count[val]%=4;
if(count[val]==1)
{
ans.append("WIN\n");
}
else {
if(left%2==0)
{
ans.append("LOSE\n");
}
else {
ans.append("WIN\n");
}
}
}
out.print(ans.toString());
out.flush();
}
}
| Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | 0891043cc6aafaaec0ac145d22d564aa | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.util.*;
import java.io.*;
public class CFA {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
private static final long MOD = 1000L * 1000L * 1000L + 7;
private static final int[] dx = {0, -1, 0, 1};
private static final int[] dy = {1, 0, -1, 0};
private static final String yes = "Yes";
private static final String no = "No";
void solve() throws IOException {
int T = nextInt();
for (int i = 0; i < T; i++) {
helper();
}
}
void helper() throws IOException {
int n = nextInt();
int[] arr = nextIntArr(n);
int sum = 0;
for (int v : arr) {
sum = sum ^ v;
}
if (sum == 0) {
outln("DRAW");
return;
}
int ones = -1;
for (int i = 31; i >= 0; i--) {
int cnt = 0;
for (int v : arr) {
if ((v & (1L << i)) != 0) {
cnt++;
}
}
if (cnt % 2 == 1) {
ones = cnt;
break;
}
}
int zeros = n - ones;
if (ones % 4 == 3 && zeros % 2 == 0) {
outln("LOSE");
} else {
outln("WIN");
}
}
void shuffle(long[] a) {
int n = a.length;
for(int i = 0; i < n; i++) {
int r = i + (int) (Math.random() * (n - i));
long tmp = a[i];
a[i] = a[r];
a[r] = tmp;
}
}
long gcd(long a, long b) {
while(a != 0 && b != 0) {
long c = b;
b = a % b;
a = c;
}
return a + b;
}
private void outln(Object o) {
out.println(o);
}
private void out(Object o) {
out.print(o);
}
private void formatPrint(double val) {
outln(String.format("%.9f%n", val));
}
public CFA() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
public static void main(String[] args) throws IOException {
new CFA();
}
public long[] nextLongArr(int n) throws IOException{
long[] res = new long[n];
for(int i = 0; i < n; i++)
res[i] = nextLong();
return res;
}
public int[] nextIntArr(int n) throws IOException {
int[] res = new int[n];
for(int i = 0; i < n; i++)
res[i] = nextInt();
return res;
}
public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return null;
}
}
return st.nextToken();
}
public String nextString() {
try {
return br.readLine();
} catch (IOException e) {
eof = true;
return null;
}
}
public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
public double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
} | Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | 1ae01c29f18c7313aac2d29be86ca14a | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | // No sorceries shall prevail. //
import java.util.*;
import java.io.*;
public class InVoker {
//Variables
static long mod = 1000000007;
static long mod2 = 998244353;
static FastReader inp= new FastReader();
static PrintWriter out= new PrintWriter(System.out);
public static void main(String args[]) {
InVoker g=new InVoker();
g.main();
out.close();
}
//Main
void main() {
int t=inp.nextInt();
loop:
while(t-->0) {
int n=inp.nextInt();
long a[]=new long[n];
input(a,n);
int bit[][]=new int[n][32];
for(int i=0;i<n;i++) {
long x=a[i];
int c=0;
while(x>0) {
bit[i][c++]=(int)x%2;
x/=2;
}
}
for(int j=31;j>=0;j--) {
int ones=0;
for(int i=0;i<n;i++) {
if(bit[i][j]==1) {
ones++;
}
}
if(ones%2==1) {
int zeros=n-ones;
out.println(zeros%2==0 && ones%4==3?"LOSE":"WIN");
continue loop;
}
}
out.println("DRAW");
}
}
/*********************************************************************************************************************************************************************************************************
* ti;. .:,:i: :,;;itt;. fDDEDDEEEEEEKEEEEEKEEEEEEEEEEEEEEEEE###WKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWW#WWWWWKKKKKEE :,:. f::::. .,ijLGDDDDDDDEEEEEEE*
*ti;. .:,:i: .:,;itt;: GLDEEGEEEEEEEEEEEEEEEEEEDEEEEEEEEEEE#W#WEKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWKKKKKKG. .::. f:,...,ijLGDDDDDDDDEEEEEE *
*ti;. .:,:i: :,;;iti, :fDDEEEEEEEEEEEEEEEKEEEEDEEEEEEEEEEEW##WEEEKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWWKKKKKKEG .::. .f,::,ijLGDDDDDDDDEEEEEE *
*ti;. .:,:i: .,,;iti;. LDDEEEEEEEEEEKEEEEWEEEDDEEEEEEEEEEE#WWWEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWKKKKKEDj .::. .:L;;ijfGDDDDDDDDDEEEEE *
*ti;. .:,:i: .:,;;iii:LLDEEEEEEEEEEEKEEEEEEEEDEEEEEEEEEEEW#WWEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKWWKWWWWWWWWWWWWWWKKKKKKKEL .::. .:;LijLGGDDDDDDDDEEEEE *
*ti;. .:,:;: :,;;ittfDEEEEEEEEEEEEEEEEKEEEGEEEEEEEEEEEKWWWEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWKKKKKKKELj .::. :,;jffGGDDDDDDDDDEEEE *
*ti;. .:,:i: .,;;tGGDEEEEEEEEEEEKEEEKEEEDEEEEEEEEEEEEWWWEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWKWWWWWWKKKKKKKEEL .::. .:;itDGGDDDDDDDDDEEEE *
*ti;. .:::;: :;ifDEEEEEEEEEEEEKEEEKEEEEEEEEEEEEEEEWWWEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WWWKKKKKKKKEEf .::. :,itfGEDDDDDDDDDDDEE *
*ti;. .:::;: :GGEEEEEEEEEEEKEKEEKEEEEEEEEEEEEEEEEWWEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKKKKEEDG .::. .,;jfLGKDLDDDDDDEEDD *
*ti;. .:::;: fDEEEEEEKKKKKKKKKEKEEEEEEEEEEEEEEE#WEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#KKKKKKKKKKEEf .:::. .,;tfLGDEDDDDDDDDEEE *
*ti;. :::;: fDEEEEEEKKKKKKKKKKWKEEEEEEEEEEEEEEEWKEEEEEEEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKW##KKKKKKKKKEEft :::. .,;tfLGDDDKDDDDDDDDD *
*ti;. .::;: fDEEEEEEKKKKKKKWKKKKKEEEEEEEEEEEEE#WEEWEEEEEDEEDEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKKKEEGG :,:. .,;tfLGGDDDKDDDDDDDD *
*ti;. .:.;: tGDEEEEKKKKKKKKKKKKKKKKKEEEEEEEEEEEWEEKWEEEEEEEDEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWKKKKKKKEEDf :::. .,;tfLGGDDDDEDDDDDDD *
*ti;. .::;: fDEEEEEKKKKKKKKKKKWKKKKKKKKEEEEEEEWWEEWEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKW##KKKKKKKEEEft.::. .,;tfLGGDDDDDDEDDDDD *
*ti;. .:.;: tGDEEEKKKKKKKKKKKKKKKKKKKKKKEKEEEEE#EEWWEEEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKEEEGD:::. .,;tfLGGDDDDDDDEDDDD *
*ti;. .:.,. LDEEEEKKKKKKKKKKWKWKKKKKKKKKKKKEEEKWEKW#EEEEEEEEEEEEEEEEKEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKW##KKKKKKEEEEf,,:. .,;tfLGGDDDDDDDDEDDD *
*ti;. ..:.,. LGDEEEEKKKKKKKKKKWKKKKKKKKKKKKKKKKKWEEW#WEEEEEEEEEEEEEEEKEEEEEEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKK##KKKKKEEEEEfi;,. .,;tfLGGDDDDDDDDDKDD *
*tt;. .:.,: jDEEEEKKKKKKKKKKWWKKKKKKKKKKKKKKKKKWKE#WWEEEEEEEEEEEEEEWEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKWWKKKKEEEEDfG;,: .,;tfLGGDDDDDDDDDDKD *
*tii,. .:.,. tGDEEEEKKKKKKKKKKWWWKKKKKKKKKKKKKKKWKKWWWKEEEEEEEEEEEEEKEEEEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKW#KKKKEEEEDGGi;,. .,;tfLGGDDDDDDDDDDDE *
*ti;;,:. .:.,: fDEEEEKKKKKKKKKKKWKKKKKKKKKKKKKKKKKWEK#WWKEEEEEEEEEEEEDEEEEEEEEEEEEEEGEEEEEEEEEEEEEEEEEEEKKKKKKKWWKKEEEEEEDDf;;;,. .,;tfLGGDDDDDDDDDDDD *
*tii;,,:.. ...,. ;LEEEEEKKKKKKWKKKKWKKKKKKKKKKKKKKKKKEKKW#WEEEEEEEEEEEEEjEEEEEEEEEKEEEEGEEEEEEEEEKEEEEEEEEEEEEEEEEE#WKEEEEEEDDf;;;;,: .,itfLGGDDDDDDDDDDDD *
*ti;,,,,,:. ...,. LDEEEEKKKKKKKKKKKWWWKKKKKKKKKKKKKKKWKK#W#WEEEEEEEEEEEDDLEEEEEEEEEWEEEEDEEEEEEEEEKEEEEEEEEEEEEEEEEEWWEEEEEEEDDfj,,,,,:. .,itfGGGDDDDDDDDDDDD *
*tii,,,,::::. ...,: .fDEEEEKKKKKKWKKKKWWWKKKKKKKKKKKKKKKEKKW#WWEEEEEEEEEEEKiKEEKEEEEEEWEEEEDEEEEEEEEEEEEEEEEEEEEEEEEEEEWWEEEEEEEDDLD:::,,,:. .,ijfGGGDDDDDDDDDDDD *
*ti;:::::::::.. .:.,: LDEEEEKKKKKKKWKKKKWWKKKKKKKKKKKKKKKKtKKWWWWKEEEEEEEEEDiiDEEEEEEEEWWEEEEEEDEEEEEEEEEEEEEEEEEEEEEEEEEEWKEEEEEDDDGL:. .:,,,: .,ijLGGGDDDDDDDDDDDD *
*tt;. .::::::::.. ...,: :fDEEEKKKKKKKKKKKKWW#KKKKKKKKKKKKKKKKfKKWWWWKEEEEEEEEDti,DEKEEEEEEWWEEEDEEEEEEEEEKEEEEEEEEEEEEEDEEEEE#WEEEEEGGDGf:. .:,;,:. .,ijLGGDDDDDDDDDDDDD *
*tt;. .:::::::.. ...,: GDEEEKKKKKKKKWKKKKWWWKKKWKKKKKKKWWWKDEKLWWWWKKEEEEEEDEi,LDEEEEEEEEWWEEEEEEEEEEEEEEEEEEEEEEEEEDEDEEEEEW#EEEEDDDDGf,. :,,,:...,ijLGGGDDDDDDDDDDDD *
*tt;. .....::::.. ...,: fDEEEKKKKKKKKWKKKKWWWWKKKWKKKKKKKKKKfWKiWWW#KKEEEEEEEi;.EDfEEEDEEiWWEEEEEEEEEEEEDGKEEEEEEEEEEDEEEEEEEWWEEEEDDDGGLi. .,;,:::,ijLGGGDDDDDDDDDDDD *
*tt;. ....:::::. ...,. iDEEEEKKKKKKKKWKKWKWWWWWKKWWWKKKKKKKKtWKt#WWWKKEEEEEDji..DDKDDEDEGiWKEEEEEEEEEEDDEjEEEEEEEEEEEDEEEEEEEKWKEEDDDDGGff. .:,;,,;ijLGGGDDDDDDDDDDDD *
*tt;. ....::::.. .:.,: .LDEEEKKKKKKKKKKKKWWWWKWWWWWWWWWWKKKKWtKKiDWWWKKKEEEEKi:..DEDDDDDDiiWKEEEEEEEEEEDDEijDEEEEEKEEEEEEEEEEEEWWEEGDDDGGLG. .:,;;iijLGGGDDDDDDDDDDDD *
*tt;. .....:::.. ...,. .fEEEEKKKKKKKKWKKKKWWWWWWWWWWWWWWKWKKKiKDiLWWWWKEEEEEi,..fD:DDDDDti;WEEEEEEEEEEKDDi:iDDEEEEWEEEEEEEEEEEE#WEEGDDDDGGG. :,iitjLGGGDDDDDDDDDDDD *
*tti. .....:::.. ...,. GDEEEKKKKKKKKKWKKKWWW#WWWWWWWWWWWKWKKjiEjitWWWKKWEEEDi...DDLDDDDji;;WEEEEEEEEEEEDEj.iDDEEEEWEEEEEEEEEEEEWWEEDDDDDDGf. .,;tjfLGGDDDDDDDDDDDD *
*tti. ....::::.. ...,. fEEEKKKKKKKKKKKKKKKW#WWWWWWWWWWWWWWWWtiEiiiWWWKKEWKEi....D.EDDDEi;.fWEEEEEEEEEEDDfL.;EDDEEEWEEEEEEEEEEEEWWEEEDDDDDGf. :;ijfLGGDDDDDDDDDDDD *
*tti. ....::::.. ...,. LDEEEKKKKKKKKKKKKKKWWWWWWWWWWWWWWWW####WKiiiWWWKKKEEK,...:E:DDDEii..GWEEEEEEEEDWDDiL.,KDDEEEWEEEEEEEEEEEEWWKEEDDDDDGf: .,itfLGGDDDDDDDDDDDD *
*tti. .....:::.. ...,. fDEEEKKKKKKKKKWKKKKWWWWWWWWWWWWW########WLiiWWWKKKEEjD...G,DDDDi;...EWEEEEEEEEDKDEii..LDDEEEWEEEEEEEEEEEEWWWEEDDDDDGfi .,;tfLGGGDDDDDDDDDDD *
*tti. .....:::.. ...,. iGEEEKKKKKKKKKKWKKKKWWWWWWWWWWWW###########KiWWWKKEEE,.D..D.DDDii:...KKEEEEEEEEEDDj:...tEDEEEWEEEEEEEEEEEEWWWEEEDDDDDLL .,;tjLLGGDDDDDDDDDDD *
*tti. ....::::......:. LEEEKKKKKKKKKKWWKKKWWW#KWWWWWWWW#####W####W##KWWKKEEL..:D.jjDDi;,....KKEEEEEEEDfDDi...:iKDEEEWKEEEEEEEEEEEWWWEEEEDDDDLG .,;tjLLGGDDDDDDDDDDD *
*tti. ...::::::..,. :GEEEKKKKKKKKKKKKWWWWW##WWWWWWWWW##WKWK#W#W####WWKEEK.....G.DDti,.....KKEEEEEEDWGDf.,...iKDEEEWWEEEEEEEEEEEW#WEEEEEDDDGL .,;tjLLGGDDDDDDDDDDD *
*tti. ....::::::,. GDEEKKKKKKKKKKKKKWWWW###WWWWWWWWWW#WWWK###W#####WKEKK.....jDDL;;......KKEEEEEEEEEDi.f...;KDEEEWWEEEEEEEEEEEWWWWEEEEEDDGf .,;tjLLGGDDDDDDDDDDD *
*tti. ....:::,,. .LEEEKKKKKWKKKKKWWWWWW###WWWWWWWWWW#WWKW#WW##W#WWWKEKD:....:DD:;......;KEEEEEEEKiDD..f...,KKEEEWWEEEEEEEEEEEWWWWEEEEEDDDf .:;tjLLGGGDDDDDDDDDD *
*tti. ...::,,,:. GDEEKKKKKKKKKKKKWWWWWWW#WWWWWWWWWWW#KjKWWWWWWWWWWWWEK.j,..;fD.;.......fKEEEEEDKG:Di..,....DKEEEWWEEEEEEKEKKKWWWWEEEEEEDDf .:;tjLLGGDDDDDDDDDDD *
*jti. ...::,,,,:. .fEEEKKKKKWKKKKKKWWWWWWW#WWWWWWWWWWK#KKKWWWWWWWWWWWWWK..f:.:G.,:.......EKEEEEEKK;:E:.......fKEEEWWKEKEKKKKKKKW#WWEEEEEEDDf: .,;tfLLGGDDDDDDDDDDD *
*tti. ...:,,,;;,: iDEEKKKKKWKKKKKKKWWWWWWW#WWWWWWWWWWK#WDKWWKKWWWWWWWWWE..;G:G..,........KKEEEEEKi.Gi..:.....tKEEKWWWKKKKKKKKKKW##WKEEEEEEDfi .,;tfLLGGGDDDDDDDDDD *
*tti. ....::,,;;;,LEEKKKKKKWKKKKKWWWWWWW###WWWWWWWWWWKWWDKWEEEWKKWWWWWKKj.:LG..;.........EKEEEEKG;.G...;.....;KKEKWWWKKKKKKKKKKW##WWKEEEEEDfL .,;tfLGGGDDDDDDDDDDD *
*jti. ...::::,;ijDEEKKKKKWKKKKKKWKWWWWW##WWWWWWWWWWWKK#KKGDGDWEEWKKWKKGE,.i;.:.........:EKEEEKE;.:L...j.....,KWEKWWWKKKKKKKKKK####WKKEEEEDLG .,;tfLGGGGDDDDDDDDDD *
*jti. ...:...,,;GEEKKKKKWWKKKKKWWWWWWWW###WWWWWWWWWKKKWWKiLGGEDEDEKGKKiEG..;...........jKEEEKK;:.G....,.....:KKEWWWWKKKKKKKWKK####WKKKKEEEGL .,;tfLGGGGDDDDDDDDDD *
*jti. ...:. .:,GEEKKKKKWKKKKKWWWWWWWW####WWWWWWWWWKKKWWKii;fDLGDK: EEi:E:.............EKEEKK;;..L...........KKKWWWWKKKKKKKWKK####WKKKWKEEDf .,;tfGGGGDDDDDDDDDDD *
*jti. ...:. ,EEKKKKKWWKKKKKWWWWWWWWW###WWWWWWWWKKKKfWWLt;i,. fi EG..D:.............EKEKK;;..t....:.......KWKWWWWKKKKKKKWKK####WKKKWEEEDf:. .,;tfGGGGDDDDDDDDDDD *
*jti. ...:. GEEKKKKKWKKKKKWWWWWWWWW####WWWWWWWKKKKKt;KKEfff .;t.................KKKKi;:..GtGGfG.......KWWWWWWKKKKKKKWKK###WWWKKKKEEEf,,: .,;tfGGGGDDDDDDDDDDD *
*jti. ...:. GEKKKKKWWKKKKKWWWWWWWWWW##WWWWWWWKKKKKKt;EiKKKK, ...t................jEKKG;;..,.....,LGi....KWWWWWWKKKKKKWKKKW####WKKKKKEEL,,,:. .,;tfGGGDDDDDDDDDDDD *
*jti. ...:. .GEEKKKKKWKKKKKWWWWWWWWWW###WWWWWWWKKKKKKtiE::tGG........................EEEj;;...,.........:D..DKWWWWWWKKKKK#KKW###W#WKKKKKEEfj:,,,:. .,;tfGGGDDDDDDDDDDDD *
*jti. ...:. DEKKKKKWWKKKKKWWWWWWWWW####WWWWWWWKKKKKKiiE:::.::.......................EEi;;...j.....f......:iDKWWWWWWKKKKK#WW######WKKKKKEELG :,,,,:. .,;tfGGGDDDDDDDDDDDD *
*jti. ...:. fEEKKKKWWKKKKWWWWWWWWWWW###WWWWWWWWKKKKKK;tE::..........................DD;.;,.::......;........EWWWWWWWKKKKW#WW#####WWKKKWKKELG .:,,,:::,;tfGGGDDDDDDDDDDDD *
*jti. ...:. .DEKEKKKWWKKKKWWWWWWWWWWW###WWWWWWWWKKKKKE,iD::..........................D..,;.,;tLffi...........DWDWWWW#KKKWWWWW#####W#KKKWKEEGL .:,;,,,;tfGGGDDDDDDDDDDDD *
*jti. ...:. ;EEKKKKWWKKKKKWWWWWW#WWWW####WWWWWWKKKKKEL:iD:..........................j ..;..;;:.....i,........DKtWWWWWKKWWWWWW#####WWWKKKEKEDf .:,;;;itfGGGDDDDDDDDDDDD *
*jti. ...:. DEKKKKKWWKKKKWWWWWWW#WWWW####WWWWWWKKKKKEj:iG...............................:....................GKiWWWWWKKWW#WWW######WWKKKKKEEf .,;iitfGGGDDDDDDDDDDDD *
*jti. ...:.:EKKKKKWWKKKKKWWWWWWW#WWW#####WWWWWKWKKKKEi:if:.................................iEKEKKKKKKDj......DKiWWWWWKWK##WW#######WWKKK:KEEL .:;itfGGGDDDDDDDDDDDD *
*jji. ...:,DEEKKKWWWKWKKWWWWWWWWWWWW#####WWWWWWWKKKKEi:it..................................j. KKKKKKKKKKKf..DKiWWWWWKWW##WW#######WWKKK,KEEf .,;tfGGGDDDDDDDDDDDD *
*jji. ..L:iDEEKKKWWKKKKKWWWWWWWWWWWW#####WWWWWKWKKKKKi.i;.................................. . KKKWWWWWWWWK..DGiWWWWWKK##WWW#####W#WWKKKjEKEL, .:;tfGGGDDDDDDDDDDDD *
*jji. .f:::EEEKKKWWWKKKKKWWWWWWWWWWWW#####WWWWWKWKKKKK;.i,.................................:: KKEKWWWWWWfWK..EiiWWWWWKWW#WW##########KKKD,KELj .:;tfGGDDDDDDDDDDDDD *
*jji. .t::::,DEEKKKWWKKKKWWWWWWWWW#WWWW#####WWWWKKWKKKEK;.i:.................................GDDEEEKKKWWWWWtWWD.E;iWWWWWW###WW#########WWKKK.EEDG .:;tfGGGDDDDDDDDDDDD *
*jji. . j..::::EKEKKKWWWKKKKWWWWWWWWW#WWW######WWWWKKWKKKEK;.t:.................................ELLEDDEEEWWWWEtWK,.KiiWWWWWW###W##########WWKKK:EEEG .;tjfLLGDDDDDDDDDDDDDDD *
*jji. i.::::::,EEEKKWWWKKKKKWWWWWWWWW#WWW#####WWWWWKWKKKKEE,.t..................................DfiEGDDDEEKKKttKWG.KiiWWWWW##WWW##########WWKKK:fEEL ,fGGGDDDDDDDDEEEDDDDDDDDDD *
*jji. .;:..:::::DEEEKKWWWKKKKKWWWWWWWWW#WWWW####WWWWWWWKKKKED,.t..................................ifjDDGGEGDKK.ttKKE.DiWWWWW###WW##########WWWKKK:.KELiLGGGGDDDDDDDDDDDDEEEDDDDDDD *
*jji. i.:.::::::,KEEKKWWWKKKKKKWWWWWWWWW#WWWW####WWWWWWWKKKKEL:.j..................................GGf,;ifLLED .iiKKi:fWWWWWW##W#W##########WWWKKK:.KKLGGDDDDDDDDDDDDDDDDEDDEEDDDDD *
*jji. .j:.::::::::EEEKKKWWWKKKKKKWWWWWWWW##WWW#####WWWWWWWKKKKKf:.f..................................:EEfftf .,. ;iE,..jWWWWWWW###W############WWKKK,:KKGDDDDDDDDDDDDDDDDDDDDDDDEDDDD *
*jji. .:.::::::::,,EEEKKWWWKKKKKKKWWWWWWWW##WWW#####WWWWWWWKKKKKt..G....................................EEELL; .j....tKWWWWWWW################WWWKKtfGKGEDDDDDDDDDDDDDDDDDDDDDDDEEDD *
*jji. :...:::::::,,jEEKKWWWWKKKKKKWWWWWWWWW##KWW#####KWWWWWWKKKKEi..D....................................:jEEE.........;KKWWWWWWWW#WW##W##########WWKKDLGKEKDDDDDDDDDDDDDDDDDDDDDDDDDED *
*jji. i:.::::::::,,,EEEKKWWWWKKKKKWWWWWWWWWW##WWW#####WWWWWWWKKKKKi..D......................................:::::......,KKKWWWWWWWWW#####W########WWWKKKGGKKEGGGGGGGGDDDDDDDDDDDDDDDDDDE *
*jji. i..:::::::::,,tEEKKWWWWKKKKKWWWWWWWWWWW##WW######WWWWWWWKKKKKi..D......................................::::......:EKKKWWWWWWWWWWW##WW########W#WKKWGGKKGGGGGGGGGGGGGGGDDDDDDDDDDDDD *
*jji. .:::::::::::,,,EEEKKWWWWKKKKKWWWWWWWWWWW##WW#####WWWWWWWWKKKKKi..D....................................:::::::::..tELii;KWWWWWWWWWW##WW######WWWWWWKWGGGKGGGGGGGGGGGGGGGGGGGGGGGGGGDG *
*jjt. :.::::::::,,,,fEEKKWWWWKKKKKKWWWWWWWWWW###WW####WWWWWWW#WKKKKKi..D....................................:::::::.:.,;;;;;;,KKWWWWWWWWW#WW########WWWKKWGGGKGGGGGGGGGGGGGGGGGGGGGGGGGGGG *
*jji. ;.::::::::,,,,;EEEKWWWWWKKKKKWWWWWWWWWWWW##WW###WKWWWWWK#WKKKKKi..G......................................:::::::,;;;;:...KKKWWWWWWWWWKWW#######WWWWKKGLGKDGGGGGGLLGGGGGGGGGGGGGGGGGGG *
*jjt. f.:::::::::,,,,fEEKKWWWWWKKKKKWWWWWWWWWWW###WW##WKKWWWWWW#WKKKKK;.jt........i.............................:::::::;j;;....:E.KKKWWWWWWWKWW#####W#WWWWKKLLGWEEGGGGGLGGGGGGGGGGGGGGGGGGGG *
*jjt. ...:::::::,,,,,;DEEKWWWWWKKKKKWWWWWWWWWWWW####WWWKKKWWWWWWWWKKKKK;.E;.........t.............................:::::ii;;.....D...KKWWWWWWWKWW#####WWEWWWKKGGGEKKGGGGGLGGGGGGGGGGGGGLGGGGGG *
*fji. ;.:::::::,,,,,;LEEKKWWWWWKKKKKWWWWWWWWWWWW####KWKKKKWWWWWWWWKKKKKi.D;..........j.............................:::tt;,.....:.....KKWWWWWWKWWWW##WWWGWWWKKGGGGKEGGGGGGGGGGGGGGGGGGGLLGGGGL *
*fji. t::::::::,,,,,,;EEEKWWWWWKKKKKKKWWWWWWWWWWW##WKWKKKKKWWWWWWWWKKKKKi:D;............j...........................::LL;,.............KKWWWWWKWWWWWWWWWGWWWKKGGGGKGGGGGGGGGGGGGGGGGGGGLLGGGGL *
*fjt: .:::::::,,,,,,,DEEKWWWWWWKKKKKKKWWWWWWWWWWWWKKWKKKKKKWWWWK#WWKKKKWitE;........... ............................:G;;:...............KKKWWKKWWWWWWWWWGWWWKKGGGGWGGGGGGGGGGGGGGGGGGGGGGGGGGL *
*fjji;:. .f:::::::,,,,,,,;EEEKWWWWWWKKKKKKWWWWWWWWWWWKKKKKKKKKKKWWKWWWWWKKKKWGKD;........................................L;;..................DKKWKKWWWWWWWWWGWWWKKDGGGKDGGGGGGGGGGGGGGGGGGGGGGGGGG *
*fjjtii;,:. :::::::,,,,,,,;EEEKWWWWWWKKKKKKWWWWWWWWWWKKKKKKKKKKKKWWWWWW#WWKKKKWiEj;......................................:i,;....,...............;KKEKWWWWWWWWWGKWWKKDDGGDEGGGDGGGGGDGGGGGGGGGGGGGGGG *
*fjtiiiii;;:. j::::::,,,,,,,;;EEEKWWWWW#KKKKKWWWWWWWWWKKKKKKWKKKKKKKWWWWWWWWWKKKKWtEL;:....................................;;;:...,;j................:KEEWWWWWWWWWDDWWKKDDDDDKDDDDDDDDDDDDDDDGGGGGGGGGGG *
*fjti;;iiii;;,:::::::,,,,,,,,;EEEKWWWWWWWKKKKWWWWWWWWKKKKKKKWKKKKKKKWWWWWWW#W#KKKKWEEii;...................................f;:....,;L...................EEKWWWWWWWWDDWWKKDDDDDKEDDDDDDDDDDDDDDDDDDDDDGGGG *
*fjt,,,;;;;ii;f::::::,,,,,,,;;EEKWWWWWWWKKKKKWWWKWWKKKKKKKKKKKKKKKKKWWWWWWW#W#KKKKWKEij;:...............................:G;,.....,;f....................:tKKWWWWWWWDDWWKKDDDDDKKDDDDDDDDDDDDDDDDDDDDDDDDD *
*jjt. ..:,;;;;,::::,,,,,,,,;;GEEWWWWWWWWKKKKWKKWKKKKKKKKKKKKKKKKKKKKWWWWWWW#W#KKKKWEDi;j;............................,Li;L;;;..,;;f........................KKKKWWWKDDWWKKDDDGDKKGGGGGGGGDGDDDDDDDDDDDDDDD *
*fjt. .:,,,:::::,,,,,,,;;;EEKWWWWWWWKKKKKKWKKKKKKKKKKKKKKKKKKKKKWKKKWKW##W#KKKKWEti;;G;........................tEEEL;;;;;;;;;;L..........................DKKKKKEDDWWKEDGftiLE;;;;itjLGGGGGGDDDDDDDDDDD *
*fjt. .j::::,,,,,,,;;;DEEWWWWWWWWKKKKWKKKKKKKKKKKKKKKKKKKKKKKWKKWWWK##W#KKKKKEii;;;L;...................iDEEEEEEKKi;j;;;;jD.....:......................,KKKKDGGEKKE:::::;E::::::::::,tLGGDDDDDDDDDD *
*fjt. .;:::,,,,,,,;;;;EEKWWWWWWWWKWKKKKKKKKKKKKKKKWKKKKKKKKKKWKKWWWW#WW#KKKKKKii;;;;f;.............:tDEEEEEKKKKKKKKEti;;;L...............................EEKf;:iKKE::::::E::::::::::::::ifDDDDDDDDD *
*fjt: :::,,,,,,,,;;;DEEWWWWWWWWWEKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKWWWW####KKKKKEiii;;;;f,.........iDEEEEKKKKKKKKKKKKKKKf;iG......i..........................fK::::KKE::::::E::::::::::::::::,tGGDDDDD *
*fjt: t:::,,,,,,;;;;iDEKWWWWWWKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKWWWW####WKKKKLiii;;;;;L,....,Li;EDEEEEKKKKKKKKKKKKKKKKiG......;:...........................:i:::KKE:::::,E,::::::::::::::::::iGDDDD *
*jjt. f::,,,,,,,;;;;GEEWWWWKEEKEKKKKKKKKKKKKKKKKWKKKKKKKKKKKWWKWWWWW###WWKKKKiii;;;;;;;G,;L;;iiEEEEEEEKKKKKKKKKKKKKWWKE......;t.........:....................j::KEE:,::,,D,,::::,,,,,,:::::::::tDDD *
*fjt:. ,::,,,,,,,;;;;EEWWKEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKWWKKWWWWW#W#KKKKKKiiiiii;;;;;i;;iiiEEKEEKKWKKKKKKKWKKKKKWWWGi;...;t......,;;;;,....................:,EEE,,,,,,D,,,,,,,,,,,,,,,,::,::::tG *
*fjt:. ,::,,,,,,,;;;;DEKEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWW#W#KKKKKKiiiii;;i;;;;;iiiKKKEKKKKWWKWWWWWWKKKKWWWWW;;;:;L.....;;;;;;;;;....................,KEE,,,,,,E,,,,,,,,,,,,,,,,,,,,,,,,; *
*fjt:. f:,,,,,,,;;;;jEDEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWW#W##KKKKKKiiiiiiii;i;;iiiEKKKKKKKKWKWWWWWWWWKKKWWWWWKi;;i.....,jEEfGi;;;;;...................EED,,,,,,E,,,,,,,,,,,,,,,,,,,,,,,,, *
*fjt:. .f::,,,,,,;;jEEDEEEEEEEEEEKKKKKKKKKKKKKKKWKKKKKKKKKKKKKWWWKWWWWW###KKKKKLiiiiiiiiiiiiiiEEKKKKKKKKWWWWWWWWWWWWKWWWWWWGi;i;,..;jDDDKEGi;;;;;;:................EED,,,,,,D,,,,,,,,,,,,,,,,,,,,,,,,, *
*fjt:. .. ;::,,,,,;;EDDEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKW#WW####KWKKKiiiiiiiiiiiiijKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWt;i;;;;i;DDDDDDGi;;;;;;;;:.............EDf;,,,;,G;;;;;;;;;;;;;;;,,,,,,,,,, *
*fjt:......:,,,,,,;LDDDEEEEEEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKKKWWWWKWWWW####KKKKKiiiiiiiiiiijKEKKWKKKKKKKWWWWWWWWWWWWWWWWWWWWWWiLiii;i;DEEEEDDE;i;;;;;;;;;:..........EDi,;;;;;L;;;;;;;;;;;;;;;;;;,,,,,,, *
*fjt:......:,,,,,;EDDDEEKEEEEEEEEEKKKKKKKKKKKKKKKWKKKKKKKKKKKKKKWWWWKKWWW##W#KWKKWEiiiiiijGKKKKKWWKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWKi;iiiiDDEEEEEEDEi;;;;;;;;;;;;;,:.....ED;;;;;;;j;;;;;;;;;;;;;;;;;;;;;;;,, *
*fjt:.....t,,,,,;DDDDEEEKEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWKKKWWWW##WKWKKWKiiiKKKKKKKKKWWKKKKKKKKWWWWWWWWWWWWWWW#WWWWWWWWWiiiiifLEEEEEEEEDi;i;;;;;;;;;;;;.....DD;;;;;;;i;;;;;;;;;;;;;;;;;;;;;;;;; *
*fjt:.....G,,,,,GDDDEEEEEEEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKKKKKWWWKKKWWW###WKWKKWKitKKKKKKKKKWKKKKKKKKKKWWWWWWWWWWWWWW###WWWWWWWWEiiiiiiiEEEEEEEEDGiiii;;;;;;;;;.....GD;;;;;;;i;;;;;;;;;;;;;;;;;;;;;;;;; *
*fjt:.....L,,,,;GDDDEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWDGWWW###KKWWKWKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWW####WWWWWWWWWiiiiiiiiEEEEEEEEEEDi;i;;;;;;;;.....Lj;;;;;;i;iiiiii;;;;;;ii;;;;;;;;;;; *
***********************************************************************************************************************************************************************************************************/
// Classes
static class Edge implements Comparable<Edge>{
int l,r;
Edge(){}
Edge(int l,int r){
this.l=l;
this.r=r;
}
@Override
public int compareTo(Edge e) {
return (l-e.l)!=0?l-e.l:r-e.r;
}
}
static class Segment implements Comparable<Segment> {
long l, r, initialIndex;
Segment () {}
Segment (long l_, long r_, long d_) {
this.l = l_;
this.r = r_;
this.initialIndex = d_;
}
@Override
public int compareTo(Segment o) {
return (int)((l - o.l) !=0 ? l-o.l : initialIndex - o.initialIndex);
}
}
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 s="";
try {
s=br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return s;
}
}
// Functions
static long gcd(long a, long b) {
return b==0?a:gcd(b,a%b);
}
static int gcd(int a, int b) {
return b==0?a:gcd(b,a%b);
}
static void reverse(long[] A,int l,int r) {
int i=l,j=r-1;
while(i<j) {
long t=A[i];
A[i]=A[j];
A[j]=t;
i++;j--;
}
}
static void reverse(int[] A,int l,int r) {
int i=l,j=r-1;
while(i<j) {
int t=A[i];
A[i]=A[j];
A[j]=t;
i++;j--;
}
}
//Input Arrays
static void input(long a[], int n) {
for(int i=0;i<n;i++) {
a[i]=inp.nextLong();
}
}
static void input(int a[], int n) {
for(int i=0;i<n;i++) {
a[i]=inp.nextInt();
}
}
static void input(String s[],int n) {
for(int i=0;i<n;i++) {
s[i]=inp.next();
}
}
static void input(int a[][], int n, int m) {
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
a[i][j]=inp.nextInt();
}
}
}
static void input(long a[][], int n, int m) {
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
a[i][j]=inp.nextLong();
}
}
}
}
| Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | f78e07a2e7e90c55bfabfa89a18284cd | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
//class Declaration
static class pair implements Comparable < pair > {
int x;
int y;
pair(int i, int j) {
x = i;
y = j;
}
public int compareTo(pair p) {
if (this.x != p.x) {
return this.x - p.x;
} else {
return this.y - p.y;
}
}
public int hashCode() {
return (x + " " + y).hashCode();
}
public String toString() {
return x + " " + y;
}
public boolean equals(Object o) {
pair x = (pair) o;
return (x.x == this.x && x.y == this.y);
}
}
// int[] dx = {0,0,1,-1};
// int[] dy = {1,-1,0,0};
// int[] ddx = {0,0,1,-1,1,-1,1,-1};
// int[] ddy = {1,-1,0,0,1,-1,-1,1};
int inf = (int) 1e9 + 5;
long mod = (long)1e9 + 7 ;
void solve() throws Exception {
int T=ni();
while(T-->0){
int n=ni();
int[] arr= new int[n];
int xor = 0;
for(int i=0;i<n;++i){
arr[i]=ni();
xor^=arr[i];
}
if(xor==0){
pn("DRAW");
}
else{
int j = (int)Math.round(Math.log(Integer.highestOneBit(xor))/Math.log(2));
int one = 0;
int zero =0;
for(int i=0;i<n;++i){
if((arr[i]& (1<<j)) > 0){
one++;
}
else{
zero++;
}
}
if(one%4 == 1){
pn("WIN");
}
else{
if(zero%2==1){
pn("WIN");
}
else {
pn("LOSE");
}
}
}
}
}
long pow(long a, long b) {
long result = 1;
while (b > 0) {
if (b % 2 == 1) result = (result * a) % mod;
b /= 2;
a = (a * a) % mod;
}
return result;
}
void print(Object o) {
System.out.println(o);
System.out.flush();
}
long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
void run() throws Exception {
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms");
}
public static void main(String[] args) throws Exception {
new Main().run();
}
//output methods
private void pn(Object o) {
out.println(o);
}
private void p(Object o) {
out.print(o);
}
private ArrayList < ArrayList < Integer >> ng(int n, int e) {
ArrayList < ArrayList < Integer >> g = new ArrayList < > ();
for (int i = 0; i <= n; ++i) g.add(new ArrayList < > ());
for (int i = 0; i < e; ++i) {
int u = ni(), v = ni();
g.get(u).add(v);
g.get(v).add(u);
}
return g;
}
private ArrayList < ArrayList < pair >> nwg(int n, int e) {
ArrayList < ArrayList < pair >> g = new ArrayList < > ();
for (int i = 0; i <= n; ++i) g.add(new ArrayList < > ());
for (int i = 0; i < e; ++i) {
int u = ni(), v = ni(), w = ni();
g.get(u).add(new pair(w, v));
g.get(v).add(new pair(w, u));
}
return g;
}
//input methods
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b));
return b;
}
private double nd() {
return Double.parseDouble(ns());
}
private char nc() {
return (char) skip();
}
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m) {
char[][] map = new char[n][];
for (int i = 0; i < n; i++) map[i] = ns(m);
return map;
}
private int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = ni();
return a;
}
private int ni() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
private long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
private void tr(Object...o) {
if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
}
void watch(Object...a) throws Exception {
int i = 1;
print("watch starts :");
for (Object o: a) {
//print(o);
boolean notfound = true;
if (o.getClass().isArray()) {
String type = o.getClass().getName().toString();
//print("type is "+type);
switch (type) {
case "[I":
{
int[] test = (int[]) o;
print(i + " " + Arrays.toString(test));
break;
}
case "[[I":
{
int[][] obj = (int[][]) o;
print(i + " " + Arrays.deepToString(obj));
break;
}
case "[J":
{
long[] obj = (long[]) o;
print(i + " " + Arrays.toString(obj));
break;
}
case "[[J":
{
long[][] obj = (long[][]) o;
print(i + " " + Arrays.deepToString(obj));
break;
}
case "[D":
{
double[] obj = (double[]) o;
print(i + " " + Arrays.toString(obj));
break;
}
case "[[D":
{
double[][] obj = (double[][]) o;
print(i + " " + Arrays.deepToString(obj));
break;
}
case "[Ljava.lang.String":
{
String[] obj = (String[]) o;
print(i + " " + Arrays.toString(obj));
break;
}
case "[[Ljava.lang.String":
{
String[][] obj = (String[][]) o;
print(i + " " + Arrays.deepToString(obj));
break;
}
case "[C":
{
char[] obj = (char[]) o;
print(i + " " + Arrays.toString(obj));
break;
}
case "[[C":
{
char[][] obj = (char[][]) o;
print(i + " " + Arrays.deepToString(obj));
break;
}
default:
{
print(i + " type not identified");
break;
}
}
notfound = false;
}
if (o.getClass() == ArrayList.class) {
print(i + " al: " + o);
notfound = false;
}
if (o.getClass() == HashSet.class) {
print(i + " hs: " + o);
notfound = false;
}
if (o.getClass() == TreeSet.class) {
print(i + " ts: " + o);
notfound = false;
}
if (o.getClass() == TreeMap.class) {
print(i + " tm: " + o);
notfound = false;
}
if (o.getClass() == HashMap.class) {
print(i + " hm: " + o);
notfound = false;
}
if (o.getClass() == LinkedList.class) {
print(i + " ll: " + o);
notfound = false;
}
if (o.getClass() == PriorityQueue.class) {
print(i + " pq : " + o);
notfound = false;
}
if (o.getClass() == pair.class) {
print(i + " pq : " + o);
notfound = false;
}
if (notfound) {
print(i + " unknown: " + o);
}
i++;
}
print("watch ends ");
}
} | Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | e34cda88d7407c324e55bd8db055d0e9 | train_004.jsonl | 1595601300 | Koa the Koala and her best friend want to play a game.The game starts with an array $$$a$$$ of length $$$n$$$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $$$0$$$. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is $$$x$$$ and the chosen element is $$$y$$$, his new score will be $$$x \oplus y$$$. Here $$$\oplus$$$ denotes bitwise XOR operation. Note that after a move element $$$y$$$ is removed from $$$a$$$. The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.If both players play optimally find out whether Koa will win, lose or draw the game. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class cdf659d
{
static void merge(int arr[], int l, int m, int r)
{
int n1 = m - l + 1;
int n2 = r - m;
int L[] = new int [n1];
int R[] = new int [n2];
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
int i = 0, j = 0;
int k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
static void sort(int arr[], int l, int r)
{
if (l < r)
{
int m = (l+r)/2;
sort(arr, l, m);
sort(arr , m+1, r);
merge(arr, l, m, r);
}
}
public static int lowerBound(int[] array, int length, int value)
{
int low = 0;
int high = length;
while (low < high)
{
final int mid = (low + high) / 2;
//checks if the value is less than middle element of the array
if (value <= array[mid])
{
high = mid;
}
else
{
low = mid + 1;
}
}
return low;
}
public static int upperBound(int[] array, int length, int value)
{
int low = 0;
int high = length;
while (low < high) {
final int mid = (low + high) / 2;
if (value >= array[mid]) {
low = mid + 1;
} else {
high = mid;
}
}
return low;
}
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static long power(long n,long m)
{
if(m==0)
return 1;
long ans=1;
while(m>0)
{
ans=ans*n;
m--;
}
return ans;
}
static int BinarySearch(int arr[], int x)
{
int l = 0, r = arr.length - 1;
while (l <= r) {
int m = l + (r - l) / 2;
if (arr[m] == x)
return m;
if (arr[m] < x)
l = m + 1;
else
r = m - 1;
}
return -1;
}
public static void main(String args[])throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
outer:for(int i=1;i<=t;i++)
{
int n=Integer.parseInt(br.readLine());
int ar[]=new int[33];
String s=br.readLine();
String str[]=s.split(" ");
for(int j=0;j<n;j++)
{
int temp=Integer.parseInt(str[j]);
int k=32;
while(temp>=1)
{
if(temp%2==1)
ar[k]++;
k--;
temp/=2;
}
}
// for(int j=0;j<=32;j++)
// System.out.print(ar[j]+" ");
// System.out.println(n);
for(int j=0;j<=32;j++)
{
if(ar[j]%2==0)
continue;
if(ar[j]%4==3&&n%2==1)
{
System.out.println("LOSE");
continue outer;
}
else
{
System.out.println("WIN");
continue outer;
}
}
System.out.println("DRAW");
}
}
}
| Java | ["3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2", "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4"] | 1 second | ["WIN\nLOSE\nDRAW", "WIN\nWIN\nDRAW\nWIN"] | NoteIn testcase $$$1$$$ of the first sample we have:$$$a = [1, 2, 2]$$$. Here Koa chooses $$$1$$$, other player has to choose $$$2$$$, Koa chooses another $$$2$$$. Score for Koa is $$$1 \oplus 2 = 3$$$ and score for other player is $$$2$$$ so Koa wins. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"games",
"math"
] | 4b78c417abfbbceef51110365c4c0f15 | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)Β β elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 1,900 | For each test case print: WIN if Koa will win the game. LOSE if Koa will lose the game. DRAW if the game ends in a draw. | standard output | |
PASSED | 79d07e218e18726f429a683a1807a667 | train_004.jsonl | 1408548600 | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: for all x the following inequality holds lββ€βxββ€βr; 1ββ€β|S|ββ€βk; lets denote the i-th element of the set S as si; value must be as small as possible. Help Victor find the described set. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;
/**
* @author master_j
* @version 0.4
* @since May 3, 2014
*/
public class Main {
private void solve() throws IOException {
long l = io.nL(), r = io.nL(), k = io.nI();
io.wln(solve(l, r, k));
}//2.2250738585072012e-308
private String solve(long l, long r, long k) throws IOException {
if(k == 1 || l == r)
return String.format("%d\n1\n%d\n", l, l);
if(k == 2 || l + 1 == r){
long ans = l;
for(long t = l; t + 1 <= r && t <= l + 1000; t++)
if((ans ^ (1 + ans)) > (t ^ (1 + t)))
ans = t;
if((ans ^ (1 + ans)) < l)
return String.format("%d\n2\n%d %d\n", ans ^ (1 + ans), ans, 1 + ans);
else
return String.format("%d\n1\n%d\n", l, l);
}
if(l == 1 && 3 <= r)
return "0\n3\n1 2 3\n";
String ans2 = "";
long f2 = Long.MAX_VALUE;
for(long p = l; p <= l + 40; p++)
for(long q = p + 1; q <= p + 40; q++){
if(r < p || r < q)
continue;
long t = p ^ q;
if(f2 > t){
f2 = t;
ans2 = String.format("%d\n2\n%d %d\n", f2, p, q);
}
}
long f3 = Long.MAX_VALUE;
String ans3 = "";
for (long p = l; p <= l + 40; p++)
for (long q = p + 1; q <= p + 40; q++)
for (long w = q + 1; w <= q + 40; w++) {
if (r < p || r < q || r < w)
continue;
long t = p ^ q ^ w;
if (f3 > t) {
f3 = t;
ans3 = String.format("%d\n3\n%d %d %d\n", f3, p, q, w);
}
}
long f4 = Long.MAX_VALUE;
String ans4 = "";
if(k >= 4){
final int Y = 25;
for (long p = l; p <= l + Y; p++)
for (long q = p + 1; q <= p + Y; q++)
for (long w = q + 1; w <= q + Y; w++)
for (long s = w + 1; s <= w + Y; s++){
if (r < p || r < q || r < w || r < s)
continue;
long t = p ^ q ^ w ^ s;
if (f4 > t) {
f4 = t;
ans4 = String.format("%d\n4\n%d %d %d %d\n", f4, p, q, w, s);
}
}
}
if(k >= 3){
int t = (int)(log(l)/log(2)) + 1;
long p2 = 1;
for(int i = 0; i < t; i++)
p2 *= 2;
long q = p2 + p2 / 2;
long p = q ^ l;
if(p <= r && q <= r){
f3 = 0;
ans3 = String.format("0\n3\n%d %d %d\n", l, p, q);
}
}
if(f2 <= f3 && f2 <= f4)
return ans2;
if(f3 <= f2 && f3 <= f4)
return ans3;
if(f4 <= 12 && f4 <= f2 && f4 <= f3)
return ans4;
throw new IOException();
}
public static void main(String[] args) throws IOException {
IO.launchSolution(args);
}
Main(IO io) throws IOException {
this.io = io;
solve();
}
private final IO io;
}
class IO {
static final String _localArg = "master_j";
private static final String _problemName = "";
private static final IO.Mode _inMode = Mode.STD_;
private static final IO.Mode _outMode = Mode.STD_;
private static final boolean _autoFlush = false;
static enum Mode {STD_, _PUT_TXT, PROBNAME_}
private final StreamTokenizer st;
private final BufferedReader br;
private final Reader reader;
private final PrintWriter pw;
private final Writer writer;
static void launchSolution(String[] args) throws IOException {
boolean local = (args.length == 1 && args[0].equals(IO._localArg));
IO io = new IO(local);
long nanoTime = 0;
if (local) {
nanoTime -= System.nanoTime();
io.wln("<output>");
}
io.flush();
new Main(io);
io.flush();
if(local){
io.wln("</output>");
nanoTime += System.nanoTime();
final long D9 = 1000000000, D6 = 1000000, D3 = 1000;
if(nanoTime >= D9)
io.wf("%d.%d seconds\n", nanoTime/D9, nanoTime%D9);
else if(nanoTime >= D6)
io.wf("%d.%d millis\n", nanoTime/D6, nanoTime%D6);
else if(nanoTime >= D3)
io.wf("%d.%d micros\n", nanoTime/D3, nanoTime%D3);
else
io.wf("%d nanos\n", nanoTime);
}
io.close();
}
IO(boolean local) throws IOException {
if(_inMode == Mode.PROBNAME_ || _outMode == Mode.PROBNAME_)
if(_problemName.length() == 0)
throw new IllegalStateException("You imbecile. Where's my <_problemName>?");
if(_problemName.length() > 0)
if(_inMode != Mode.PROBNAME_ && _outMode != Mode.PROBNAME_)
throw new IllegalStateException("You imbecile. What's the <_problemName> for?");
Locale.setDefault(Locale.US);
if (local) {
reader = new FileReader("input.txt");
writer = new OutputStreamWriter(System.out);
} else {
switch (_inMode) {
case STD_:
reader = new InputStreamReader(System.in);
break;
case PROBNAME_:
reader = new FileReader(_problemName + ".in");
break;
case _PUT_TXT:
reader = new FileReader("input.txt");
break;
default:
throw new NullPointerException("You imbecile. Gimme _inMode.");
}
switch (_outMode) {
case STD_:
writer = new OutputStreamWriter(System.out);
break;
case PROBNAME_:
writer = new FileWriter(_problemName + ".out");
break;
case _PUT_TXT:
writer = new FileWriter("output.txt");
break;
default:
throw new NullPointerException("You imbecile. Gimme _outMode.");
}
}
br = new BufferedReader(reader);
st = new StreamTokenizer(br);
pw = new PrintWriter(writer, _autoFlush);
if(local && _autoFlush)
wln("Note: auto-flush is on.");
}
void wln() {pw.println(); }
void wln(boolean x) {pw.println(x);}
void wln(char x) {pw.println(x);}
void wln(char x[]) {pw.println(x);}
void wln(double x) {pw.println(x);}
void wln(float x) {pw.println(x);}
void wln(int x) {pw.println(x);}
void wln(long x) {pw.println(x);}
void wln(Object x) {pw.println(x);}
void wln(String x) {pw.println(x);}
void wf(String f, Object...o){pw.printf(f, o);}
void w(boolean x) {pw.print(x);}
void w(char x) {pw.print(x);}
void w(char x[]) {pw.print(x);}
void w(double x) {pw.print(x);}
void w(float x) {pw.print(x);}
void w(int x) {pw.print(x);}
void w(long x) {pw.print(x);}
void w(Object x) {pw.print(x);}
void w(String x) {pw.print(x);}
int nI() throws IOException {st.nextToken(); return (int)st.nval;}
double nD() throws IOException {st.nextToken(); return st.nval;}
float nF() throws IOException {st.nextToken(); return (float)st.nval;}
long nL() throws IOException {st.nextToken(); return (long)st.nval;}
String nS() throws IOException {st.nextToken(); return st.sval;}
void wc(String x){ wc(x.toCharArray()); }
void wc(char c1, char c2){for(char c = c1; c<=c2; c++)wc(c);}
void wc(char x[]){
for(char c : x)
wc(c);
}
void wc(char x){st.ordinaryChar(x); st.wordChars(x, x);}
public boolean eof() {return st.ttype == StreamTokenizer.TT_EOF;}
public boolean eol() {return st.ttype == StreamTokenizer.TT_EOL;}
void flush(){pw.flush();}
void close() throws IOException{reader.close(); br.close(); flush(); pw.close();}
} | Java | ["8 15 3", "8 30 7"] | 1 second | ["1\n2\n10 11", "0\n5\n14 9 28 11 16"] | NoteOperation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | Java 8 | standard input | [
"constructive algorithms",
"brute force",
"math"
] | b5eb2bbdba138a4668eb9736fb5258ac | The first line contains three space-separated integers l,βr,βk (1ββ€βlββ€βrββ€β1012;Β 1ββ€βkββ€βmin(106,βrβ-βlβ+β1)). | 2,300 | Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order. If there are multiple optimal sets, you can print any of them. | standard output | |
PASSED | 8239d131a278cdf02c1d5c5f21dff237 | train_004.jsonl | 1408548600 | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: for all x the following inequality holds lββ€βxββ€βr; 1ββ€β|S|ββ€βk; lets denote the i-th element of the set S as si; value must be as small as possible. Help Victor find the described set. | 256 megabytes | import java.util.LinkedList;
import java.io.BufferedWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.AbstractSequentialList;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.math.BigInteger;
import java.io.OutputStream;
import java.util.Iterator;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;
import java.util.Arrays;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.Comparator;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
}
//class Task {
// private final int N = 100009;
// long[] a = new long[N];
// long[] b = new long[N];
// int n , w , m;
// boolean check(long x){
// Arrays.fill(b, 0);
// long now = 0;
// int mm = m;
// for (int i = 0 ; i < n ; ++i){
// now += b[i];
// if (now + a[i] < x){
// if (x - a[i] - now > mm) return false;
// if (i + w < n) b[i + w] -= x - a[i] - now;
// mm -= x - a[i] - now;
// now += x - a[i] - now;
// }
// }
// return true;
// }
// public void solve(int testNumber, InputReader in, OutputWriter out) {
// n = in.readInt();
// m = in.readInt();
// w = in.readInt();
// for (int i = 0 ; i < n ; ++i)
// a[i] = in.readInt();
// long low = 1 , high = 100000L , mid;
// high *= 1000000000L;
// high += 9L;
// long ans = low;
// do{
// mid = (low + high) >> 1;
// if (check(mid)){
// if (ans < mid) ans = mid;
// low = mid + 1;
// }
// else high = mid - 1;
// }while(low <= high);
// System.out.println(ans);
// }
//}
class Task {
Scanner cin = new Scanner(System.in);
public void solve(int testNumber, InputReader in, OutputWriter out) {
long l , r , k;
l = cin.nextLong();
r = cin.nextLong();
k = cin.nextLong();
if (k == 1){
System.out.println(l);
System.out.println(1);
System.out.println(l);
return;
}
if (k == 2){
if (r - l == 1){
if ((l ^ r) < l){
System.out.println(l ^ r);
System.out.println(2);
System.out.println(l + " " + r);
// System.out.print(' ');
}
else{
System.out.println(l);
System.out.println(1);
System.out.println(l);
}
}
else{
if (l % 2 == 1) l++;
System.out.println(1);
System.out.println(2);
System.out.println(l + " " + (l + 1));
}
return;
}
if (k == 3){
long key = 1; while (key <= l) key *= 2;
long ll = key + (key >> 1);
long lll = l ^ ll;
if (ll <= r && lll <= r){
System.out.println(0);
System.out.println(3);
System.out.println(l+" "+ll +' ' + lll);
return;
}
}
long ll = l;
for (int x = 0 ; x < 16 ; ++x){
ArrayList<Long> a = new ArrayList();
for (long i = l + x ; i + x <= r && i + x < l + 16 ; ++i){
a.add(i + x);
}
int TAT = 1 << a.size();
for (int i = 1 ; i < TAT ; ++i){
int ii = i , y = 0;
long now = 0;
for (int j = 0 ; j < a.size(); ++j) if (((1 << j) & i) != 0){
now = now ^ a.get(j);
y++;
}
if (y > k) continue;
if (now == 0){
ArrayList<Long> ans = new ArrayList();
for (int j = 0 ; j < a.size(); ++j) if (((1 << j) & i) != 0){
ans.add(a.get(j));
}
System.out.println(0);
System.out.println(ans.size());
for (int j = 0 ; j < ans.size(); ++j){
if (j > 0) System.out.print(' ');
System.out.print(ans.get(j));
}
return;
}
}
}
l = ll;
if (l % 2 == 1) l++;
System.out.println(1);
System.out.println(2);
System.out.println(l + " " + (l + 1));
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void close() {
writer.close();
}
public void printLine(int i) {
writer.println(i);
}
}
class IOUtils {
public static void readIntArrays(InputReader in, int[]... arrays) {
for (int i = 0; i < arrays[0].length; i++) {
for (int j = 0; j < arrays.length; j++)
arrays[j][i] = in.readInt();
}
}
}
abstract class IntList extends IntCollection implements Comparable<IntList> {
private static final int INSERTION_THRESHOLD = 16;
public abstract int get(int index);
public abstract void set(int index, int value);
public IntIterator iterator() {
return new IntIterator() {
private int size = size();
private int index = 0;
public int value() throws NoSuchElementException {
if (!isValid())
throw new NoSuchElementException();
return get(index);
}
public void advance() throws NoSuchElementException {
if (!isValid())
throw new NoSuchElementException();
index++;
}
public boolean isValid() {
return index < size;
}
};
}
private void swap(int first, int second) {
if (first == second)
return;
int temp = get(first);
set(first, get(second));
set(second, temp);
}
public IntSortedList inPlaceSort(IntComparator comparator) {
quickSort(0, size() - 1, (Integer.bitCount(Integer.highestOneBit(size()) - 1) * 5) >> 1, comparator);
return new IntSortedArray(this, comparator);
}
private void quickSort(int from, int to, int remaining, IntComparator comparator) {
if (to - from < INSERTION_THRESHOLD) {
insertionSort(from, to, comparator);
return;
}
if (remaining == 0) {
heapSort(from, to, comparator);
return;
}
remaining--;
int pivotIndex = (from + to) >> 1;
int pivot = get(pivotIndex);
swap(pivotIndex, to);
int storeIndex = from;
int equalIndex = to;
for (int i = from; i < equalIndex; i++) {
int value = comparator.compare(get(i), pivot);
if (value < 0)
swap(storeIndex++, i);
else if (value == 0)
swap(--equalIndex, i--);
}
quickSort(from, storeIndex - 1, remaining, comparator);
for (int i = equalIndex; i <= to; i++)
swap(storeIndex++, i);
quickSort(storeIndex, to, remaining, comparator);
}
private void heapSort(int from, int to, IntComparator comparator) {
for (int i = (to + from - 1) >> 1; i >= from; i--)
siftDown(i, to, comparator, from);
for (int i = to; i > from; i--) {
swap(from, i);
siftDown(from, i - 1, comparator, from);
}
}
private void siftDown(int start, int end, IntComparator comparator, int delta) {
int value = get(start);
while (true) {
int child = ((start - delta) << 1) + 1 + delta;
if (child > end)
return;
int childValue = get(child);
if (child + 1 <= end) {
int otherValue = get(child + 1);
if (comparator.compare(otherValue, childValue) > 0) {
child++;
childValue = otherValue;
}
}
if (comparator.compare(value, childValue) >= 0)
return;
swap(start, child);
start = child;
}
}
private void insertionSort(int from, int to, IntComparator comparator) {
for (int i = from + 1; i <= to; i++) {
int value = get(i);
for (int j = i - 1; j >= from; j--) {
if (comparator.compare(get(j), value) <= 0)
break;
swap(j, j + 1);
}
}
}
public int hashCode() {
int hashCode = 1;
for (IntIterator i = iterator(); i.isValid(); i.advance())
hashCode = 31 * hashCode + i.value();
return hashCode;
}
public boolean equals(Object obj) {
if (!(obj instanceof IntList))
return false;
IntList list = (IntList)obj;
if (list.size() != size())
return false;
IntIterator i = iterator();
IntIterator j = list.iterator();
while (i.isValid()) {
if (i.value() != j.value())
return false;
i.advance();
j.advance();
}
return true;
}
public int compareTo(IntList o) {
IntIterator i = iterator();
IntIterator j = o.iterator();
while (true) {
if (i.isValid()) {
if (j.isValid()) {
if (i.value() != j.value()) {
if (i.value() < j.value())
return -1;
else
return 1;
}
} else
return 1;
} else {
if (j.isValid())
return -1;
else
return 0;
}
i.advance();
j.advance();
}
}
}
class IntArrayList extends IntList {
private int[] array;
private int size;
public IntArrayList() {
this(10);
}
public IntArrayList(int capacity) {
array = new int[capacity];
}
public IntArrayList(IntList list) {
this(list.size());
addAll(list);
}
public int get(int index) {
if (index >= size)
throw new IndexOutOfBoundsException();
return array[index];
}
public void set(int index, int value) {
if (index >= size)
throw new IndexOutOfBoundsException();
array[index] = value;
}
public int size() {
return size;
}
public void add(int value) {
ensureCapacity(size + 1);
array[size++] = value;
}
public void ensureCapacity(int newCapacity) {
if (newCapacity > array.length) {
int[] newArray = new int[Math.max(newCapacity, array.length << 1)];
System.arraycopy(array, 0, newArray, 0, size);
array = newArray;
}
}
}
abstract class IntCollection {
public abstract IntIterator iterator();
public abstract int size();
public abstract void add(int value);
public void addAll(IntCollection values) {
for (IntIterator it = values.iterator(); it.isValid(); it.advance()) {
add(it.value());
}
}
}
abstract class IntSortedList extends IntList {
protected final IntComparator comparator;
protected IntSortedList(IntComparator comparator) {
this.comparator = comparator;
}
public void set(int index, int value) {
throw new UnsupportedOperationException();
}
public void add(int value) {
throw new UnsupportedOperationException();
}
public IntSortedList inPlaceSort(IntComparator comparator) {
if (comparator == this.comparator)
return this;
throw new UnsupportedOperationException();
}
protected void ensureSorted() {
int size = size();
if (size == 0)
return;
int last = get(0);
for (int i = 1; i < size; i++) {
int current = get(i);
if (comparator.compare(last, current) > 0)
throw new IllegalArgumentException();
last = current;
}
}
}
interface IntComparator {
public static final IntComparator DEFAULT = new IntComparator() {
public int compare(int first, int second) {
if (first < second)
return -1;
if (first > second)
return 1;
return 0;
}
};
public int compare(int first, int second);
}
class ArrayUtils {
public static long sumArray(int[] array) {
long result = 0;
for (int element : array)
result += element;
return result;
}
}
class Heap {
private IntComparator comparator;
private int size = 0;
private int[] elements;
private int[] at;
public Heap(int maxElement) {
this(10, maxElement);
}
public Heap(IntComparator comparator, int maxElement) {
this(10, comparator, maxElement);
}
public Heap(int capacity, int maxElement) {
this(capacity, IntComparator.DEFAULT, maxElement);
}
public Heap(int capacity, IntComparator comparator, int maxElement) {
this.comparator = comparator;
elements = new int[capacity];
at = new int[maxElement];
Arrays.fill(at, -1);
}
public boolean isEmpty() {
return size == 0;
}
public int add(int element) {
ensureCapacity(size + 1);
elements[size] = element;
at[element] = size;
shiftUp(size++);
return at[element];
}
public void shiftUp(int index) {
// if (index < 0 || index >= size)
// throw new IllegalArgumentException();
int value = elements[index];
while (index != 0) {
int parent = (index - 1) >>> 1;
int parentValue = elements[parent];
if (comparator.compare(parentValue, value) <= 0) {
elements[index] = value;
at[value] = index;
return;
}
elements[index] = parentValue;
at[parentValue] = index;
index = parent;
}
elements[0] = value;
at[value] = 0;
}
public void shiftDown(int index) {
if (index < 0 || index >= size)
throw new IllegalArgumentException();
while (true) {
int child = (index << 1) + 1;
if (child >= size)
return;
if (child + 1 < size && comparator.compare(elements[child], elements[child + 1]) > 0)
child++;
if (comparator.compare(elements[index], elements[child]) <= 0)
return;
swap(index, child);
index = child;
}
}
private void swap(int first, int second) {
int temp = elements[first];
elements[first] = elements[second];
elements[second] = temp;
at[elements[first]] = first;
at[elements[second]] = second;
}
private void ensureCapacity(int size) {
if (elements.length < size) {
int[] oldElements = elements;
elements = new int[Math.max(2 * elements.length, size)];
System.arraycopy(oldElements, 0, elements, 0, this.size);
}
}
public int poll() {
if (isEmpty())
throw new IndexOutOfBoundsException();
int result = elements[0];
at[result] = -1;
if (size == 1) {
size = 0;
return result;
}
elements[0] = elements[--size];
at[elements[0]] = 0;
shiftDown(0);
return result;
}
}
interface IntIterator {
public int value() throws NoSuchElementException;
/*
* @throws NoSuchElementException only if iterator already invalid
*/
public void advance() throws NoSuchElementException;
public boolean isValid();
}
class IntSortedArray extends IntSortedList {
private final int[] array;
public IntSortedArray(int[] array) {
this(array, IntComparator.DEFAULT);
}
public IntSortedArray(IntCollection collection) {
this(collection, IntComparator.DEFAULT);
}
public IntSortedArray(int[] array, IntComparator comparator) {
super(comparator);
this.array = array;
ensureSorted();
}
public IntSortedArray(IntCollection collection, IntComparator comparator) {
super(comparator);
array = new int[collection.size()];
int i = 0;
for (IntIterator iterator = collection.iterator(); iterator.isValid(); iterator.advance())
array[i++] = iterator.value();
ensureSorted();
}
public int get(int index) {
return array[index];
}
public int size() {
return array.length;
}
} | Java | ["8 15 3", "8 30 7"] | 1 second | ["1\n2\n10 11", "0\n5\n14 9 28 11 16"] | NoteOperation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | Java 8 | standard input | [
"constructive algorithms",
"brute force",
"math"
] | b5eb2bbdba138a4668eb9736fb5258ac | The first line contains three space-separated integers l,βr,βk (1ββ€βlββ€βrββ€β1012;Β 1ββ€βkββ€βmin(106,βrβ-βlβ+β1)). | 2,300 | Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order. If there are multiple optimal sets, you can print any of them. | standard output | |
PASSED | 08d06b94b926922535309b5d0ddb750a | train_004.jsonl | 1408548600 | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: for all x the following inequality holds lββ€βxββ€βr; 1ββ€β|S|ββ€βk; lets denote the i-th element of the set S as si; value must be as small as possible. Help Victor find the described set. | 256 megabytes | import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author xiaodao (www.shuizilong.com/house)
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, Scanner in, PrintWriter out) {
long l = in.nextLong(), r = in.nextLong(), k = in.nextLong();
long rr = r;
if (r > l + 20) r = l + 20;
if (r <= l + 20) {
long ans = r;
long n = r - l + 1;
for (int s = 1; s < 1 << n; ++s) {
long xx = 0;
int cnt = 0;
for (int i = 0; i < n; ++i)
if ((s & (1 << i)) != 0) {
++cnt;
xx ^= (l + i);
}
if (cnt > k) continue;
if (xx < ans) {
ans = xx;
}
}
if (ans == 1 && k == 3){
long key = 1; while (key <= l) key *= 2;
long ll = key + (key >> 1);
long lll = l ^ ll;
if (ll <= rr && lll <= rr){
out.println(0);
out.println(3);
out.println(l+" "+ll +" " + lll);
return;
}
}
out.println(ans);
for (int s = 1; s < 1 << n; ++s) {
long xx = 0;
int cnt = 0;
for (int i = 0; i < n; ++i)
if ((s & (1 << i)) != 0) {
++cnt;
xx ^= (l + i);
}
if (cnt > k) continue;
if (xx == ans) {
out.println(cnt);
for (int i = 0; i < n; ++i)
if ((s & (1 << i)) != 0) {
out.print(l + i);
out.print(' ');
}
return;
}
}
}
}
}
| Java | ["8 15 3", "8 30 7"] | 1 second | ["1\n2\n10 11", "0\n5\n14 9 28 11 16"] | NoteOperation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | Java 8 | standard input | [
"constructive algorithms",
"brute force",
"math"
] | b5eb2bbdba138a4668eb9736fb5258ac | The first line contains three space-separated integers l,βr,βk (1ββ€βlββ€βrββ€β1012;Β 1ββ€βkββ€βmin(106,βrβ-βlβ+β1)). | 2,300 | Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order. If there are multiple optimal sets, you can print any of them. | standard output | |
PASSED | 466129f331d9603ab63e6ce81cc68be5 | train_004.jsonl | 1408548600 | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: for all x the following inequality holds lββ€βxββ€βr; 1ββ€β|S|ββ€βk; lets denote the i-th element of the set S as si; value must be as small as possible. Help Victor find the described set. | 256 megabytes | import java.util.LinkedList;
import java.io.BufferedWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.AbstractSequentialList;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.math.BigInteger;
import java.io.OutputStream;
import java.util.Iterator;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;
import java.util.Arrays;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.Comparator;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
}
class Task {
Scanner cin = new Scanner(System.in);
public void solve(int testNumber, InputReader in, OutputWriter out) {
long l , r , k;
l = cin.nextLong();
r = cin.nextLong();
k = cin.nextLong();
if (k == 1){
System.out.println(l);
System.out.println(1);
System.out.println(l);
return;
}
if (k == 2){
if (r - l == 1){
if ((l ^ r) < l){
System.out.println(l ^ r);
System.out.println(2);
System.out.println(l + " " + r);
// System.out.print(' ');
}
else{
System.out.println(l);
System.out.println(1);
System.out.println(l);
}
}
else{
if (l % 2 == 1) l++;
System.out.println(1);
System.out.println(2);
System.out.println(l + " " + (l + 1));
}
return;
}
if (k >= 3){
long key = 1; while (key <= l) key *= 2;
long ll = key + (key >> 1);
long lll = l ^ ll;
if (ll <= r && lll <= r){
System.out.println(0);
System.out.println(3);
System.out.println(l+" "+ll +' ' + lll);
return;
}
}
long ll = l;
while((l & 3) != 0) ++l;
if (l + 3 <= r && k >= 4){
System.out.println(0);
System.out.println(4);
System.out.println(l + " " + (l + 1) + " " + (l + 2) + " " + (l + 3));
return;
}
l = ll;
while((l & 3) != 2) ++l;
if (l + 3 <= r && k >= 4){
System.out.println(0);
System.out.println(4);
System.out.println(l + " " + (l + 1) + " " + (l + 2) + " " + (l + 3));
return;
}
l = ll;
if (l % 2 == 1) l++;
System.out.println(1);
System.out.println(2);
System.out.println(l + " " + (l + 1));
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void close() {
writer.close();
}
public void printLine(int i) {
writer.println(i);
}
}
class IOUtils {
public static void readIntArrays(InputReader in, int[]... arrays) {
for (int i = 0; i < arrays[0].length; i++) {
for (int j = 0; j < arrays.length; j++)
arrays[j][i] = in.readInt();
}
}
}
abstract class IntList extends IntCollection implements Comparable<IntList> {
private static final int INSERTION_THRESHOLD = 16;
public abstract int get(int index);
public abstract void set(int index, int value);
public IntIterator iterator() {
return new IntIterator() {
private int size = size();
private int index = 0;
public int value() throws NoSuchElementException {
if (!isValid())
throw new NoSuchElementException();
return get(index);
}
public void advance() throws NoSuchElementException {
if (!isValid())
throw new NoSuchElementException();
index++;
}
public boolean isValid() {
return index < size;
}
};
}
private void swap(int first, int second) {
if (first == second)
return;
int temp = get(first);
set(first, get(second));
set(second, temp);
}
public IntSortedList inPlaceSort(IntComparator comparator) {
quickSort(0, size() - 1, (Integer.bitCount(Integer.highestOneBit(size()) - 1) * 5) >> 1, comparator);
return new IntSortedArray(this, comparator);
}
private void quickSort(int from, int to, int remaining, IntComparator comparator) {
if (to - from < INSERTION_THRESHOLD) {
insertionSort(from, to, comparator);
return;
}
if (remaining == 0) {
heapSort(from, to, comparator);
return;
}
remaining--;
int pivotIndex = (from + to) >> 1;
int pivot = get(pivotIndex);
swap(pivotIndex, to);
int storeIndex = from;
int equalIndex = to;
for (int i = from; i < equalIndex; i++) {
int value = comparator.compare(get(i), pivot);
if (value < 0)
swap(storeIndex++, i);
else if (value == 0)
swap(--equalIndex, i--);
}
quickSort(from, storeIndex - 1, remaining, comparator);
for (int i = equalIndex; i <= to; i++)
swap(storeIndex++, i);
quickSort(storeIndex, to, remaining, comparator);
}
private void heapSort(int from, int to, IntComparator comparator) {
for (int i = (to + from - 1) >> 1; i >= from; i--)
siftDown(i, to, comparator, from);
for (int i = to; i > from; i--) {
swap(from, i);
siftDown(from, i - 1, comparator, from);
}
}
private void siftDown(int start, int end, IntComparator comparator, int delta) {
int value = get(start);
while (true) {
int child = ((start - delta) << 1) + 1 + delta;
if (child > end)
return;
int childValue = get(child);
if (child + 1 <= end) {
int otherValue = get(child + 1);
if (comparator.compare(otherValue, childValue) > 0) {
child++;
childValue = otherValue;
}
}
if (comparator.compare(value, childValue) >= 0)
return;
swap(start, child);
start = child;
}
}
private void insertionSort(int from, int to, IntComparator comparator) {
for (int i = from + 1; i <= to; i++) {
int value = get(i);
for (int j = i - 1; j >= from; j--) {
if (comparator.compare(get(j), value) <= 0)
break;
swap(j, j + 1);
}
}
}
public int hashCode() {
int hashCode = 1;
for (IntIterator i = iterator(); i.isValid(); i.advance())
hashCode = 31 * hashCode + i.value();
return hashCode;
}
public boolean equals(Object obj) {
if (!(obj instanceof IntList))
return false;
IntList list = (IntList)obj;
if (list.size() != size())
return false;
IntIterator i = iterator();
IntIterator j = list.iterator();
while (i.isValid()) {
if (i.value() != j.value())
return false;
i.advance();
j.advance();
}
return true;
}
public int compareTo(IntList o) {
IntIterator i = iterator();
IntIterator j = o.iterator();
while (true) {
if (i.isValid()) {
if (j.isValid()) {
if (i.value() != j.value()) {
if (i.value() < j.value())
return -1;
else
return 1;
}
} else
return 1;
} else {
if (j.isValid())
return -1;
else
return 0;
}
i.advance();
j.advance();
}
}
}
class IntArrayList extends IntList {
private int[] array;
private int size;
public IntArrayList() {
this(10);
}
public IntArrayList(int capacity) {
array = new int[capacity];
}
public IntArrayList(IntList list) {
this(list.size());
addAll(list);
}
public int get(int index) {
if (index >= size)
throw new IndexOutOfBoundsException();
return array[index];
}
public void set(int index, int value) {
if (index >= size)
throw new IndexOutOfBoundsException();
array[index] = value;
}
public int size() {
return size;
}
public void add(int value) {
ensureCapacity(size + 1);
array[size++] = value;
}
public void ensureCapacity(int newCapacity) {
if (newCapacity > array.length) {
int[] newArray = new int[Math.max(newCapacity, array.length << 1)];
System.arraycopy(array, 0, newArray, 0, size);
array = newArray;
}
}
}
abstract class IntCollection {
public abstract IntIterator iterator();
public abstract int size();
public abstract void add(int value);
public void addAll(IntCollection values) {
for (IntIterator it = values.iterator(); it.isValid(); it.advance()) {
add(it.value());
}
}
}
abstract class IntSortedList extends IntList {
protected final IntComparator comparator;
protected IntSortedList(IntComparator comparator) {
this.comparator = comparator;
}
public void set(int index, int value) {
throw new UnsupportedOperationException();
}
public void add(int value) {
throw new UnsupportedOperationException();
}
public IntSortedList inPlaceSort(IntComparator comparator) {
if (comparator == this.comparator)
return this;
throw new UnsupportedOperationException();
}
protected void ensureSorted() {
int size = size();
if (size == 0)
return;
int last = get(0);
for (int i = 1; i < size; i++) {
int current = get(i);
if (comparator.compare(last, current) > 0)
throw new IllegalArgumentException();
last = current;
}
}
}
interface IntComparator {
public static final IntComparator DEFAULT = new IntComparator() {
public int compare(int first, int second) {
if (first < second)
return -1;
if (first > second)
return 1;
return 0;
}
};
public int compare(int first, int second);
}
class ArrayUtils {
public static long sumArray(int[] array) {
long result = 0;
for (int element : array)
result += element;
return result;
}
}
class Heap {
private IntComparator comparator;
private int size = 0;
private int[] elements;
private int[] at;
public Heap(int maxElement) {
this(10, maxElement);
}
public Heap(IntComparator comparator, int maxElement) {
this(10, comparator, maxElement);
}
public Heap(int capacity, int maxElement) {
this(capacity, IntComparator.DEFAULT, maxElement);
}
public Heap(int capacity, IntComparator comparator, int maxElement) {
this.comparator = comparator;
elements = new int[capacity];
at = new int[maxElement];
Arrays.fill(at, -1);
}
public boolean isEmpty() {
return size == 0;
}
public int add(int element) {
ensureCapacity(size + 1);
elements[size] = element;
at[element] = size;
shiftUp(size++);
return at[element];
}
public void shiftUp(int index) {
// if (index < 0 || index >= size)
// throw new IllegalArgumentException();
int value = elements[index];
while (index != 0) {
int parent = (index - 1) >>> 1;
int parentValue = elements[parent];
if (comparator.compare(parentValue, value) <= 0) {
elements[index] = value;
at[value] = index;
return;
}
elements[index] = parentValue;
at[parentValue] = index;
index = parent;
}
elements[0] = value;
at[value] = 0;
}
public void shiftDown(int index) {
if (index < 0 || index >= size)
throw new IllegalArgumentException();
while (true) {
int child = (index << 1) + 1;
if (child >= size)
return;
if (child + 1 < size && comparator.compare(elements[child], elements[child + 1]) > 0)
child++;
if (comparator.compare(elements[index], elements[child]) <= 0)
return;
swap(index, child);
index = child;
}
}
private void swap(int first, int second) {
int temp = elements[first];
elements[first] = elements[second];
elements[second] = temp;
at[elements[first]] = first;
at[elements[second]] = second;
}
private void ensureCapacity(int size) {
if (elements.length < size) {
int[] oldElements = elements;
elements = new int[Math.max(2 * elements.length, size)];
System.arraycopy(oldElements, 0, elements, 0, this.size);
}
}
public int poll() {
if (isEmpty())
throw new IndexOutOfBoundsException();
int result = elements[0];
at[result] = -1;
if (size == 1) {
size = 0;
return result;
}
elements[0] = elements[--size];
at[elements[0]] = 0;
shiftDown(0);
return result;
}
}
interface IntIterator {
public int value() throws NoSuchElementException;
/*
* @throws NoSuchElementException only if iterator already invalid
*/
public void advance() throws NoSuchElementException;
public boolean isValid();
}
class IntSortedArray extends IntSortedList {
private final int[] array;
public IntSortedArray(int[] array) {
this(array, IntComparator.DEFAULT);
}
public IntSortedArray(IntCollection collection) {
this(collection, IntComparator.DEFAULT);
}
public IntSortedArray(int[] array, IntComparator comparator) {
super(comparator);
this.array = array;
ensureSorted();
}
public IntSortedArray(IntCollection collection, IntComparator comparator) {
super(comparator);
array = new int[collection.size()];
int i = 0;
for (IntIterator iterator = collection.iterator(); iterator.isValid(); iterator.advance())
array[i++] = iterator.value();
ensureSorted();
}
public int get(int index) {
return array[index];
}
public int size() {
return array.length;
}
} | Java | ["8 15 3", "8 30 7"] | 1 second | ["1\n2\n10 11", "0\n5\n14 9 28 11 16"] | NoteOperation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | Java 8 | standard input | [
"constructive algorithms",
"brute force",
"math"
] | b5eb2bbdba138a4668eb9736fb5258ac | The first line contains three space-separated integers l,βr,βk (1ββ€βlββ€βrββ€β1012;Β 1ββ€βkββ€βmin(106,βrβ-βlβ+β1)). | 2,300 | Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order. If there are multiple optimal sets, you can print any of them. | standard output | |
PASSED | f6d7920a9f7face9bc8ed8ae4f35169b | train_004.jsonl | 1408548600 | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: for all x the following inequality holds lββ€βxββ€βr; 1ββ€β|S|ββ€βk; lets denote the i-th element of the set S as si; value must be as small as possible. Help Victor find the described set. | 256 megabytes | import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;
import java.lang.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, Scanner in, PrintWriter out) {
long l = in.nextLong(), r = in.nextLong(), k = in.nextLong();
long rr = r;
if (r > l + 20) r = l + 20;
if (r <= l + 20) {
long ans = r;
long n = r - l + 1;
for (int s = 1; s < 1 << n; ++s) {
long xx = 0;
int cnt = 0;
for (int i = 0; i < n; ++i)
if ((s & (1 << i)) != 0) {
++cnt;
xx ^= (l + i);
}
if (cnt > k) continue;
if (xx < ans) {
ans = xx;
}
}
if (ans == 1 && k == 3){
long key = 1; while (key <= l) key *= 2;
long ll = key + (key >> 1);
long lll = l ^ ll;
if (ll <= rr && lll <= rr){
out.println(0);
out.println(3);
out.println(l+" "+ll +" " + lll);
return;
}
}
out.println(ans);
for (int s = 1; s < 1 << n; ++s) {
long xx = 0;
int cnt = 0;
for (int i = 0; i < n; ++i)
if ((s & (1 << i)) != 0) {
++cnt;
xx ^= (l + i);
}
if (cnt > k) continue;
if (xx == ans) {
out.println(cnt);
for (int i = 0; i < n; ++i)
if ((s & (1 << i)) != 0) {
out.print(l + i);
out.print(' ');
}
return;
}
}
}
}
} | Java | ["8 15 3", "8 30 7"] | 1 second | ["1\n2\n10 11", "0\n5\n14 9 28 11 16"] | NoteOperation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | Java 8 | standard input | [
"constructive algorithms",
"brute force",
"math"
] | b5eb2bbdba138a4668eb9736fb5258ac | The first line contains three space-separated integers l,βr,βk (1ββ€βlββ€βrββ€β1012;Β 1ββ€βkββ€βmin(106,βrβ-βlβ+β1)). | 2,300 | Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order. If there are multiple optimal sets, you can print any of them. | standard output | |
PASSED | 2ce8e58e444367885c420821f68c9b10 | train_004.jsonl | 1408548600 | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: for all x the following inequality holds lββ€βxββ€βr; 1ββ€β|S|ββ€βk; lets denote the i-th element of the set S as si; value must be as small as possible. Help Victor find the described set. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.BigInteger.*;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import static java.util.Arrays.*;
import java.util.logging.Level;
import java.util.logging.Logger;
// https://netbeans.org/kb/73/java/editor-codereference_ru.html#display
//<editor-fold defaultstate="collapsed" desc="Main">
public class Main {
private void run() {
Locale.setDefault(Locale.US);
boolean oj = true;
try {
oj = System.getProperty("MYLOCAL") == null;
} catch (Exception e) {
}
if (oj) {
sc = new FastScanner(new InputStreamReader(System.in));
out = new PrintWriter(new OutputStreamWriter(System.out));
} else {
try {
sc = new FastScanner(new FileReader("input.txt"));
out = new PrintWriter(new FileWriter("output.txt"));
} catch (IOException e) {
MLE();
}
}
Solver s = new Solver();
s.sc = sc;
s.out = out;
s.solve();
if (!oj) {
err.println("Time: " + (System.currentTimeMillis() - timeBegin) / 1e3);
err.printf("Mem: %d\n", (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20);
}
out.flush();
}
private void show(int[] arr) {
for (int v : arr) {
err.print(" " + v);
}
err.println();
}
public static void exit() {
out.flush();
out.close();
System.exit(0);
}
public static void MLE() {
int[][] arr = new int[1024 * 1024][];
for (int i = 0; i < arr.length; i++) {
arr[i] = new int[1024 * 1024];
}
}
public static void main(String[] args) {
new Main().run();
}
long timeBegin = System.currentTimeMillis();
static FastScanner sc;
static PrintWriter out;
static PrintStream err = System.err;
}
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="FastScanner">
class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner(InputStreamReader reader) {
br = new BufferedReader(reader);
st = new StringTokenizer("");
}
String next() {
while (!st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException ex) {
Main.MLE();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
//</editor-fold>
class Solver {
FastScanner sc;
PrintWriter out;
PrintStream err = System.err;
long l, r;
int k;
long ans = Long.MAX_VALUE;
long[] vect;
void f( long... arr ){
long curAns = 0;
for (long v : arr) curAns ^= v;
if( ans > curAns ){
ans = curAns;
vect = arr;
}
}
void solve() {
l = sc.nextLong();
r = sc.nextLong();
k = sc.nextInt();
f( l );
if( 2 <= k ){
f( l, l+1 );
if( l+2 <= r )
f( l+1, l+2 );
}
if( 3 <= k )
for (int a = 0; a <= 50; a++) {
for (int b = 0; b <= 50; b++) {
for (int c = 0; c <= 50; c++) {
long x = 0, y = 0, z = 0;
x = add( x, a, 1 );
x = add( x, b, 1 );
x = add( x, c, 0 );
y = add( y, a, 1 );
y = add( y, b, 0 );
y = add( y, c, 1 );
z = add( z, a, 0 );
z = add( z, b, 1 );
z = add( z, c, 1 );
if( l <= z && z < y && y < x && x <= r ){
f( x, y, z );
}
}
}
}
if( 4 <= k ){
f( l, l+1, l+2, l+3 );
if( l+4 <= r )
f( l+1, l+2, l+3, l+4 );
}
out.println(ans);
out.println(vect.length);
for (long v : vect) out.print( " " + v );
out.println();
/////////////////////////////////////////////////
}
long add( long val, int cnt, int bit) {
for (int iter = 0; iter < cnt; iter++) {
val = val*2 + bit;
}
return val;
}
}
| Java | ["8 15 3", "8 30 7"] | 1 second | ["1\n2\n10 11", "0\n5\n14 9 28 11 16"] | NoteOperation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | Java 8 | standard input | [
"constructive algorithms",
"brute force",
"math"
] | b5eb2bbdba138a4668eb9736fb5258ac | The first line contains three space-separated integers l,βr,βk (1ββ€βlββ€βrββ€β1012;Β 1ββ€βkββ€βmin(106,βrβ-βlβ+β1)). | 2,300 | Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order. If there are multiple optimal sets, you can print any of them. | standard output | |
PASSED | 9caabcbd4255aa3aa08254b06e4bad37 | train_004.jsonl | 1408548600 | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: for all x the following inequality holds lββ€βxββ€βr; 1ββ€β|S|ββ€βk; lets denote the i-th element of the set S as si; value must be as small as possible. Help Victor find the described set. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
/**
* @author Don Li
*/
public class LittleVictorSet {
static final long INF = (long) 1e18;
long l, r;
int k;
void solve() {
l = in.nextLong();
r = in.nextLong();
k = in.nextInt();
if (r - l + 1 < 5) go1();
else go2();
}
void go1() {
long n = r - l + 1;
long ans = INF;
List<Long> res = new ArrayList<>();
for (int i = 1; i < 1 << n; i++) {
if (Long.bitCount(i) > k) continue;
long xor = 0;
for (int j = 0; j < n; j++) {
if ((i & (1 << j)) > 0) xor ^= l + j;
}
if (xor < ans) {
ans = xor;
res.clear();
for (int j = 0; j < n; j++) {
if ((i & (1 << j)) > 0) res.add(l + j);
}
}
}
out.println(ans);
out.println(res.size());
for (int i = 0; i < res.size(); i++) {
if (i > 0) out.print(' ');
out.print(res.get(i));
}
out.println();
}
void go2() {
if (k == 1) {
out.println(l);
out.println(1);
out.println(l);
return;
}
if (k == 2) {
out.println(1);
out.println(2);
if (l % 2 == 0) out.printf("%d %d%n", l, l + 1);
else out.printf("%d %d%n", l + 1, l + 2);
return;
}
if (k >= 4) {
out.println(0);
out.println(4);
if (l % 2 == 0) out.printf("%d %d %d %d%n", l, l + 1, l + 2, l + 3);
else out.printf("%d %d %d %d%n", l + 1, l + 2, l + 3, l + 4);
return;
}
long min = 1, max = 3;
while (max <= r) {
if (min >= l) {
out.println(0);
out.println(3);
out.printf("%d %d %d%n", min, max - 1, max);
return;
}
min <<= 1;
min++;
max <<= 1;
}
out.println(1);
out.println(2);
if (l % 2 == 0) out.printf("%d %d%n", l, l + 1);
else out.printf("%d %d%n", l + 1, l + 2);
}
public static void main(String[] args) {
in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
out = new PrintWriter(System.out);
new LittleVictorSet().solve();
out.close();
}
static FastScanner in;
static PrintWriter out;
static class FastScanner {
BufferedReader in;
StringTokenizer st;
public FastScanner(BufferedReader in) {
this.in = in;
}
public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(in.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
public double nextDouble() {
return Double.parseDouble(nextToken());
}
}
}
| Java | ["8 15 3", "8 30 7"] | 1 second | ["1\n2\n10 11", "0\n5\n14 9 28 11 16"] | NoteOperation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | Java 8 | standard input | [
"constructive algorithms",
"brute force",
"math"
] | b5eb2bbdba138a4668eb9736fb5258ac | The first line contains three space-separated integers l,βr,βk (1ββ€βlββ€βrββ€β1012;Β 1ββ€βkββ€βmin(106,βrβ-βlβ+β1)). | 2,300 | Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order. If there are multiple optimal sets, you can print any of them. | standard output | |
PASSED | 756784de40aeff6e71fd3150278bd045 | train_004.jsonl | 1408548600 | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: for all x the following inequality holds lββ€βxββ€βr; 1ββ€β|S|ββ€βk; lets denote the i-th element of the set S as si; value must be as small as possible. Help Victor find the described set. | 256 megabytes | /*************************************************************************
> File: Main.java
> Author: Riho.Yoshioka
> Mail: riho.yoshioka@yandex.com
> Created Time: Fri 29 Jul 2016 03:18:11 PM CST
*************************************************************************/
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskD solver = new TaskD();
solver.solve(1, in, out);
out.close();
}
static class TaskD {
public void solve(int testNumber, InputReader in, PrintWriter out) {
long l, r, k;
l = in.nextInt();
r = in.nextInt();
k = in.nextInt();
long result = Long.MAX_VALUE;
ArrayList<Long> numbers = new ArrayList<>();
if (r - l + 1 >= 5 && k >= 4) {
long nl = l;
if (nl % 2 != 0) {
nl++;
}
long tmp = 0;
ArrayList<Long> tmpArray = new ArrayList<>();
for (int i = 0; i < 4; i++) {
tmpArray.add(nl + i);
}
if (tmp < result) {
result = tmp;
numbers = tmpArray;
}
}
if (r - l + 1 <= 4 && k <= 4) {
int cnt = (int) (r - l + 1);
for (int i = 1; i < (1 << cnt); i++) {
if (Integer.bitCount(i) > k) continue;
long tmp = 0;
ArrayList<Long> tmpArray = new ArrayList<>();
for (int j = 0; j < cnt; j++) {
if ((i & (1 << j)) != 0) {
tmp ^= (l + j);
tmpArray.add(l + j);
}
}
if (tmp < result) {
result = tmp;
numbers = tmpArray;
}
}
}
if (k >= 1) {
long tmp = l;
ArrayList<Long> tmpArray = new ArrayList<>();
tmpArray.add(l);
if (tmp < result) {
result = tmp;
numbers = tmpArray;
}
}
if (k >= 2) {
if (r > l + 1) {
long nl = l;
if (nl % 2 != 0) {
nl++;
}
long tmp = 1;
ArrayList<Long> tmpArray = new ArrayList<>();
tmpArray.add(nl); tmpArray.add(nl + 1);
if (tmp < result) {
result = tmp;
numbers = tmpArray;
}
}
else {
long tmp = l ^ r;
ArrayList<Long> tmpArray = new ArrayList<>();
tmpArray.add(l); tmpArray.add(r);
if (tmp < result) {
result = tmp;
numbers = tmpArray;
}
}
}
if (k >= 3) {
//out.println(Long.toBinaryString(r) + " " + Long.toBinaryString(l));
long A = Long.highestOneBit(l);
long B = A << 1;
//2 large 1 small
if (r >= B + A) {
result = 0;
numbers.clear();
numbers.add(l); numbers.add(B + A); numbers.add(B + l - A);
}
}
out.println(result);
out.println(numbers.size());
for (Long x: numbers) {
out.print(x + " ");
}
out.println();
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public long nextInt() {
return Long.parseLong(next());
}
}
}
| Java | ["8 15 3", "8 30 7"] | 1 second | ["1\n2\n10 11", "0\n5\n14 9 28 11 16"] | NoteOperation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | Java 8 | standard input | [
"constructive algorithms",
"brute force",
"math"
] | b5eb2bbdba138a4668eb9736fb5258ac | The first line contains three space-separated integers l,βr,βk (1ββ€βlββ€βrββ€β1012;Β 1ββ€βkββ€βmin(106,βrβ-βlβ+β1)). | 2,300 | Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order. If there are multiple optimal sets, you can print any of them. | standard output | |
PASSED | 0112dab0e26c78efa409be70b3e918ba | train_004.jsonl | 1408548600 | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: for all x the following inequality holds lββ€βxββ€βr; 1ββ€β|S|ββ€βk; lets denote the i-th element of the set S as si; value must be as small as possible. Help Victor find the described set. | 256 megabytes | import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Niyaz Nigmatullin
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(inputStream);
FastPrinter out = new FastPrinter(outputStream);
TaskD solver = new TaskD();
solver.solve(1, in, out);
out.close();
}
}
class TaskD {
public void solve(int testNumber, FastScanner in, FastPrinter out) {
long left = in.nextLong();
long right = in.nextLong();
int k = in.nextInt();
if (right - left <= 10) {
int count = (int) (right - left + 1);
long best = Long.MAX_VALUE;
int bMask = 0;
for (int mask = 1; mask < 1 << count; mask++) {
if (Integer.bitCount(mask) > k) continue;
long xor = 0;
for (int i = 0; i < count; i++) {
if (((mask >> i) & 1) == 1) xor ^= (left + i);
}
if (xor < best) {
best = xor;
bMask = mask;
}
}
out.println(best);
out.println(Integer.bitCount(bMask));
for (int i = 0; i < count; i++) {
if (((bMask >> i) & 1) == 1) {
out.print(left + i + " ");
}
}
out.println();
return;
}
if (k == 1) {
out.println(left);
out.println(1);
out.println(left);
return;
}
if (k >= 4) {
left = (left + 3) / 4 * 4;
out.println(0);
out.println(4);
out.println(left + " " + (left + 1) + " " + (left + 2) + " " + (left + 3));
return;
}
if (k == 3) {
for (int bit = 2; bit < 50; bit++) {
long first = (1L << bit - 1) - 1;
long second = ((1L << bit) - 1) ^ (1L << bit - 2);
long third = first ^ second;
if (first >= second || second >= third) throw new AssertionError();
if (first >= left && third <= right) {
out.println(0);
out.println(3);
out.println(first + " " + second + " " + third);
return;
}
}
}
if ((left & 1) == 1) ++left;
out.println(1);
out.println(2);
out.println(left + " " + (left + 1));
}
}
class FastScanner extends BufferedReader {
public FastScanner(InputStream is) {
super(new InputStreamReader(is));
}
public int read() {
try {
int ret = super.read();
// if (isEOF && ret < 0) {
// throw new InputMismatchException();
// }
// isEOF = ret == -1;
return ret;
} catch (IOException e) {
throw new InputMismatchException();
}
}
public String next() {
StringBuilder sb = new StringBuilder();
int c = read();
while (isWhiteSpace(c)) {
c = read();
}
if (c < 0) {
return null;
}
while (c >= 0 && !isWhiteSpace(c)) {
sb.appendCodePoint(c);
c = read();
}
return sb.toString();
}
static boolean isWhiteSpace(int c) {
return c >= 0 && c <= 32;
}
public int nextInt() {
int c = read();
while (isWhiteSpace(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int ret = 0;
while (c >= 0 && !isWhiteSpace(c)) {
if (c < '0' || c > '9') {
throw new NumberFormatException("digit expected " + (char) c
+ " found");
}
ret = ret * 10 + c - '0';
c = read();
}
return ret * sgn;
}
public long nextLong() {
return Long.parseLong(next());
}
public String readLine() {
try {
return super.readLine();
} catch (IOException e) {
return null;
}
}
}
class FastPrinter extends PrintWriter {
public FastPrinter(OutputStream out) {
super(out);
}
public FastPrinter(Writer out) {
super(out);
}
}
| Java | ["8 15 3", "8 30 7"] | 1 second | ["1\n2\n10 11", "0\n5\n14 9 28 11 16"] | NoteOperation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | Java 8 | standard input | [
"constructive algorithms",
"brute force",
"math"
] | b5eb2bbdba138a4668eb9736fb5258ac | The first line contains three space-separated integers l,βr,βk (1ββ€βlββ€βrββ€β1012;Β 1ββ€βkββ€βmin(106,βrβ-βlβ+β1)). | 2,300 | Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order. If there are multiple optimal sets, you can print any of them. | standard output | |
PASSED | 9a1e47f5b36b4b0e652e688dd9ac3052 | train_004.jsonl | 1408548600 | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: for all x the following inequality holds lββ€βxββ€βr; 1ββ€β|S|ββ€βk; lets denote the i-th element of the set S as si; value must be as small as possible. Help Victor find the described set. | 256 megabytes | import java.io.*;
import java.util.*;
public class D
{
FastScanner in;
PrintWriter out;
int i = 0, j = 0;
void solve() {
/**************START**************/
long l = in.nextLong(), r = in.nextLong(), k = in.nextLong();
if (k == 1 || l == r)
{
out.println(l);
out.println("1");
out.println(l);
}
else if (k == 2 || (r-l < 2))
{
if (r-l == 1)
{
if ((l ^ r) < l)
{
out.println((l^r));
out.println("2");
out.println(l + " " + r);
}
else
{
out.println(l);
out.println("1");
out.println(l);
}
}
else
{
if (l % 2 == 1)
l++;
out.println("1");
out.println("2");
out.println(l + " " + (l+1));
}
}
else if (k == 3)
{
if (l == 1)
{
out.println("0");
out.println("3");
out.println("1 2 3");
return;
}
long highBit = Long.highestOneBit(l);
long lowerBound = highBit * 2;
long upperBound = lowerBound + highBit;
lowerBound--;
if (upperBound <= r)
{
long midBound = (upperBound ^ lowerBound);
out.println("0");
out.println("3");
out.println(lowerBound + " " + midBound + " " + upperBound);
}
else
{
if (l % 2 == 1)
l++;
out.println("1");
out.println("2");
out.println(l + " " + (l+1));
}
}
else
{
if (l == 1)
{
out.println("0");
out.println("3");
out.println("1 2 3");
return;
}
else if (l == 3)
{
out.println("0");
out.println("3");
out.println("3 5 6");
return;
}
if (l % 2 == 1)
{
l++;
}
if (r - l >= 3)
{
out.println("0");
out.println("4");
out.println(l + " " + (l+1) + " " + (l+2) + " " + (l+3));
}
else
{
out.println("1");
out.println("2");
out.println(l + " " + (l+1));
}
}
/***************END***************/
}
public static void main(String[] args) {
new D().runIO();
}
void runIO() {
in = new FastScanner(System.in);
out = new PrintWriter(System.out);
solve();
out.close();
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public FastScanner(InputStream f) {
br = new BufferedReader(new InputStreamReader(f));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
//This will empty out the current line (if non-empty) and return the next line down. If the next line is empty, will return the empty string.
String nextLine() {
st = null;
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return s;
}
boolean hasMoreTokens() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return false;
st = new StringTokenizer(s);
}
return true;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
} | Java | ["8 15 3", "8 30 7"] | 1 second | ["1\n2\n10 11", "0\n5\n14 9 28 11 16"] | NoteOperation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | Java 8 | standard input | [
"constructive algorithms",
"brute force",
"math"
] | b5eb2bbdba138a4668eb9736fb5258ac | The first line contains three space-separated integers l,βr,βk (1ββ€βlββ€βrββ€β1012;Β 1ββ€βkββ€βmin(106,βrβ-βlβ+β1)). | 2,300 | Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order. If there are multiple optimal sets, you can print any of them. | standard output | |
PASSED | c7a03a2bd41625168a2b475544a6ba02 | train_004.jsonl | 1408548600 | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: for all x the following inequality holds lββ€βxββ€βr; 1ββ€β|S|ββ€βk; lets denote the i-th element of the set S as si; value must be as small as possible. Help Victor find the described set. | 256 megabytes | import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.util.NoSuchElementException;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Stanislav Pak
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskD solver = new TaskD();
solver.solve(1, in, out);
out.close();
}
}
class TaskD {
public void solve(int testNumber, InputReader in, OutputWriter out) {
long l = in.readLong();
long r = in.readLong();
int k = in.readInt();
Random random = new Random();
if (r - l + 1 <= 10) {
brute(l, r, k, out);
} else {
if (k == 1) {
out.printLine(l);
out.printLine(1);
out.printLine(l);
} else if (k == 2) {
while (l % 4 > 0) ++l;
out.printLine(1);
out.printLine(2);
out.printLine(l + " " + (l + 1));
} else if (k == 3) {
long a = 3;
long b = 2;
long c = 1;
while (c < l) {
c <<= 1;
++c;
b <<= 1;
++b;
a <<= 1;
}
if (a <= r) {
out.printLine(0);
out.printLine(3);
out.printLine(a + " " + b + " " + c);
return;
}
while (l % 4 > 0) ++l;
out.printLine(1);
out.printLine(2);
out.printLine(l + " " + (l + 1));
} else {
while (l % 4 > 0) ++l;
out.printLine(0);
out.printLine(4);
out.printLine(l + " " + (l + 1) + " " + (l + 2) + " " + (l + 3));
}
}
}
private void brute(long l, long r, int k, OutputWriter out) {
int n = (int) (r - l + 1);
long ans = -1;
int bmask = -1;
for (int mask = 1; mask < (1 << n); ++mask) {
if (Integer.bitCount(mask) <= k) {
long x = 0;
for (int i = 0; i < n; ++i) {
if ((mask & (1 << i)) > 0) {
x ^= l + i;
}
}
if (ans == -1 || ans > x) {
ans = x;
bmask = mask;
}
}
}
out.printLine(ans);
out.printLine(Integer.bitCount(bmask));
boolean first = true;
for (int i = 0; i < n; ++i) {
if ((bmask & (1 << i)) > 0) {
if (!first) out.print(" ");
first = false;
out.print(l + i);
}
}
out.printLine();
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long readLong() {
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 boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine() {
writer.println();
}
public void printLine(Object...objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void print(long i) {
writer.print(i);
}
public void printLine(long i) {
writer.println(i);
}
public void printLine(int i) {
writer.println(i);
}
}
| Java | ["8 15 3", "8 30 7"] | 1 second | ["1\n2\n10 11", "0\n5\n14 9 28 11 16"] | NoteOperation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | Java 8 | standard input | [
"constructive algorithms",
"brute force",
"math"
] | b5eb2bbdba138a4668eb9736fb5258ac | The first line contains three space-separated integers l,βr,βk (1ββ€βlββ€βrββ€β1012;Β 1ββ€βkββ€βmin(106,βrβ-βlβ+β1)). | 2,300 | Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order. If there are multiple optimal sets, you can print any of them. | standard output | |
PASSED | 0cd73eaf8996501bb497ef9ec6e650e3 | train_004.jsonl | 1408548600 | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: for all x the following inequality holds lββ€βxββ€βr; 1ββ€β|S|ββ€βk; lets denote the i-th element of the set S as si; value must be as small as possible. Help Victor find the described set. | 256 megabytes |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
/**
* #
* @author pttrung
*/
public class D_Round_262_Div2 {
public static long MOD = 1000000007;
static long[][][][][][][] dp;
public static void main(String[] args) throws FileNotFoundException {
PrintWriter out = new PrintWriter(System.out);
Scanner in = new Scanner();
long l = in.nextLong();
long r = in.nextLong();
int k = in.nextInt();
if (k == 1) {
out.println(l);
out.println(1);
out.println(l);
} else {
long result = l;
long s = l;
long e = l;
dp = new long[64][2][2][2][2][2][2];
boolean found = false;
for (long i = l; i <= r && i - l < 100; i++) {
if (k >= 3) {
for (long[][][][][][] j : dp) {
for (long[][][][][] a : j) {
for (long[][][][] b : a) {
for (long[][][] c : b) {
for (long[][] d : c) {
for (long[] f : d) {
Arrays.fill(f, -2);
}
}
}
}
}
}
long re = cal(63, i, 0, 0, 0, 0, 0, 0, l, r);
if(re != -1){
found = true;
out.println(0);
out.println(3);
out.print(i + " " + re + " " + (i ^ re));
break;
}
}
for (long j = l - 1; j < i; j++) {
if (i - j <= k) {
long a = xorUpToK(i) ^ xorUpToK(j);
if (a < result) {
result = a;
s = j + 1;
e = i;
}
}
}
}
if(!found){
out.println(result);
out.println(e - s + 1);
for (long i = s; i <= e; i++) {
out.print(i + " ");
}
}
out.println();
}
out.close();
}
public static long cal(int index, long need, int dif1, int dif2, int larger1, int smaller1, int larger2, int smaller2, long l, long r) {
if (index < 0) {
if (dif1 != 0 && dif2 != 0) {
return 0;
}
return -1;
}
if(dp[index][dif1][dif2][larger1][smaller1][larger2][smaller2] != -2){
return dp[index][dif1][dif2][larger1][smaller1][larger2][smaller2];
}
int cur = (((1L << index) & need) != 0) ? 1 : 0;
int a = (((1L << index) & l) != 0) ? 1 : 0;
int b = (((1L << index) & r) != 0) ? 1 : 0;
long result = -1;
if (cur == 0) {
for (int i = 0; i < 2; i++) {
if ((i >= a || larger1 == 1) && (i <= b || smaller1 == 1) && (i >= a || larger2 == 1) && (i <= b || smaller2 == 1)) {
long re = cal(index - 1, need, i != cur ? 1 : dif1, i != cur ? 1 : dif2, i > a ? 1 : larger1, i < b ? 1 : smaller1, i > a ? 1 : larger2, i < b ? 1 : smaller2, l, r);
if (re != -1) {
result = ((long) i << index) | re;
break;
}
}
}
} else {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
if (i != j) {
if ((i >= a || larger1 == 1) && (i <= b || smaller1 == 1) && (j >= a || larger2 == 1) && (j <= b || smaller2 == 1)) {
long re = cal(index - 1, need, i != cur ? 1 : dif1, j != cur ? 1 : dif2, i > a ? 1 : larger1, i < b ? 1 : smaller1, j > a ? 1 : larger2, j < b ? 1 : smaller2, l, r);
if (re != -1) {
result = ((long) i << index) | re;
break;
}
}
}
}
}
}
return dp[index][dif1][dif2][larger1][smaller1][larger2][smaller2] = result;
}
public static long xorUpToK(long k) {
switch ((int) (k % 4)) {
case 0:
return k;
case 1:
return 1;
case 2:
return k + 1;
default:
return 0;
}
}
public static int[] KMP(String val) {
int i = 0;
int j = -1;
int[] result = new int[val.length() + 1];
result[0] = -1;
while (i < val.length()) {
while (j >= 0 && val.charAt(j) != val.charAt(i)) {
j = result[j];
}
j++;
i++;
result[i] = j;
}
return result;
}
public static boolean nextPer(int[] data) {
int i = data.length - 1;
while (i > 0 && data[i] < data[i - 1]) {
i--;
}
if (i == 0) {
return false;
}
int j = data.length - 1;
while (data[j] < data[i - 1]) {
j--;
}
int temp = data[i - 1];
data[i - 1] = data[j];
data[j] = temp;
Arrays.sort(data, i, data.length);
return true;
}
public static int digit(long n) {
int result = 0;
while (n > 0) {
n /= 10;
result++;
}
return result;
}
public static double dist(long a, long b, long x, long y) {
double val = (b - a) * (b - a) + (x - y) * (x - y);
val = Math.sqrt(val);
double other = x * x + a * a;
other = Math.sqrt(other);
return val + other;
}
public static class Point implements Comparable<Point> {
int x, y;
public Point(int start, int end) {
this.x = start;
this.y = end;
}
@Override
public int hashCode() {
int hash = 5;
hash = 47 * hash + this.x;
hash = 47 * hash + this.y;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Point other = (Point) obj;
if (this.x != other.x) {
return false;
}
if (this.y != other.y) {
return false;
}
return true;
}
@Override
public int compareTo(Point o) {
return x - o.x;
}
}
public static class FT {
long[] data;
FT(int n) {
data = new long[n];
}
public void update(int index, long value) {
while (index < data.length) {
data[index] += value;
index += (index & (-index));
}
}
public long get(int index) {
long result = 0;
while (index > 0) {
result += data[index];
index -= (index & (-index));
}
return result;
}
}
public static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
public static long pow(long a, long b, long MOD) {
if (b == 0) {
return 1;
}
if (b == 1) {
return a;
}
long val = pow(a, b / 2, MOD);
if (b % 2 == 0) {
return val * val % MOD;
} else {
return val * (val * a % MOD) % MOD;
}
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner() throws FileNotFoundException {
// System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
br = new BufferedReader(new InputStreamReader(System.in));
// br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
throw new RuntimeException();
}
}
return st.nextToken();
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
st = null;
try {
return br.readLine();
} catch (Exception e) {
throw new RuntimeException();
}
}
public boolean endLine() {
try {
String next = br.readLine();
while (next != null && next.trim().isEmpty()) {
next = br.readLine();
}
if (next == null) {
return true;
}
st = new StringTokenizer(next);
return st.hasMoreTokens();
} catch (Exception e) {
throw new RuntimeException();
}
}
}
}
| Java | ["8 15 3", "8 30 7"] | 1 second | ["1\n2\n10 11", "0\n5\n14 9 28 11 16"] | NoteOperation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | Java 8 | standard input | [
"constructive algorithms",
"brute force",
"math"
] | b5eb2bbdba138a4668eb9736fb5258ac | The first line contains three space-separated integers l,βr,βk (1ββ€βlββ€βrββ€β1012;Β 1ββ€βkββ€βmin(106,βrβ-βlβ+β1)). | 2,300 | Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order. If there are multiple optimal sets, you can print any of them. | standard output | |
PASSED | 5553298879749f40e7616c19bd5ade74 | train_004.jsonl | 1408548600 | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: for all x the following inequality holds lββ€βxββ€βr; 1ββ€β|S|ββ€βk; lets denote the i-th element of the set S as si; value must be as small as possible. Help Victor find the described set. | 256 megabytes | import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
/**
* Created by hama_du on 2014/08/24.
*/
public class ProblemD {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long l = in.nextLong();
long r = in.nextLong();
long k = in.nextInt();
long min = l;
Set<Long> bestValues = new HashSet<>();
bestValues.add(l);
// voe
for (long w = 2 ; w <= Math.min(k, 4) ; w++) {
long xor = 0;
for (long x = l; x <= r ; x++) {
if (Math.abs(x - l) >= 1000000) {
break;
}
xor ^= x;
if (x - l >= w) {
xor ^= (x-w);
}
long reg = xor;
if (min > reg) {
min = reg;
bestValues.clear();
for (long i = x-w+1 ; i <= x ; i++) {
bestValues.add(i);
}
}
}
}
// okay... try another solution.
if (k >= 3 && Long.highestOneBit(l) < Long.highestOneBit(r)) {
long hl = Long.highestOneBit(l);
if(hl*3 <= r) {
min = 0;
bestValues.clear();
bestValues.add(hl*2-1);
bestValues.add(hl*3-1);
bestValues.add(hl*3);
}
}
System.out.println(min);
System.out.println(bestValues.size());
StringBuilder b = new StringBuilder();
for (long i : bestValues) {
b.append(' ');
b.append(i);
}
System.out.println(b.substring(1));
}
}
| Java | ["8 15 3", "8 30 7"] | 1 second | ["1\n2\n10 11", "0\n5\n14 9 28 11 16"] | NoteOperation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | Java 8 | standard input | [
"constructive algorithms",
"brute force",
"math"
] | b5eb2bbdba138a4668eb9736fb5258ac | The first line contains three space-separated integers l,βr,βk (1ββ€βlββ€βrββ€β1012;Β 1ββ€βkββ€βmin(106,βrβ-βlβ+β1)). | 2,300 | Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order. If there are multiple optimal sets, you can print any of them. | standard output | |
PASSED | d52ab930aff99f92cb9a154ab1c5b3bc | train_004.jsonl | 1408548600 | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: for all x the following inequality holds lββ€βxββ€βr; 1ββ€β|S|ββ€βk; lets denote the i-th element of the set S as si; value must be as small as possible. Help Victor find the described set. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
private static Reader in;
private static PrintWriter out;
public static void main(String[] args) throws IOException {
in = new Reader();
out = new PrintWriter(System.out, true);
L = in.nextLong();
R = in.nextLong();
int K = in.nextInt();
if (K == 1) {
out.println (L);
out.println (1);
out.println (L);
out.close();
System.exit(0);
}
if (K == 2) {
if (R - L + 1 == 2) {
if ((R ^ L) < L) {
out.println (R ^ L);
out.println (2);
out.println (L + " " + R);
} else {
out.println (L);
out.println (1);
out.println (L);
}
} else {
if ((L ^ (L + 1)) < ((L + 1) ^ (L + 2))) {
out.println (L ^ (L + 1));
out.println (2);
out.println (L + " " + (L + 1));
} else {
out.println ((L + 1) ^ (L + 2));
out.println (2);
out.println ((L + 1) + " " + (L + 2));
}
}
out.close();
System.exit(0);
}
ArrayList<Long> bset = new ArrayList<Long> ();
long bxor = R + 1;
if (R - L + 1 >= 5 && K >= 4) {
long x1 = 0;
for (long i = L; i <= L + 3; i++)
x1 ^= i;
long x2 = 0;
for (long i = L + 1; i <= L + 4; i++)
x2 ^= i;
if (x1 < x2) {
bxor = x1;
for (long i = L; i <= L + 3; i++) bset.add(i);
} else {
bxor = x2;
for (long i = L + 1; i <= L + 4; i++) bset.add(i);
}
} else if (R - L + 1 <= 4) {
int e = (int)(R - L + 1);
for (int mask = 1; mask < 1 << e; mask++) {
long x = 0;
if (Integer.bitCount(mask) > K) continue;
for (int j = 0; j < e; j++) {
if ((mask & (1 << j)) > 0) {
x ^= (j + L);
}
}
if (x < bxor) {
bxor = x;
bset = new ArrayList<Long> ();
for (int j = 0; j < e; j++) {
if ((mask & (1 << j)) > 0) {
bset.add(j + L);
}
}
}
}
} else {
// K == 3
vis = new boolean[40][4][4][4];
dp = new boolean[40][4][4][4];
if (solve(39, 0, 0, 0)) {
long a1 = 0, a2 = 0, a3 = 0;
int m1 = 0, m2 = 0, m3 = 0;
outer : for (int bit = 39; bit >= 0; bit--) {
for (int i = 0; i <= 1; i++) {
for (int j = 0; j <= 1; j++) {
long lb = (L >> bit) & 1, rb = (R >> bit) & 1;
if (lb == 1 && i == 0 && (m1 & 1) == 0) continue;
if (rb == 0 && i == 1 && (m1 & 2) == 0) continue;
if (lb == 1 && j == 0 && (m2 & 1) == 0) continue;
if (rb == 0 && j == 1 && (m2 & 2) == 0) continue;
if (lb == 1 && (i ^ j) == 0 && (m3 & 1) == 0) continue;
if (rb == 0 && (i ^ j) == 1 && (m3 & 2) == 0) continue;
int nm1 = m1;
if (i == 1 && lb == 0) nm1 |= 1;
if (i == 0 && rb == 1) nm1 |= 2;
int nm2 = m2;
if (j == 1 && lb == 0) nm2 |= 1;
if (j == 0 && rb == 1) nm2 |= 2;
int nm3 = m3;
if ((i ^ j) == 1 && lb == 0) nm3 |= 1;
if ((i ^ j) == 0 && rb == 1) nm3 |= 2;
if (bit == 0 || dp[bit - 1][nm1][nm2][nm3]) {
a1 |= (long)i << (long)bit;
a2 |= (long)j << (long)bit;
a3 |= (long)(i ^ j) << (long)bit;
m1 = nm1;
m2 = nm2;
m3 = nm3;
continue outer;
}
}
}
}
bxor = 0;
bset.add(a1);
bset.add(a2);
bset.add(a3);
} else {
if ((L ^ (L + 1)) < ((L + 1) ^ (L + 2))) {
out.println (L ^ (L + 1));
out.println (2);
out.println (L + " " + (L + 1));
} else {
out.println ((L + 1) ^ (L + 2));
out.println (2);
out.println ((L + 1) + " " + (L + 2));
}
out.close();
System.exit(0);
}
}
out.println (bxor);
out.println (bset.size());
boolean first = true;
for (long x : bset) {
if (!first) out.print (" ");
out.print(x);
first = false;
}
out.println();
out.close();
System.exit(0);
out.close();
System.exit(0);
}
public static boolean[][][][] dp;
public static boolean[][][][] vis;
public static long L, R;
public static boolean solve(int bit, int m1, int m2, int m3) {
if (bit == -1) {
return true;
}
if (vis[bit][m1][m2][m3]) return dp[bit][m1][m2][m3];
vis[bit][m1][m2][m3] = true;
boolean res = false;
for (int i = 0; i <= 1; i++) {
for (int j = 0; j <= 1; j++) {
long lb = (L >> bit) & 1, rb = (R >> bit) & 1;
if (lb == 1 && i == 0 && (m1 & 1) == 0) continue;
if (rb == 0 && i == 1 && (m1 & 2) == 0) continue;
if (lb == 1 && j == 0 && (m2 & 1) == 0) continue;
if (rb == 0 && j == 1 && (m2 & 2) == 0) continue;
if (lb == 1 && (i ^ j) == 0 && (m3 & 1) == 0) continue;
if (rb == 0 && (i ^ j) == 1 && (m3 & 2) == 0) continue;
int nm1 = m1;
if (i == 1 && lb == 0) nm1 |= 1;
if (i == 0 && rb == 1) nm1 |= 2;
int nm2 = m2;
if (j == 1 && lb == 0) nm2 |= 1;
if (j == 0 && rb == 1) nm2 |= 2;
int nm3 = m3;
if ((i ^ j) == 1 && lb == 0) nm3 |= 1;
if ((i ^ j) == 0 && rb == 1) nm3 |= 2;
res |= solve(bit - 1, nm1, nm2, nm3);
}
}
return dp[bit][m1][m2][m3] = res;
}
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[1024];
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.')
while ((c = read()) >= '0' && c <= '9')
ret += (c - '0') / (div *= 10);
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
}
| Java | ["8 15 3", "8 30 7"] | 1 second | ["1\n2\n10 11", "0\n5\n14 9 28 11 16"] | NoteOperation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | Java 6 | standard input | [
"constructive algorithms",
"brute force",
"math"
] | b5eb2bbdba138a4668eb9736fb5258ac | The first line contains three space-separated integers l,βr,βk (1ββ€βlββ€βrββ€β1012;Β 1ββ€βkββ€βmin(106,βrβ-βlβ+β1)). | 2,300 | Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order. If there are multiple optimal sets, you can print any of them. | standard output | |
PASSED | 7cb395f4d0206d69a65caf84e352167c | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Multithreading {
public static void main(String[] args) throws NumberFormatException,
IOException {
BufferedReader input = new BufferedReader(new InputStreamReader(
System.in));
int z = Integer.parseInt(input.readLine());
StringTokenizer sc = new StringTokenizer(input.readLine());
int[] x = new int[z];
for (int i = 0; i < x.length; i++) {
x[i] = Integer.parseInt(sc.nextToken());
}
if (x.length == 1) {
System.out.println(0);
return;
}
int counter = 0;
for (int i = 1; i < x.length; i++) {
if (x[i] < x[i - 1]) {
counter = i;
}
}
System.out.println(counter);
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 2b63ae610a795e809ceba54866323f14 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.*;
import java.math.*;
import static java.lang.Math.*;
import java.security.SecureRandom;
import static java.util.Arrays.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
new Main().run();
}
StreamTokenizer in;
PrintWriter out;
//deb////////////////////////////////////////////////
public static void deb(String n, Object n1) {
System.out.println(n + " is : " + n1);
}
public static void deb(int[] A) {
for (Object oo : A) {
System.out.print(oo + " ");
}
System.out.println("");
}
public static void deb(long[] A) {
for (Object oo : A) {
System.out.print(oo + " ");
}
System.out.println("");
}
public static void deb(String[] A) {
for (Object oo : A) {
System.out.print(oo + " ");
}
System.out.println("");
}
public static void deb(int[][] A) {
for (int i = 0; i < A.length; i++) {
for (Object oo : A[i]) {
System.out.print(oo + " ");
}
System.out.println("");
}
}
public static void deb(long[][] A) {
for (int i = 0; i < A.length; i++) {
for (Object oo : A[i]) {
System.out.print(oo + " ");
}
System.out.println("");
}
}
public static void deb(String[][] A) {
for (int i = 0; i < A.length; i++) {
for (Object oo : A[i]) {
System.out.print(oo + " ");
}
System.out.println("");
}
}
/////////////////////////////////////////////////////////////
int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
void run() throws IOException {
// in = new StreamTokenizer(new BufferedReader(new FileReader("input.txt")));
// out = new PrintWriter(new FileWriter("output.txt"));
in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
out = new PrintWriter(new OutputStreamWriter(System.out));
solve();
out.flush();
}
@SuppressWarnings("unchecked")
void solve() throws IOException {
// long p=1000000007;
// BufferedReader re= new BufferedReader(new InputStreamReader(System.in));
// Scanner sc= new Scanner(System.in);
int N=nextInt();
int[] a= new int[N];
for (int i = 0; i < N; i++) {
a[i]=nextInt();
}
int[] c=new int[N+1];
// long ret= (a.length*(a.length-1))/2;
long ret,ans=0,evi=-1;
for(int i = 0;i < a.length-1;i++)
{ ret=a[i]-1;
for(int j = a[i];j > 0;j -= j & -j) ret -= c[j] ;
if(ret>0){
evi=i;
}
for(int j = a[i];j < N;j += j & -j) c[j]++ ;
}
c=new int[N+1];
for(int i = 0;i < a.length-1;i++)
{ ret=a[i]-1;
for(int j = a[i];j > 0;j -= j & -j) ret -= c[j] ;
if(ret>0){
ans++;
}
else if(ret==0&&i<evi)ans++;
for(int j = a[i];j < N;j += j & -j) c[j]++ ;
}
System.out.println(ans);//aa
}
}
//////////////////////////
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 04866873b125ea441114d695d757b586 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
int ans = n - 1;
for (int i = n - 1; i > 0; i--) {
if(a[i] < a[i - 1])
break;
ans--;
}
out.print(ans);
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 06a4744ec7070baef54548c11ef4a5a6 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.awt.Point;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;
public class Start {
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
void init() throws FileNotFoundException {
if (ONLINE_JUDGE) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
} else {
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
}
}
String readString() throws IOException {
while (!tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
int readInt() throws IOException {
return Integer.parseInt(readString());
}
long readLong() throws IOException {
return Long.parseLong(readString());
}
double readDouble() throws IOException {
return Double.parseDouble(readString());
}
public static void main(String[] args) {
new Start().run();
// Sworn to fight and die
}
public static void mergeSort(int[] a) {
mergeSort(a, 0, a.length - 1);
}
private static void mergeSort(int[] a, int levtIndex, int rightIndex) {
final int MAGIC_VALUE = 50;
if (levtIndex < rightIndex) {
if (rightIndex - levtIndex <= MAGIC_VALUE) {
insertionSort(a, levtIndex, rightIndex);
} else {
int middleIndex = (levtIndex + rightIndex) / 2;
mergeSort(a, levtIndex, middleIndex);
mergeSort(a, middleIndex + 1, rightIndex);
merge(a, levtIndex, middleIndex, rightIndex);
}
}
}
private static void merge(int[] a, int levtIndex, int middleIndex,
int rightIndex) {
int length1 = middleIndex - levtIndex + 1;
int length2 = rightIndex - middleIndex;
int[] levtArray = new int[length1];
int[] rightArray = new int[length2];
System.arraycopy(a, levtIndex, levtArray, 0, length1);
System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
for (int k = levtIndex, i = 0, j = 0; k <= rightIndex; k++) {
if (i == length1) {
a[k] = rightArray[j++];
} else if (j == length2) {
a[k] = levtArray[i++];
} else {
a[k] = levtArray[i] <= rightArray[j] ? levtArray[i++]
: rightArray[j++];
}
}
}
private static void insertionSort(int[] a, int levtIndex, int rightIndex) {
for (int i = levtIndex + 1; i <= rightIndex; i++) {
int current = a[i];
int j = i - 1;
while (j >= levtIndex && a[j] > current) {
a[j + 1] = a[j];
j--;
}
a[j + 1] = current;
}
}
public void run() {
try {
long t1 = System.currentTimeMillis();
init();
solve();
out.close();
long t2 = System.currentTimeMillis();
System.err.println("Time = " + (t2 - t1));
} catch (Exception e) {
e.printStackTrace(System.err);
System.exit(-1);
}
}
class LOL implements Comparable<LOL> {
int x;
int y;
public LOL(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(LOL o) {
if (x == o.x)
return y - o.y;
return x - o.x; // ---->
// return o.x - x; // <----
// return o.y-y;
}
}
public void solve() throws IOException {
int n = readInt();
int [] a = new int [n];
for (int i = 0; i < n; i++) {
a[i] = readInt();
}
int ans= -1;
int j = 0;
// TreeSet<Integer> set = new TreeSet<Integer>();
// for (int i= 0; i < n; i++){
// if (a[i]!=1){
// ans++;
// set.add(i);
// }
// else {
// j = i;
// break;
// }
// }
//
for (int i = 0; i < n-1; i++){
if (a[i] > a[i+1]){
ans = i;
}
}
out.print(++ans);
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 158a8e8a013de3df6199de0b3992bdb5 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] f = new int[n];
for (int i=0;i<n;i++) {
f[i] = in.nextInt();
}
boolean bool = true;
int res = 0;
for (int i=n-2;i>=0;i--) {
if (f[i]>f[i+1]) {
bool = false;
}
if (!bool) {
res++;
}
}
System.out.println(res);
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | d08cdda79d57093c7d2903047e0277dd | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.Scanner;
public class B165 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t= sc.nextInt();
int arr[] = new int[t];
for (int i = 0; i < t; i++) {
arr[i]= sc.nextInt();
}
int i; boolean flag= false;
for (i =t-1; i>0; i--) {
if(arr[i-1]>arr[i]){
flag = true;
break;
}
}
i= flag?i:0;
System.out.println(i);
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 0690c4e39c537d5b95fdcbc287f1c0b3 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.Scanner;
/**
* @author: Serhat YILMAZ
* @date: Feb 1, 2013
* @file: R165_2.java
*/
/**
* @author Serhat YILMAZ
*
*/
public class R165_2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int result = 0;
int[] values = new int[N];
for (int i = 0; i < N; i++) {
int val = scan.nextInt();
values[i] = val;
}
boolean check = true;
int k = 0;
for (int i = N-1; i > 0; i--) {
if(values[i] <= values[i-1]) {
check = false;
k = i;
break;
}
}
System.out.print(k);
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 4175eda196df8914b7847e1dc742ec6c | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class AA {
static StringTokenizer st;
static BufferedReader in;
public static void main(String[] args) throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = nextInt();
int[]a = new int[n+1];
for (int i = 1; i <= n; i++) {
a[i] = nextInt();
}
int min = n+1;
int ans = 0;
for (int i = n; i >= 1; i--) {
if (a[i] > min) {
ans = i;
break;
}
min = Math.min(a[i], min);
}
System.out.println(ans);
pw.close();
}
private static int nextInt() throws IOException{
return Integer.parseInt(next());
}
private static long nextLong() throws IOException{
return Long.parseLong(next());
}
private static double nextDouble() throws IOException{
return Double.parseDouble(next());
}
private static String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | d77d738a9b563a9d0c0a6d4ee826edb0 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.*;
import java.util.*;
public class j
{
public static void main(String a[])throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int k=0,j=0,m=0,i=0;
m=Integer.parseInt(b.readLine());
int d[]=new int[m];
String s;
s=b.readLine();
StringTokenizer c=new StringTokenizer(s);
for(i=0;i<m;i++)
d[i]=Integer.parseInt(c.nextToken());
for(i=m-1;i>0;i--)
if(d[i]<d[i-1])
break;
System.out.print(i);
}
} | Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 4c2a24942e6e2581b544539c5233edd5 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
public static Scanner scan = new Scanner(System.in);
public static boolean bg = true;
public static void main(String[] args) throws Exception {
int n1 = Integer.parseInt(scan.next());
int[] l1 = new int[n1];
for (int i=0;i<n1;i++){
l1[i]= Integer.parseInt(scan.next());
}
int fin = 1;
for (int i=l1.length-1;i>0;i--){
if (l1[i]>l1[i-1]){
fin++;
}
else {
break;
}
}
System.out.println(l1.length-fin);
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 458296ce4d10deea001a7d072000ef86 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | //Date: Oct 9, 2013
//Time: 12:06:41 AM
import java.util.*;
import java.io.*;
public class B270 implements Runnable {
public void solve() throws IOException {
int N = nextInt();
int[] a = new int[N];
for(int i = 0; i <N; i++) a[i] = nextInt();
for(int i = N - 1; i > 0; i--) if(a[i - 1] > a[i]){
System.out.println(i);
return;
}
System.out.println(0);
}
//-----------------------------------------------------------
public static void main(String[] args) {
new B270().run();
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
tok = null;
solve();
in.close();
} catch (IOException e) {
System.exit(0);
}
}
public String nextToken() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
public double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
BufferedReader in;
StringTokenizer tok;
}
/**
public class B270 {
}
*/ | Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | d67146de9511800eb7ebb1cea91218c7 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
*
* @author AltynbeKZ
*/
public class b {
BufferedReader br;
StringTokenizer st;
public static void main(String[] args) throws Exception {
new b().run();
}
public void run() throws Exception {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int[] f = new int[n];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
f[i] = Integer.parseInt(st.nextToken());
}
int res = n - 1;
for (int i = n - 1; i > 0; i--) {
if (f[i] < f[i - 1]) {
break;
} else {
res--;
}
}
System.out.println(res);
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | a5451aaa85afbd31dc22bfce4f614b8d | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.Scanner;
public class b {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] f = new int[n];
for (int i=0;i<n;i++) {
f[i] = in.nextInt();
}
boolean bool = true;
int res = 0;
for (int i=n-2;i>=0;i--) {
if (f[i]>f[i+1]) {
bool = false;
}
if (!bool) {
res++;
}
}
System.out.println(res);
}
} | Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | d45dabad8db3177690f6642c8171c9a7 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Igors
*/
public class CF165B {
public static void main(String[] args){
Scanner s;
s=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int n=s.nextInt();
long counter =0;
// long first=s.nextInt(),
long[] second=new long[n];
for(int i=0;i<n;i++){
second[i]=s.nextInt();
// first=second;
}
counter=n-1;
for(int i=n-1;i>0;i--){
if (second[i-1]>second[i]){
break;
}
counter--;
// first=second;
}
System.out.println(counter);
s.close();
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 1a60a3fb714a021ef421c8a1c638a87b | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.*;
import java.util.ArrayList;
public class IncreasinghSub {
static StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static int nextInt() {
try {
st.nextToken();
return (int) st.nval;
} catch (IOException ex) {
return 0;
}
}
public static void main(String[] args) {
int n = nextInt();
ArrayList<Integer> l = new ArrayList<Integer>();
int a=n;
while(a-->0)
{
l.add(nextInt());
}
// 5 4 1 2 3
// 5 4 3 2 1
int ans=n-1;
while(n-2>=0)
{if(l.get(n-1)>l.get(n-2))
{
ans--;
}else{
break;
}
n--;
}
System.out.println(ans);
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 01b128aafbb9a9ce6f1e9b8852653f96 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class Task270B {
public static void main(String... args) throws NumberFormatException,
IOException {
Solution.main(System.in, System.out);
}
static class Solution {
public static void main(InputStream is, OutputStream os)
throws NumberFormatException, IOException {
PrintWriter pw = new PrintWriter(os);
Scanner s = new Scanner(is);
int n = s.nextInt();
ArrayList<Integer> a = new ArrayList<>(n);
for (int i = 0; i < n; i++) {
a.add(s.nextInt());
}
int lcds = 1;
while(n-lcds-1 >= 0 && a.get(n-lcds) > a.get(n-lcds-1)){
lcds++;
}
pw.write(n-lcds+"");
pw.flush();
s.close();
}
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 2cd1f433ec94d8cd4fff405cf3ee726a | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.*;
public class Main{
static int a;
public static void main(String[]args){
Scanner cin=new Scanner(System.in);
for(int s,n,i,a,b;cin.hasNextInt();System.out.println(s))
for(n=cin.nextInt(),a=s=i=0;n>i++;a=b)
if(a>(b=cin.nextInt())) s=i-1;
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | dc6d1e08de1a45c1ab25c5614f897a8c | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.*;
public class Main{
static int a;
public static void main(String[]args){
Scanner cin=new Scanner(System.in);
for(int s,n,i,a,b;cin.hasNextInt();System.out.println(s))
for(a=n=cin.nextInt(),s=i=0;n>i++;a=b)
if(a>(b=cin.nextInt())) s=i-1;
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | c1c9741871d6dc2b1b3c58ce081f7103 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Task270B {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken());
st = new StringTokenizer(in.readLine());
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = Integer.parseInt(st.nextToken());
}
int c = 1;
for (int i = n - 1; i > 0; i--) {
if (a[i] > a[i - 1]) {
c++;
} else {
break;
}
}
System.out.println(n - c);
}
} | Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | bc0fe92f6d9e14f6f6e9cbf5d9086553 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.Scanner;
public class Task270B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.next());
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = Integer.parseInt(sc.next());
}
sc.close();
int c = 1;
for (int i = n - 1; i > 0; i--) {
if (a[i] > a[i - 1]) {
c++;
} else {
break;
}
}
System.out.println(n - c);
}
} | Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 7d24851ac398cb7c0935004f249cbc91 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.Scanner;
public class Task270B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
sc.close();
int c = 1;
for (int i = n - 1; i > 0; i--) {
if (a[i] > a[i - 1]) {
c++;
} else {
break;
}
}
System.out.println(n - c);
}
} | Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 3b25f012e1eb96c199f91c9e45fa5a70 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
// split de array
public static int[] atoi(String cad) {
String read[] = cad.split(" ");
int res[] = new int[ read.length ];
for (int i = 0; i < read.length; i++) {
res[i] = Integer.parseInt(read[i]);
}
return res;
}
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line = in.readLine();
int n = Integer.parseInt(line.trim());
int arr[] = atoi(in.readLine().trim());
int sum = 0;
int m = 0;
boolean a = false;
for (int i = 0; i < arr.length - 1; i++) {
if (arr[i] > arr[i + 1]) {
a = true;
break;
}
}
for (int i = 0; i < arr.length - 1; i++) {
if (arr[i + 1] < arr[i])
m = i;
}
if (a)
System.out.println(m + 1);
else {
System.out.println(0);
}
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 3399065dac0d0f7dab3964597d71b78c | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.lang.*;
import java.io.*;
import java.util.*;
public class Sequence {
public static void main(String[] args) throws java.lang.Exception {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(in, out);
out.close();
}
}
class TaskA {
public void solve(InputReader in, PrintWriter out) {
int n = in.nextInt();
int[] a = new int[n];
int i, j, k;
if (n == 1) {
out.println(0);
return ;
}
for (i=0; i<n; ++i)
a[i] = in.nextInt();
for (i=n-2; i>=0; --i) {
if (a[i] > a[i+1])
break;
}
out.println(i+1);
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 01dc64b0418c9fa1f2392d395847070a | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.Scanner;
public class B {
private static int n;
private static int[] a;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
a = new int[n];
for(int i=0; i<n; i++)
a[i] = sc.nextInt();
int i;
for(i= n-1; i>0; i--)
if( a[i-1] > a[i] )
break;
System.out.println(i);
sc.close();
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | ac9ad0e0cd8d129be3e8738c66feaf2c | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.*;
import java.io.*;
public class FancyFence {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
int c = 0;
while (sc.hasNextInt()){
a[c]=sc.nextInt();
c++;
}
int t = a[a.length-1];
int r = -1;
for (int i=a.length-2;i>-1;i--){
if (t<a[i]){r=i;break;}
t=a[i];
}
System.out.println(r+1);
}
} | Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 57a595c368589fbe231ba224c38df6e1 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes |
import java.io.*;
import java.util.*;
public class CF165B {
private static BufferedReader br;
private static StringTokenizer st;
private static PrintWriter pw;
// private static Timer t = new Timer();
public CF165B() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(System.out);
}
String next() throws IOException {
while (st == null || !st.hasMoreElements())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
boolean hasNext() {
if (st != null && st.hasMoreElements())
return true;
try {
while (st == null || !st.hasMoreElements())
st = new StringTokenizer(br.readLine());
}
catch (Exception e) {
return false;
}
return true;
}
String nextLine() throws IOException {
return br.readLine();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
void solve() throws IOException {
int n = nextInt();
int[] A = new int[n];
for(int i = 0; i < n; i++)
A[i] = nextInt();
int count = n - 1;
for(int i = n - 1; i > 0; i--) {
if(A[i] < A[i-1])
break;
count--;
}
pw.println(count);
pw.flush();
}
public static void main(String[] args) throws IOException{
new CF165B().solve();
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | b0e8eec93554c6c6f6ed6522ba0048e6 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int prev = in.nextInt();
int ans = 0;
for (int i=1; i<N; i++) {
int cur = in.nextInt();
if (cur < prev)
ans = i;
prev = cur;
}
System.out.println(ans);
}
} | Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | d88a6fc0576eecd145997d8bb2c666d6 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.Scanner;
public class B {
/**
* @param args
*/
public static void main(String[] args) {
Scanner scr = new Scanner(System.in);
int n = scr.nextInt();
int[] a = new int[n+1];
int j = 0;
for (int i = 1; i <= n; i++){
a[i] = scr.nextInt();
}
for (int i = 1; i < n; i++){
if (a[i] > a[i+1]) j = i;
}
System.out.println(j);
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | d33e49d596b9b914cd66653f2b443d64 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n=in.readInt();
int min= Integer.MAX_VALUE;
int arr[]=new int[n+1];
for (int i=1;i<=n;i++) arr[i]=in.readInt();
for (int i=n;i>=1;i--) {
int a=arr[i];
if(a>min) {
out.println(i);
return;
}
min=Math.min(min,a);
}
out.println(0);
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | d21dc3973e085975bee80deca0d233fd | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.*;
import java.util.*;
public class B {
String s = null;
public void run() throws Exception{
BufferedReader br = null;
File file = new File("input.txt");
if(file.exists()){
br = new BufferedReader(new FileReader("input.txt"));
}
else{
br = new BufferedReader(new InputStreamReader(System.in));
}
String s = br.readLine();
int n = Integer.parseInt(s);
int[] a = new int[n];
s = br.readLine();
String[] ss = s.split(" ");
for(int i = 0; i < n; i++){
a[i] = Integer.parseInt(ss[i]);
}
int num = 0;
for(int i = n - 1; i > 0; i--){
if(a[i] < a[i-1]){
break;
}
num++;
}
num++;
int ans = n - num;
System.out.println(ans + "");
}
/**
* @param args
*/
public static void main(String[] args) throws Exception{
B t = new B();
t.run();
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | b5322d7b7beb76b038ce42ba045baa51 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main {
private void solve() throws IOException {
int n = nextInt();
int a[] = new int[n];
for (int i = 0; i < n; ++i)
a[i] = nextInt();
int res = 0;
int i;
for (i = n - 1; i > 0; --i)
if (a[i] < a[i - 1])
break;
print(i);
}
public static void main(String[] args) {
new Main().run();
}
public void run() {
try {
if (isFileIO) {
pw = new PrintWriter(new File("output.txt"));
br = new BufferedReader(new FileReader("input.txt"));
} else {
pw = new PrintWriter(System.out);
br = new BufferedReader(new InputStreamReader(System.in));
}
solve();
pw.close();
br.close();
} catch (IOException e) {
System.err.println("IO Error");
}
}
private void print(Object o) {
pw.print(o);
}
private void println(Object o) {
pw.println(o);
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
private String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(br.readLine());
}
return tokenizer.nextToken();
}
private BufferedReader br;
private StringTokenizer tokenizer;
private PrintWriter pw;
private final boolean isFileIO = false;
} | Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | c17ff8e587d7e004b2e03e112e6f7a4f | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Nguyen Trung Hieu - vuondenthanhcong11@yahoo.com
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int count = in.readInt();
int[] A = new int[count + 1];
A[0] = Integer.MAX_VALUE;
for (int i = 1; i <= count; i++)
A[i] = in.readInt();
for (int i = count; i >= 0; i--)
if (A[i] < A[i - 1]){
out.printLine(i - 1);
break;
}
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 387e6309fb7adfd196f2c27cbac0a979 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.*;
public class w23 {
public static void main(String [] args){
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int array[]=new int[n];
int cnt=0;
for(int i=0;i<n;i++){
array[i]=in.nextInt();
if(array[i]==1)
cnt=i;
}
int ans=0;
for(int i=n-1;i>cnt;i--){
if(array[i]>array[i-1])
ans++;
else
break;
}
ans++;
System.out.print(n-ans);
}
} | Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 911762ace8e068c3b0b20c6865d665ed | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class two {
private static int[] a;
public static void main(String[] args) throws NumberFormatException,
IOException {
readData();
boolean did = false;
int max = 0;
for (int i = a.length-2; i >=0; i--) {
if(a[i] > a[i+1]){
max = i+1;
break;
}
}
System.out.println(max);
}
private static void readData() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
a = new int[n];
String nums = (br.readLine());
StringTokenizer st = new StringTokenizer(nums);
int i = 0;
while (st.hasMoreTokens()) {
String key = st.nextToken();
a[i] = Integer.parseInt(key);
i++;
}
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | dfc98a7bba8b13c8f5a7bda9dc716195 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class judge {
public static void main(String[] arg) throws IOException {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] a= new int[n];
int[] b = new int[n];
for(int i = 0; i < n; i++){
a[i] = in.nextInt() - 1;
b[a[i]] = i;
}
int[] c = new int[n];
for(int i =0; i < n; i++)
c[i] = b[i];
for(int i = 1; i < n; i++)
b[i] = Math.max(b[i], b[i - 1]);
TreeSet<Integer> used = new TreeSet<Integer>();
TreeSet<Integer> us = new TreeSet<Integer>();
int ans = 0;
for(int i = 1; i < n; i++){
if (b[i] == b[i - 1]){
ans++;
used.add(i);
us.add(c[i]);
}
}
for(int i = n - 2; i >= 0; i--)
if (!used.isEmpty() && used.last() > i && !used.contains(i) && c[i] < us.last()){
us.add(c[i]);
used.add(i);
ans++;
}
System.out.println(ans);
}
} | Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | c52b9d11e44d27ec257b451e28c219a6 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Round165_B {
boolean v[];
public void solve()throws Exception{
InputReader in = new InputReader();
int n = in.nextInt();
v = new boolean[n+2];
int next = 1;
int ans =0;
int last = 0;
int tmp =0;
for(int i =0 ; i < n;i++){
int x = in.nextInt();
if(x == next){
for(next = next+1;next <= n+1;next++)
if(!v[next])break;
tmp++;
}else{
v[x] = true;
ans++;
ans += tmp;
tmp =0;
}
}
System.out.println(ans);
}
public static void main(String[] args) throws Exception{
new Round165_B().solve();
}
static class InputReader {
BufferedReader in;
StringTokenizer st;
public InputReader() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(in.readLine());
}
public String next() throws IOException {
while (!st.hasMoreElements())
st = new StringTokenizer(in.readLine());
return st.nextToken();
}
public int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(next());
}
public long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(next());
}
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 2fe8f2b04736a9a0fa0de1147c4d1b70 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.*;
import java.io.*;
public class Multithreading
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] array = new int[n];
for(int x = 0; x < n; x++)
{
array[x] = in.nextInt();
}
int result = 0;
for(int y = n - 2; y >= 0; y--)
{
if(array[y] > array[y + 1])
{
result = y + 1;
break;
}
}
System.out.println(result);
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 6a3c9dfe69ed6ef5d182c4abe3ca4a23 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Main m = new Main();
System.out.println(m.run(new Scanner(System.in)));
// System.out.println(m.run(new Scanner("3\n1 2 3\n")));
}
public int run(Scanner sc) {
int n = sc.nextInt();
int firstSortedIndx = 0;
int lastValue = 0;
for (int i = 0; i < n; i++) {
int current = sc.nextInt();
if (current > lastValue)
lastValue = current;
else {
firstSortedIndx = i;
lastValue = current;
}
}
return firstSortedIndx;
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 9fe21186c11cbb538c6748812fac3574 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class B270 {
static FastScanner in;
static FastWriter out;
public static void main(String[] args) throws IOException {
in = new FastScanner(System.in);
out = new FastWriter(System.out);
int n = in.nextInt();
int last = in.nextInt();
int ans = 0;
for (int i = 0; i < n - 1; i++) {
int v = in.nextInt();
if (v < last) {
ans = i + 1;
}
last = v;
}
out.println(ans);
out.close();
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
st = new StringTokenizer("");
}
public FastScanner(File f) throws IOException {
br = new BufferedReader(new FileReader(f));
st = new StringTokenizer("");
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public String next() throws IOException {
if (st.hasMoreTokens()) return st.nextToken();
st = new StringTokenizer(br.readLine());
return next();
}
}
static class FastWriter extends PrintWriter {
public FastWriter(OutputStream out) throws IOException {
super(new BufferedWriter(new OutputStreamWriter(out)));
}
public FastWriter(File f) throws IOException {
super(new BufferedWriter(new FileWriter(f)));
}
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 77153bde2c9635f6b851e5f0894a0c5b | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.IOException;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.io.BufferedWriter;
import java.util.Locale;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Jacob Jiang
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt();
int[] a = in.nextIntArray(n);
for (int i = n - 2; i >= 0; i--) {
if (a[i + 1] < a[i]) {
out.println(i + 1);
return;
}
}
out.println(0);
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1 << 16];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int 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 & 15;
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public static boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public int[] nextIntArray(int count) {
int[] result = new int[count];
for (int i = 0; i < count; i++) {
result[i] = nextInt();
}
return result;
}
}
class OutputWriter {
private PrintWriter writer;
public OutputWriter(OutputStream stream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void println(int i) {
writer.println(i);
}
public void close() {
writer.close();
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | d77253504694df00116e7a83eeb393cb | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
Task task = new Task();
task.getData();
task.solve();
task.printAnswer();
}
}
class Task {
int[] a;
StringBuilder answer = new StringBuilder();
public void getData() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
a = new int[Integer.parseInt(br.readLine())];
String[] data = br.readLine().split(" ");
for (int i = 0; i < data.length; ++i) {
a[i] = Integer.parseInt(data[i]);
}
}
public void solve() {
int i = a.length - 1;
for (; i >= 1; --i) {
if (a[i - 1] > a[i]) {
break;
}
}
answer.append(i);
}
public void printAnswer() {
System.out.print(answer);
}
}
class Coder {
String nick;
int plus;
int minus;
int[] taskScores;
Coder(String nick, int plus, int minus, int[] taskScores) {
this.nick = nick;
this.plus = plus;
this.minus = minus;
//this.taskScores = new int[taskScores.length];
this.taskScores = Arrays.copyOf(taskScores, taskScores.length);
}
} | Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 9e8e1906a616cd9891c223eed5aef90a | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.*; //PrintWriter
import java.math.*; //BigInteger, BigDecimal
import java.util.*; //StringTokenizer, ArrayList
public class R165_Div2_B
{
FastReader in;
PrintWriter out;
public static void main(String[] args) {
new R165_Div2_B().run();
}
void run()
{
in = new FastReader(System.in);
out = new PrintWriter(System.out);
solve();
out.close();
}
void solve()
{
int n = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = in.nextInt();
int cnt = 0;
for (int i = 0; i < n-1; i++)
if (a[i] > a[i + 1]) cnt = i + 1;
out.println(cnt);
}
//-----------------------------------------------------
void runWithFiles() {
in = new FastReader(new File("input.txt"));
try {
out = new PrintWriter(new File("output.txt"));
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
solve();
out.close();
}
class FastReader
{
BufferedReader br;
StringTokenizer tokenizer;
public FastReader(InputStream stream)
{
br = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public FastReader(File f) {
try {
br = new BufferedReader(new FileReader(f));
tokenizer = null;
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
}
private String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens())
try {
tokenizer = new StringTokenizer(br.readLine());
}
catch (IOException e) {
throw new RuntimeException(e);
}
return tokenizer.nextToken();
}
public String nextLine() {
try {
return br.readLine();
}
catch(Exception e) {
throw(new RuntimeException());
}
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
BigInteger nextBigInteger() {
return new BigInteger(next());
}
BigDecimal nextBigDecimal() {
return new BigDecimal(next());
}
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | f0e0f34ebd7689c6d67b675b601e5a55 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
Scanner scan = new Scanner(System.in);
int threadCount = scan.nextInt();
int prevNum = -1;
int currentNum;
int sequenceSize = 0;
int nonSequenceElemCount = 0;
for(int i=0;i<threadCount;i++){
currentNum = scan.nextInt();
if (currentNum>prevNum){
if (sequenceSize==0 && i!=0){
sequenceSize = 2;
} else {
sequenceSize++;
}
} else {
sequenceSize = 0;
}
if (sequenceSize==0 && i==(threadCount-1) && currentNum<prevNum){
sequenceSize = 1;
}
prevNum=currentNum;
}
System.out.print(threadCount-sequenceSize);
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 4ece02ab9a9471b38995173499aa8572 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.Scanner;
public class Prob270B {
public static void main(String[] Args) {
Scanner scan = new Scanner(System.in);
int x = scan.nextInt();
int[] arr = new int[x];
for (int i = 0; i < x; i++)
arr[i] = scan.nextInt();
int max = 0;
for (int i = 1; i < x; i++)
if (arr[i] < arr[i - 1])
max = i;
System.out.println(max);
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 321aaa8c9a5fe946e344626303f6d885 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.util.Scanner;
public class MultiThreading {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner r = new Scanner(System.in);
int n = r.nextInt();
int a[] = new int[n];
for (int i=0; i<n; i++){
a[i] = r.nextInt();
}
int ans=0;
for (int i=n-1; i>0; i--){
if (a[i-1]>a[i]){
ans = i;
break;
}
}
System.out.println(ans);
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 6be0441ebd05106c6f1ac5da60e3dc55 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n, mark, x, x1;
n = in.nextInt();
mark = 0;
x1 = 10001;
for (int i = 1; i <=n; ++i){
x = in.nextInt();
if (x < x1)
mark = i-1;
x1 = x;
}
out.print(mark);
in.close();
out.close();
}
}
| Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output | |
PASSED | 9cb5225b076f9ba6115ce3f1b0ef39b0 | train_004.jsonl | 1359732600 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the ai-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a1, a2, ..., an. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.TreeSet;
public class B {
public static BufferedReader in;
public static PrintWriter out;
public static void main(String[] args) throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
boolean showLineError = true;
if (showLineError) {
solve();
out.close();
} else {
try {
solve();
} catch (Exception e) {
} finally {
out.close();
}
}
}
static void debug(Object... os) {
out.println(Arrays.deepToString(os));
}
private static void solve() throws IOException {
int n = Integer.parseInt(in.readLine());
List<Integer> list = new ArrayList<Integer>(n);
String[] line = in.readLine().split(" ");
for(String s : line)
list.add(Integer.valueOf(s));
int creciente = 1;
int index = list.size()-2;
while(index>=0 && list.get(index)<list.get(index+1)){
index--;
creciente++;
}
out.println(n-creciente);
}
} | Java | ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1"] | 2 seconds | ["2", "0", "3"] | NoteIn the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.In the second test case, there may be no new messages at all, since the thread order hasn't changed.In the third test case, only thread 1 can contain no new messages. | Java 7 | standard input | [
"data structures",
"implementation",
"greedy"
] | 310a0596c0a459f496b8d6b57676d25e | The first line of input contains an integer n, the number of threads (1ββ€βnββ€β105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1ββ€βaiββ€βn) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | 1,400 | Output a single integer β the number of threads that surely contain a new message. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.