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 | 49e2f7f0ebcb5c477d661cf52e8fc183 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class anime {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
int t = 1;
for(int i = 0; i < t; i++) {
solver.solve(i, in, out);
}
out.close();
}
static class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int[] mas = new int[n];
for(int i = 0; i < n; i++) {
mas[i] = in.nextInt();
}
int ans = 0;
for(int i = 1; i < n - 1; i++) {
if(mas[i] == 0 && mas[i - 1] == 1 && mas[i + 1] == 1) {
mas[i + 1] = 0;
ans++;
}
}
out.println(ans);
}
private long gcd(long a, long b) {
while (b > 0) {
long t = a % b;
a = b;
b = t;
}
return a;
}
}
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 nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | 6722b7afc80990a295d3af5300fcaf34 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
public class DistrubedPeople {
public static void main(String[] args)throws Exception {
int n;
int k=0;
UltraFastReader input = new UltraFastReader();
n=input.nextInt();
int[] a = new int[n];
for(int i=0;i<n;i++)
a[i] = input.nextInt();
for(int i=0;i<n;i++) {
if(isAdjacentlyDisturbed(i,a)) {
k++;
a[i+1]=0;
continue;
}
if(isDisturbed(i,a)) {
k++;
}
}
System.out.println(k);
}
private static boolean isDisturbed(int i,int[] a) {
if((i+1)<a.length&&i-1>=0&&a[i]==0&&a[i+1]==1&&a[i-1]==1)
return true;
return false;
}
private static boolean isAdjacentlyDisturbed(int i,int[] a) {
if(i+2<a.length-1 && isDisturbed(i+2,a)&&isDisturbed(i,a))
return true;
return false;
}
}
class UltraFastReader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public UltraFastReader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public UltraFastReader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | 76b538c019588367c2cc4a0523b35d51 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class First
{
public static void main(String args[])
{
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
arr[i]=scan.nextInt();
int a=0;
int b=1;
int c=2;
int d=3;
int e=4;
int count=0;
while(e<n)
{
if(arr[a]==1&&arr[b]==0&&arr[c]==1&&arr[d]==0&&arr[e]==1)
{
count++;
arr[c]=0;
}
a++;
b++;
c++;
d++;
e++;
}
a=0;b=1;c=2;
while(c<n)
{
if(arr[a]==1&&arr[b]==0&&arr[c]==1)
count++;
a++;
b++;
c++;
}
System.out.println(count);
}
} | Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | 54cc9fa7312ae9f2f2fe020c9c32e062 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes |
import java.util.Scanner;
public class p1 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] arr = new int[n];
int count = 0;
for (int i = 0; i < n; i++) {
arr[i] = scan.nextInt();
if (arr[i] == 0) {
count++;
}
}
int l = n - 2;
int r = 0;
if (arr[n - 1] == 1) {
l = n - 1;
}
if (arr[0] == 0) {
r = 1;
}
int[] sleep = new int[count + 1];
int counter = 0;
for (int i = r; i <= l; i++) {
if (arr[i] == 0 && arr[i + 1] == 1 && arr[i - 1] == 1) {
sleep[counter] = i;
counter++;
}
}
int c = 0;
for (int i = 0; i < counter ; i++) {
if (sleep[i + 1] - sleep[i] == 2) {
c++;
i++;
} else {
c++;
}
}
System.out.print(c);
}
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | 3dd9519d6883b3d17bcf3eb114a9a702 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class ConcernedTenants {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
byte n = (byte) sc.nextInt();
boolean[] a = new boolean[n];
for (byte i = 0; i < n; i++) {
a[i] = sc.nextInt() == 1;
}
byte k = 0;
for (byte i = 1; i < n; i++) {
if (i == n - 1) break;
if (a[i - 1] && !a[i] && a[i + 1]) {
a[i + 1] = false;
k++;
}
}
out.println(k);
out.close();
}
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//--------------------------------------------------------
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | 1cd0e4cc0fb33be35a280e1f78d0eef2 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes |
import java.io.*;
import java.util.*;
public class B521 {
public static void main(String[] args)
{
FastScanner s = new FastScanner();
int n = s.nextInt();
int[] arr = new int[n+1];
for(int i = 1 ;i<n+1 ; i++)
{
arr[i] = (s.nextInt());
}
int ans = 0;
for(int i = 2;i<n;i++)
{
if(arr[i]==0&&arr[i-1]==1&&arr[i+1]==1)
{
ans++;
arr[i+1] = 0;
}
}
System.out.println(ans);
}
public static class FastScanner {
private InputStream mIs;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastScanner() {
this(System.in);
}
public FastScanner(InputStream is) {
mIs = is;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = mIs.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
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 String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
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 | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | a434a50e9b16a71a00ac12056923efb7 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class yuy {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n=sc.nextInt();
int[] a=new int[n];
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
int [] t=new int[n];
for(int i=0;i<n;i++) {
if(i!=0 && i!=n-1 && a[i]==0 && a[i-1]==1 && a[i+1]==1) {
t[i]=-1; t[i-1]++; t[i+1]++;
}
}
int c=0;
for(int i=0;i<n;i++) {
if(t[i]==2) {
t[i-1]=0; c++; t[i+1]=0;
t[i+2]--;
}
}
for(int i=0;i<n;i++) {
if(t[i]==-1) {
c++;
}
}
out.print(c);
out.flush();
}
static 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 char nextChar() throws IOException {
return next().charAt(0);
}
public Long nextLong() throws IOException {
return Long.parseLong(next());
}
public boolean ready() throws IOException {
return br.ready();
}
public void waitForInput() throws InterruptedException {
Thread.sleep(3000);
}
}
} | Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | db052b9dfb97ec8c0fcf23371094d13e | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.util.Scanner;
public class B {
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int [] a = new int[n];
for (int i=0; i<n;i++) {
a[i] = input.nextInt();
}
int cur=0;
int k;
for (int i=1; i<n-1; i++) {
if (a[i-1]==1 && a[i+1]==1 && a[i]==0 ) {
cur++; a[i+1]=0;
}
}
System.out.println(cur);
}
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | e7e1fead0a2edd4ae2c317a18d232364 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.*;
/**
*
* @author abdelmagied
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import javafx.scene.Node;
/**
*
* @author abdelmagied
*/
public class JavaApplication1 {
/**
* @param args the command line arguments
**/
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
List<Integer> arr = new ArrayList<>();
for(int i = 0 ; i < n ; i++){
int next = sc.nextInt();
arr.add(next);
}
int counter = 0 , last = -1;
for(int i = 0 ; i < arr.size() ; i++){
if(i+4 < n && arr.get(i) == 1 && arr.get(i+1) == 0 && arr.get(i+2) == 1 && arr.get(i+3) == 0 && arr.get(i+4) == 1){
counter++;
i+=3;
}else if(i+2 < n && arr.get(i) == 1 && arr.get(i+1) == 0 && arr.get(i+2) == 1){
counter++;
i++;
}
}
System.out.println(counter);
}
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | 6005cf2e250ce6dbd2ed3d3441bd3159 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.util.*;
public class VC521B {
public static boolean check(int []arr, int i) {
return (arr[i] == 0 && arr[i-1] == 1 && arr[i+1] == 1);
}
public static ArrayList<Integer> countDisturbed(int []arr) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = 1; i < arr.length -1; i++) {
if (check(arr, i)) {
list.add(i);
}
}
return list;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
if (countDisturbed(arr).size() == 0) {
System.out.println("0");
}
else {
ArrayList<Integer> list = countDisturbed(arr);
int p = list.size();
int count = 0;
for (int i = 1; i < n-1; i++) {
if (arr[i] == 0) {
if (check(arr, i)) {
count += 1;
arr[i+1] = 0;
}
}
}
System.out.println(count);
}
}
} | Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | 05d1c1af34824b0efea6898669ed1913 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.util.*;
import java.lang.*;
//f
public class b_0112 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int[]b= new int[a];
int count = 0;
for (int i = 0; i <a ; i++) {
b[i] = in.nextInt();
}
for (int i = 4; i < a; i++) {
if(b[i-4] == 1 && b[i-3]==0 && b[i-2] == 1&& b[i-1]==0 && b[i] == 1){
b[i-2] = 0;
count++;
}
}
for (int i = 2; i < a; i++) {
if(b[i-2] == 1&& b[i-1]==0 && b[i] == 1){
count++;
}
}
System.out.println(count);
}
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | 964c925740d247791e841dbf555d726a | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes |
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
/**
*
* @author Pc
*/
public class Test1 {
public static Scanner in=new Scanner(System.in);
public static void main(String args[]){
int j=0;
int n=in.nextInt();
int t[]=new int[n];
for(int i=0;i<n;i++)
t[i]=in.nextInt();
for(int i=1;i<n-1;i++)
if(t[i]==0 && t[i+1]==1 &&t[i-1]==1)
{
t[i+1]=0;
j++;
i++;
}
System.out.println(j);
}
} | Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | 6fa7cf483c838868d0de2c530b61b217 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.io.BufferedReader;
import java.util.Arrays;
import java.io.InputStreamReader;
public class b{
public static void main(String[] args)throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String c[] = br.readLine().split(" ");
int ans = 0;
for(int i=0;i<n-2;i++){
if((c[i]+c[i+1]+c[i+2]).equals("101")){
c[i+2] = "0";
ans++;
}
}
System.out.println(ans);
}
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | 425598208582f7ef5ac7f059a0590f18 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.util.Scanner;
public class disturbed {
static boolean check(int arr[],int i) {
if(i==0)return false;
if(i==arr.length-1) return false;
if(arr[i]==0 && arr[i-1]==1 && arr[i+1]==1) return true;
return false;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if(n <3) {
}else {
int arr[] = new int[n];
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
int count = 0;
for (int i = 0; i < arr.length; i++) {
if(check(arr,i)) {
count++;
arr[i + 1] = 0;
}
}
System.out.println(count);
}
}
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | b902fa507cc3c77ddbeb55a2121cf556 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | /*
⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿
⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿
⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿
⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿
⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿
⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺
⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘
⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆
⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇
⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇
⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇
⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇
⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇
⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀
⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀
⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸
⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼
⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿
⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿
⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿
⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿
*/
import java.awt.List;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++) {
arr[i]=s.nextInt();
}
ArrayList<Integer> list=new ArrayList<>();
int count=0;
for(int i=0;i<=n-3;i++) {
if(arr[i]==1&&arr[i+1]==0&&arr[i+2]==1) {
count++;
i++;
}else {
list.add(count);
count=0;
}
}
list.add(count);
int ans=0;
for(int i=0;i<list.size();i++) {
if(list.get(i)==1) {
ans++;
}else if(list.get(i)>0) {
ans=ans+list.get(i)%2+list.get(i)/2;
}
}
System.out.println(ans);
}
} | Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | c2b247206eec13d27368c1798b4db33a | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.util.Scanner;
/**
* @author: zhaoqing
* @date: 2018/9/9
* @time: 下午9:37
*/
public class BDisturbedPeople {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
int a=-1;
int b=-1;
int c=-1;
int result=0;
for(int i=0;i<t;i++){
int n=sc.nextInt();
if(a==-1){
if(n==1){
a=n;
}
continue;
}
if(b==-1){
if(n==0){
b=n;
}
continue;
}
if(c==-1){
if(n==1){
result++;
}
a=-1;
b=-1;
c=-1;
continue;
}
}
System.out.println(result);
}
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | 10c9eb4354e9f881b6f763d72346ecea | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class A {
public static void main(String[] sachin32) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int arr[] = new int[n];
for(int i=0; i<n; i++) arr[i] = in.nextInt();
int cnt=0;
ArrayList<Integer> list = new ArrayList<Integer>();
for(int i=1; i<n-1; i++) {
if(arr[i-1]==1 && arr[i+1]==1 && arr[i]==0) {
cnt++;
list.add(i+1);
}
}
if(cnt==0) System.out.println(0);
else if(cnt==1) System.out.println(1);
else {
boolean L[] = new boolean[cnt];
Arrays.fill(L,false);
int ans=0;
for(int i=0; i<cnt-1; i++) {
if(!L[i]) {
L[i] = true; ans++;
if(list.get(i)+2==list.get(i+1)) {
L[i+1] = true;
}
}
}
for(int i=0; i<cnt; i++) {
if(!L[i]) ans++;
}
System.out.println(ans);
}
in.close();
}
static void exit() {
System.exit(0);
}
} | Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | 921f9f96bef02e324d8d7eae9f12d926 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
public class ProblemB {
public static void main(String[] args) throws IOException {
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader buffer = new BufferedReader(in);
String line = buffer.readLine();
Long number = Long.parseLong(line);
Scanner scanner;
ArrayList<Long> list = new ArrayList<Long>();
boolean prev = false;
boolean last= false;
boolean current;
line = buffer.readLine();
scanner = new Scanner(line);
for (long i = 0; i < number; i++) {
current = scanner.nextLong() == 1;
if (current && !last && prev && i > 1) {
list.add(i - 1);
}
prev = last;
last = current;
}
scanner.close();
long count = 0;
boolean skipNext = false;
for (int i = 0; i < list.size(); i++) {
if (skipNext) {
skipNext = false;
continue;
}
count++;
if (i == list.size() - 1) {
break;
}
if (list.get(i + 1) - list.get(i) == 2) {
skipNext = true;
}
}
System.out.println(count);
}
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | c876e9eff3e4d31beb9abd76462334f5 | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes | import java.util.Scanner;
public class CF2 {
public static void main (String [] args ) {
Scanner mos = new Scanner ( System.in ) ;
int a = mos.nextInt () ;
int c = 0 ;
int temp ;
int [] b = new int [a] ;
for ( int i = 0 ; i < b.length ; i ++ )
b [i] = mos.nextInt();
for ( int i = 0 ; i < b.length ; i++ )
for ( int j = 0 ; j < i ; j ++ ){
if ( b [ i ] < b [ j ]){
temp = b[i] ;
b[i] = b[j] ;
b[j] = temp ;
}
}
for ( int i = 1 ; i < b.length ; i++ ){
for ( int j = 0 ; j < i ; j ++ )
if ( b[i] == b[j]){
c ++ ;
}
if ( c == 0 ){
System.out.println( b[i] );
c++ ;
break ;
}
c = 0 ;
}
if ( c == 0 || b.length <= 1 )
System.out.println("NO");
}
}
| Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | db45e06a3087d9f0e0d2ee0db47956df | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes |
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import static java.util.Collections.list;
import java.util.List;
import java.util.Scanner;
/**
*
* @author hossam
*/
public class Ps {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n=in.nextInt(),g,k=-1;
boolean x=false;
ArrayList<Integer> a=new ArrayList(n);
for(int i=0;i<n;i++)
{
a.add(in.nextInt());
}
Collections.sort(a);
g=a.get(0);
for(int i=0;i<n;i++)
{
if(a.get(i)>g)
{ x=true;k=i;break;}
}
if(x==false)
System.out.println("NO");
else
System.out.println(a.get(k));
}
} | Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | e8892891e8c14bc0599f10ac50777bbc | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Fun {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Vector<Integer> list=new Vector<Integer>();
int num=sc.nextInt();
sc.nextLine();
String word=sc.nextLine();
Set<Integer> hs = new HashSet<>();
for(int i=0;i<num;i++){
String[] arr=word.split(" ");
int arr2=Integer.parseInt(arr[i]);
hs.add(arr2);
}
list.addAll(hs);
Collections.sort(list);
if(list.size()==1){
System.out.println("NO");
}else{
System.out.println(list.get(1));}
}
} | Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | 81eb80859ede03d76198c4438c4b5273 | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes |
import java.util.Arrays;
import java.util.Scanner;
public class Second_Order_Statistics {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int[] input = new int[N];
for (int i = 0; i < N; i++) {
input[i] = scan.nextInt();
}
Arrays.sort(input);
if (input.length > 1) {
int tmp = 0;
for (int i = 0; i < N - 1; i++) {
if (input[i] != input[i + 1]) {
tmp = input[i + 1];
break;
}
}
if (tmp == 0) {
System.out.println("NO");
} else
System.out.println(tmp);
}
else
System.out.println("NO");
}
} | Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | 7690f6be66c7dc46628de2c64e5625fa | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.PriorityQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedOutputStream;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Kattio in = new Kattio(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskAA solver = new TaskAA();
solver.solve(1, in, out);
out.close();
}
static class TaskAA {
public void solve(int testNumber, Kattio in, PrintWriter out) {
int n = in.nextInt();
HashSet<Integer> set = new HashSet<>();
PriorityQueue<Integer> q = new PriorityQueue<>();
for (int i = 0; i < n; ++i) {
int x = in.nextInt();
if (!set.contains(x)) {
set.add(x);
q.offer(x);
}
}
if (q.size() <= 1) {
out.println("NO");
} else {
q.poll();
out.println(q.peek());
}
}
}
static class Kattio extends PrintWriter {
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
public Kattio(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public Kattio(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null) return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) {
}
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
}
}
| Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | fbd20bbd53dc9e8d1ba16f8b580dcdd7 | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedOutputStream;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Kattio in = new Kattio(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskAA solver = new TaskAA();
solver.solve(1, in, out);
out.close();
}
static class TaskAA {
public void solve(int testNumber, Kattio in, PrintWriter out) {
int n = in.nextInt();
HashSet<Integer> set = new HashSet<>();
for (int i = 0; i < n; ++i)
set.add(in.nextInt());
int min = Integer.MAX_VALUE;
int ans = Integer.MAX_VALUE;
for (int i : set) {
min = Math.min(min, i);
}
for (int i : set) {
if (i > min)
ans = Math.min(ans, i);
}
out.println(ans == Integer.MAX_VALUE ? "NO" : ans);
}
}
static class Kattio extends PrintWriter {
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
public Kattio(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public Kattio(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null) return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) {
}
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
}
}
| Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | 354b3638b448e9c0b25662cb2a9f03f4 | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes |
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
/*
* 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 MuHamd Gomaa
*/
public class a22 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = in.nextInt();
Set s = new HashSet();
int arr[] = new int[num];
for (int i = 0; i < num; i++) {
arr[i] = in.nextInt();
s.add(arr[i]);
}
List sortedList = new ArrayList(s);
Collections.sort(sortedList);
if(sortedList.size()==1){
System.out.println("NO");
}else
System.out.println(sortedList.get(1));
}
}
| Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | 54a33592c359c9582759caa0f95daa58 | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
import java.util.*;
import java.math.*;
import java.io.*;
public class Main {
public static void main ( String args[] ) {
Scanner s = new Scanner(System.in);
int number = s.nextInt();
int[] secound = new int[number];
for(int i = 0 ;i <number ; i++){
secound[i] = s.nextInt();
}
Arrays.sort(secound);
int min = secound[0];
for(int i = 0 ;i <number ; i++){
if(secound[i]>min){
min = secound[i];
break;
}
}
System.out.print(min == secound[0] ? "NO" : min );
}
}
| Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | b7605dc1ed9e0eb5822fa8841a23425a | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes | import java.util.Iterator;
import java.util.Scanner;
import java.util.SortedSet;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scn=new Scanner(System.in);
int n=Integer.parseInt(scn.nextLine());
SortedSet<Integer> numbers=new TreeSet<Integer>();
for(int i=0; i<n; i++)
numbers.add(scn.nextInt());
scn.close();
/*Iterator<Integer> iter=numbers.iterator();
while(iter.hasNext())
System.out.println();*/
Object[] arr=numbers.toArray();
System.out.println(arr.length==1? "NO": arr[1]);
}
}
| Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | 86e9d2ca078d6a45ea24d4693e01e79a | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes | import java.util.Scanner;
public class acm22 {
public static void main(String[]args)
{
int hh=1;
int y=0;
Scanner a=new Scanner(System.in);
int b=a.nextInt();//amount of numbers
int[] number=new int [b];
for(int i=0;i<b;i++)
{
number[i]=a.nextInt();
}
if(b<=1)
{
System.out.println("NO");
}
else
{
for(int j=0;j<b;j++)
{
for(int h=0;h<b;h++)
{
if(number[j]<number[h])
{
y=number[j];
number[j]=number[h];
number[h]=y;
}
}
}
for(int z=1;z<b;z++)
{
if(number[0]==number[z])
{
hh++;
}
}
if(hh==b)
{
System.out.println("NO");
}
else
{
System.out.println(number[hh]);
}
}
}} | Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | 17c072d95fbbfcd9a33ae533ed8255c0 | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes | import java.util.Scanner;
public class acm22 {//accept
public static void main(String[]args)
{
int hh=1;
int y=0;
Scanner a=new Scanner(System.in);
int b=a.nextInt();//amount of numbers
int[] number=new int [b];
for(int i=0;i<b;i++)
{
number[i]=a.nextInt();
}
if(b<=1)
{
System.out.println("NO");
}
else
{
for(int j=0;j<b;j++)
{
for(int h=0;h<b;h++)
{
if(number[j]<number[h])
{
y=number[j];
number[j]=number[h];
number[h]=y;
}
}
}
for(int z=1;z<b;z++)
{
if(number[0]==number[z])
{
hh++;;
}
}
if(hh==b)
{
System.out.println("NO");
}
else
{
System.out.println(number[hh]);
}
}
}} | Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | 4588576694f1bb1eeb8b8b798308ecc2 | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes |
//import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
//import java.io.OutputStream;
import java.io.PrintWriter;
//import java.util.Scanner;
import java.util.Arrays;
import java.util.StringTokenizer;
//import jdk.nashorn.internal.runtime.regexp.joni.Option;
public class Codechef1 {
public static void main(String[] args) throws IOException {
FastReader in = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
int n = in.nextInt();
int n1=0,n2=0;
int a[] = new int[n];
int e=0,o=0;
for (int i = 0; i < n; i++) {
a[i]=in.nextInt();
}
Arrays.sort(a);
for (int i = 1; i < n; i++) {
if(a[i]!=a[i-1]){System.out.println(a[i]);return;}
}
System.out.println("NO");
pw.flush();
pw.close();
}
// a+=Integer.parseInt(String.valueOf(s.charAt(i)));
static class FastReader {
StringTokenizer st;
BufferedReader br;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() throws IOException {
if (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
public boolean hasNext() throws IOException {
if (st != null && st.hasMoreTokens()) {
return true;
}
String s = br.readLine();
if (s == null || s.isEmpty()) {
return false;
}
st = new StringTokenizer(s);
return true;
}
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 nextLine() throws IOException {
return br.readLine();
}
}
}
| Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | 27de044b8263acd617132f43270dd19d | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class SecondOrder {
public static void main(String[] args) {
Scanner input = new Scanner(System.in) ;
int size = input.nextInt() ;
int a [] = new int [size] ;
for(int i = 0 ; i < size ; i ++){
a[i] = input.nextInt() ;
}
if(size > 1) {
Arrays.sort(a);
int min1 = a[0] ;
boolean found = false ;
for(int i = 1 ; i < a.length ; i++){
if(a[i] > min1){
System.out.println(a[i]);
found = true ;
break ;
}
}
if(!found){
System.out.println("NO");
}
}else {
System.out.println("NO");
}
input.close();
}
}
| Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | a823c8c495f1a41b876427fcb2c568e8 | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 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.Collections;
import java.util.StringTokenizer;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
PrintWriter out=new PrintWriter(System.out);
int n=Integer.parseInt(reader.readLine());
StringTokenizer str=new StringTokenizer(reader.readLine());
// int a=Integer.parseInt(str.nextToken());
// int b=Integer.parseInt(str.nextToken());
// int[] arr=new int[n];
// str=new StringTokenizer(reader.readLine());
// for(int i=0;i<n;i++)
// {
// arr[i]=Integer.parseInt(str.nextToken());
// }
ArrayList<Integer> arr=new ArrayList<>();
for(int i=0;i<n;i++)
{
int num=Integer.parseInt(str.nextToken());
if(arr.isEmpty() || !arr.contains(num)){
arr.add(num);
}
}
Collections.sort(arr);
if(arr.size()>1){
out.println(arr.get(1));
}
else{
out.println("NO");
}
out.close();
reader.close();
}
} | Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | b7198849c0919cf5086912c946002f8f | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class Solution2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int min = 101;
int max = -101;
ArrayList<Integer> a = new ArrayList<>();
for (int i = 0; i < n; i++) {
int ai = sc.nextInt();
min = ai < min ? ai : min;
max = ai > max ? ai : max;
a.add(ai);
}
if (min == max) {
System.out.println("NO");
} else {
int second_order = 101;
for (int i = 0; i < a.size(); i++) {
int ai = a.get(i);
if (ai != min && ai < second_order) {
second_order = ai < second_order ? ai : second_order;
}
}
System.out.println(second_order);
}
sc.close();
}
} | Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | cf3a59c540e882f41cddccc5091cbe6c | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int x = input.nextInt();
int z, num1 = 0, num2 = 0;
int[] arr = new int[x];
for (int i = 0; i < x; i++) {
int y = input.nextInt();
arr[i] = y;
}
for (int j = 0; j < arr.length - 1; j++) {
for (int k = j + 1; k < arr.length; k++) {
if (arr[j] > arr[k]) {
z = arr[j];
arr[j] = arr[k];
arr[k] = z;
}
}
}
if (arr.length == 1) {
System.out.println("NO");
} else {
for (int c = 0; c < arr.length - 1; c++) {
if (arr[c] == arr[c + 1]) {
if (arr[c + 1] == arr[arr.length - 1]) {
System.out.println("NO");
break;
} else {
continue;
}
} else if (arr[c + 1] > arr[c]) {
System.out.println(arr[c + 1]);
break;
} else {
continue;
}
}
input.close();
}
}
}
| Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | 1a6fdf329f46a3fd91ddbc00ae6fd02c | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes |
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;
import javax.lang.model.type.ArrayType;
public class Main {
static void sapxep(int[] A, int n) {
int tg;
int i, j;
for (i = 0; i < n; i++) {
for (j = i; j < n; j++) {
if (A[i] > A[j]) {
tg = A[i];
A[i] = A[j];
A[j] = tg;
}
}
}
}
public static void main(String[] args) {
Scanner ip = new Scanner(System.in);
int n;
int A[] = new int[120];
n = ip.nextInt();
for (int i = 0; i < n; i++) {
A[i] = ip.nextInt();
}
sapxep(A, n);
int a = A[0];
int dem =0;
int flag = 0;
for (int i : A) {
if (i != a && dem <n) {
System.out.println(i);
flag=1;
break;
}
dem++;
}
if (flag == 0) {
System.out.println("NO");
}
}
}
| Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | a282a06967a0e4cb838c7eebf5598b69 | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes |
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
/* Name of the class has to be "Main" only if the class is public. */
public class bbg
{
public static int result;
public static ArrayList<Integer> [] graph;
public static int[]cats;
public static int vizitat[];
public static int x;
//public static HashMap<String, Integer> map2;
public static void main (String[] args) throws java.lang.Exception
{
Scanner input=new Scanner(System.in);
HashMap<Integer, Integer> contor1= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> contor2= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> map= new HashMap<Integer, Integer>();
HashMap<String, Integer> curatare= new HashMap<String, Integer>();
HashMap<String, Integer> combinari= new HashMap<String, Integer>();
int n=input.nextInt();
for(int i=0;i<n;i++) {int a=input.nextInt();
if(!map.containsKey(a)) map.put(a,1);
}
int v[]=new int[map.size()];
int contor=-1;
for(int x:map.keySet()){contor++; v[contor]=x;}
Arrays.sort(v);
if(contor>0) System.out.println(v[1]);
else System.out.println("NO");
}
}
| Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | f14e51e97d0f9bd8956482f3e9d65ee5 | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes | import java.util.*;
public class SecondOrderStatistics {
public static void main(String[] args)
{
int a[] = new int[100];
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=0;i<n;i++)
{
a[i] = sc.nextInt();
}
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
int aux=a[i];
a[i]=a[j];
a[j]=aux;
}
}
int contor;
for(contor=0;contor<n;)
{
if(contor==n-1)
{
System.out.println("NO");
break;
}
if(a[contor]==a[contor+1])
contor++;
else
{
System.out.println(a[contor+1]);
break;
}
}
}
}
| Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | abb25e081bd93387150ccc67eed48ac9 | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes | import static java.lang.System.*;
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(in);
int n = sc.nextInt();
ArrayList<Integer> set = new ArrayList<Integer>();
for(int x=0;x<n;x++) {
int num = sc.nextInt();
if(!set.contains(num))
set.add(num);
}
Collections.sort(set);
if(set.size()>=2)
out.println(set.get(1));
else
out.println("NO");
}
} | Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | 78341aecfe5061df6e0694db804abdbe | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.StringTokenizer;
public class Mac
{
static String newString;
public static void main (String[] args) throws IOException
{
BufferedReader in;
in =new BufferedReader(new InputStreamReader(System.in));
int N=Integer.parseInt(in.readLine());
int A[];
int x=0;
HashSet<Integer> st=new HashSet<>();
StringTokenizer input=new StringTokenizer(in.readLine());
while (input.hasMoreTokens())
{
st.add(Integer.parseInt(input.nextToken()));
}
A=new int [st.size()];
Iterator it=st.iterator();
while (it.hasNext())
{
A[x]=(int)it.next();
x++;
}
Arrays.sort(A);
if (A.length>1)
System.out.println(A[1]);
else
System.out.println("NO");
}
} | Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | 19ea4d6ad73c055c56d8d9d29b16443d | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes | import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
public class Bob {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int j;
HashSet<Integer> a = new HashSet<>();
for (j = 0; j < n; j++) {
a.add(sc.nextInt());
}
if (a.size() == 1) {
System.out.println("NO");
} else {
ArrayList l = new ArrayList(a);
Collections.sort(l);
int min = (int) Collections.min(l);
int index = l.indexOf(min);
int ans = index + 1;
System.out.println(l.get(ans));
}
}
}
| Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | 4b35251867af9f5ff503449ff7693d15 | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class SecondOrderStatistics {
public static void main(String[] args) {
BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
String input = null;
try {
input = scan.readLine();
} catch (Exception e) {
e.printStackTrace();
}
int number = Integer.parseInt(input);
try {
input = scan.readLine();
} catch (IOException e) {
e.printStackTrace();
}
int chosen = 1000000;
String[] stas = input.split(" ");
if (stas.length < 2) {
System.out.println("NO");
} else {
int min = Integer.parseInt(stas[0]);
for (int i = 1; i < stas.length; i++) {
if (Integer.parseInt(stas[i]) < min) {
min = Integer.parseInt(stas[i]);
}
}
for (int i = 0; i < stas.length; i++) {
if (Integer.parseInt(stas[i]) > min && Integer.parseInt(stas[i]) < chosen) {
chosen = Integer.parseInt(stas[i]);
}
}
if (chosen == min || chosen == 1000000) {
System.out.println("NO");
} else {
System.out.println(chosen);
}
}
}
}
| Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | e4d4fc8e7887e76cdc5cd4c26864a087 | train_001.jsonl | 1277823600 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
if(n == 1)
{
System.out.println("NO");
return;
}
else
{
int p = 1;
for(int i = 0;i<n;i++)
{
a[i] = sc.nextInt();
}
Arrays.sort(a);
for(int j = 0,l = 1;j < n & l < n;j++,l++)
{
if(a[j] == a[l])
{
p++;
}
}
if(p == n)
{
System.out.println("NO");
return;
}
int ans = 0;
for(int i= 0,j = 1;i < n & j < n;i++,j++)
{
if(a[i] != a[j])
{
System.out.println(a[j]);
return;
}
}
}
}
} | Java | ["4\n1 2 2 -4", "5\n1 2 3 1 1"] | 2 seconds | ["1", "2"] | null | Java 8 | standard input | [
"brute force"
] | 930be5ec102fbe062062aa23eac75187 | The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | 800 | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | standard output | |
PASSED | f433b5fc9d2c61d6b7930e776dc22074 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class G {
public static void main(String[] args) throws IOException {
//PrintWriter out = new PrintWriter(new File("out.txt"));
PrintWriter out = new PrintWriter(System.out);
//Reader in = new Reader(new FileInputStream("in.txt"));
Reader in = new Reader();
G solver = new G();
solver.solve(out, in);
out.flush();
out.close();
}
static int maxn = 5*(int)1e5+5;
static long mod=(int)1e9+7;
static int n, m, t, k, q;
void solve(PrintWriter out, Reader in) throws IOException{
k = in.nextInt();
int p = 1;
while (p <= k) p*=2;
out.println("3 3");
out.println((p+k)+" "+p+" "+p);
out.println(k+" "+p+" "+p);
out.println(k+" "+(p+k)+" "+k);
}
//<>
static class Reader {
private InputStream mIs;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public Reader() {
this(System.in);
}
public Reader(InputStream is) {
mIs = is;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = mIs.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
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 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();
}
double nextDouble()
{
return Double.parseDouble(next());
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
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 | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | df03d2ae5d01c9f982a332e2708e9aed | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.*;
import java.io.*;
public class d {
static final int m = 18, a = (1 << m) - 1, b = 1 << (m - 1), c = (1 << (m - 1)) - 1;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k = sc.nextInt();
System.out.println("2 3");
System.out.println(a + " " + b + " 0");
System.out.println(c + " " + a + " " + k);
}
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 e) {}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 06ef07f9827013670729b593567fe18f | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.*;
import java.util.*;
import java.lang.*;
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);
solve(in, out);
out.close();
}
static int L,R,top,bottom;
// static int ans;
public static void solve(InputReader sc, PrintWriter pw) {
// int t=sc.nextInt();
int t=1;
u:while(t-->0){
int k=sc.nextInt();
int n=1;
while(n<=k)
n<<=1;
pw.println(3+" "+2);
pw.println((n+k)+" "+k);
pw.println(n+" "+(n+k));
pw.println(n+" "+k);
}
}
public static void swap(char []chrr, int i, int j){
char temp=chrr[i];
chrr[i]=chrr[j];
chrr[j]=temp;
}
public static int num(int n){
int a=0;
while(n>0){
a+=(n&1);
n>>=1;
}
return a;
}
static class Pair{
long u, v;
Pair(long a,long b){
this.u=a;
this.v=b;
}
}
// public int compareTo(Pair p){
// return (b-p.b);
// }
// public int hashCode(){
// int hashcode = (a+" "+b).hashCode();
// return hashcode;
// }
// public boolean equals(Object obj){
// if (obj instanceof Pair) {
// Pair p = (Pair) obj;
// return (p.a==this.a && p.b == this.b);
// }
// return false;
// }
static boolean isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static int gcd(int a, int b) {
if (b == 0)
return a;
return a>b?gcd(b, a % b):gcd(a, b % a);
}
static long fast_pow(long base,long n,long M){
if(n==0)
return 1;
if(n==1)
return base;
long halfn=fast_pow(base,n/2,M);
if(n%2==0)
return ( halfn * halfn ) % M;
else
return ( ( ( halfn * halfn ) % M ) * base ) % M;
}
static long modInverse(long n,long M){
return fast_pow(n,M-2,M);
}
public static void feedArr(long []arr,InputReader sc){
for(int i=0;i<arr.length;i++)
arr[i]=sc.nextLong();
}
public static void feedArr(double []arr,InputReader sc){
for(int i=0;i<arr.length;i++)
arr[i]=sc.nextDouble();
}
public static void feedArr(int []arr,InputReader sc){
for(int i=0;i<arr.length;i++)
arr[i]=sc.nextInt();
}
public static void feedArr(String []arr,InputReader sc){
for(int i=0;i<arr.length;i++)
arr[i]=sc.next();
}
public static String printArr(int []arr){
StringBuilder sbr=new StringBuilder();
for(int i:arr)
sbr.append(i+" ");
return sbr.toString();
}
public static String printArr(long []arr){
StringBuilder sbr=new StringBuilder();
for(long i:arr)
sbr.append(i+" ");
return sbr.toString();
}
public static String printArr(String []arr){
StringBuilder sbr=new StringBuilder();
for(String i:arr)
sbr.append(i+" ");
return sbr.toString();
}
public static String printArr(double []arr){
StringBuilder sbr=new StringBuilder();
for(double i:arr)
sbr.append(i+" ");
return sbr.toString();
}
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 int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | e500f64037266dcfb790a74df09df449 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.*;
import java.io.*;
public class Main
{
public static void main(String []args) throws IOException {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
solve(in, out);
in.close();
out.close();
}
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); }
private static int fact(int n) { int ans=1; for(int i=2;i<=n;i++) ans*=i; return ans; }
static class FastScanner{
BufferedReader reader;
StringTokenizer st;
FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
String nextLine() {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
int nextInt() {return Integer.parseInt(next());}
long nextLong() {return Long.parseLong(next());}
double nextDouble(){return Double.parseDouble(next());}
char nextChar() {return next().charAt(0);}
int[] nextIntArray(int n) {int[] arr= new int[n]; int i=0;while(i<n){arr[i++]=nextInt();} return arr;}
long[] nextLongArray(int n) {long[]arr= new long[n]; int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
int[] nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
void close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
}
/********* SOLUTION STARTS HERE ************/
private static void solve(FastScanner in, PrintWriter out){
int k = in.nextInt();
out.println("2 3");
out.println((1<<17)+k+" "+k+" 0");
out.println((1<<17) + " "+((1<<17)+k)+" "+k);
}
/************* SOLUTION ENDS HERE **********/
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 219c241d9e0313151cbc574ac51ff7c2 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.*;
import java.io.*;
public class EdE {
static long[] mods = {1000000007, 998244353, 1000000009};
static long mod = mods[0];
public static MyScanner sc;
public static PrintWriter out;
public static void main(String[] omkar) throws Exception{
// TODO Auto-generated method stub
sc = new MyScanner();
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
out.println("2 3");
int power2 = 1;
while(power2 <= n)
power2*=2;
out.println((2*power2-1) + " " + n + " " + 0);
out.println(power2 + " " + (2*power2-1) + " " + n);
out.println();
out.close();
}
public static void sort(int[] array){
ArrayList<Integer> copy = new ArrayList<Integer>();
for (int i : array)
copy.add(i);
Collections.sort(copy);
for(int i = 0;i<array.length;i++)
array[i] = copy.get(i);
}
static String[] readArrayString(int n){
String[] array = new String[n];
for(int j =0 ;j<n;j++)
array[j] = sc.next();
return array;
}
static int[] readArrayInt(int n){
int[] array = new int[n];
for(int j = 0;j<n;j++)
array[j] = sc.nextInt();
return array;
}
static int[] readArrayInt1(int n){
int[] array = new int[n+1];
for(int j = 1;j<=n;j++){
array[j] = sc.nextInt();
}
return array;
}
static long[] readArrayLong(int n){
long[] array = new long[n];
for(int j =0 ;j<n;j++)
array[j] = sc.nextLong();
return array;
}
static double[] readArrayDouble(int n){
double[] array = new double[n];
for(int j =0 ;j<n;j++)
array[j] = sc.nextDouble();
return array;
}
static int minIndex(int[] array){
int minValue = Integer.MAX_VALUE;
int minIndex = -1;
for(int j = 0;j<array.length;j++){
if (array[j] < minValue){
minValue = array[j];
minIndex = j;
}
}
return minIndex;
}
static int minIndex(long[] array){
long minValue = Long.MAX_VALUE;
int minIndex = -1;
for(int j = 0;j<array.length;j++){
if (array[j] < minValue){
minValue = array[j];
minIndex = j;
}
}
return minIndex;
}
static int minIndex(double[] array){
double minValue = Double.MAX_VALUE;
int minIndex = -1;
for(int j = 0;j<array.length;j++){
if (array[j] < minValue){
minValue = array[j];
minIndex = j;
}
}
return minIndex;
}
static long power(long x, long y){
if (y == 0)
return 1;
if (y%2 == 1)
return (x*power(x, y-1))%mod;
return power((x*x)%mod, y/2)%mod;
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
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;
}
}
}
//StringJoiner sj = new StringJoiner(" ");
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 3f6c567bb49ae0f005705f1f165c2c24 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k = Integer.parseInt(sc.next());
int n = 3;
int m = 3;
int[][] a = new int[n+1][m+1];
a[1][1] = 262143; a[1][2] = 131071; a[1][3] = 0;
a[2][1] = 131072; a[2][2] = 131071; a[2][3] = 131071-k;
a[3][1] = 262143; a[3][2] = 262143; a[3][3] = 131071;
System.out.println(n + " " + m);
System.out.println(a[1][1] + " " + a[1][2] + " " + a[1][3]);
System.out.println(a[2][1] + " " + a[2][2] + " " + a[2][3]);
System.out.println(a[3][1] + " " + a[3][2] + " " + a[3][3]);
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 6961a860f17875f6a710c499edc364e6 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.*;
import java.io.*;
import java.security.acl.Owner;
public class codeforces {
public static void main(String[] args) throws Exception {
int n=sc.nextInt();
int infinity=262143;
int smaller_infinity=131072;
int N=infinity^n;
pw.println(2+" "+3);
pw.println(infinity+" "+N+" "+infinity);
pw.println(n+" "+infinity+" "+n);
pw.close();
}
static class Scanner {
private InputStream in;
private byte[] buffer = new byte[1024];
private int curbuf;
private int lenbuf;
public Scanner(InputStream in) {
this.in = in;
this.curbuf = this.lenbuf = 0;
}
public boolean hasNextByte() {
if (curbuf >= lenbuf) {
curbuf = 0;
try {
lenbuf = in.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return false;
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[curbuf++];
else
return -1;
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private void skip() {
while (hasNextByte() && isSpaceChar(buffer[curbuf]))
curbuf++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (!isSpaceChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
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;
}
}
static class pair implements Comparable<pair> {
int x;
int y;
public pair(int x, int y) {
this.x = x;
this.y = y;
}
public String toString() {
return x + " " + y;
}
public int compareTo(pair other) {
if (this.x == other.x) {
return this.y - other.y;
} else {
return 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) {
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, int e, int mod) // O(log e)
{
a %= mod;
long res = 1;
while (e > 0) {
if ((e & 1) == 1)
res = (res * a) % mod;
a = (a * a) % mod;
e >>= 1;
}
return res;
}
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;
}
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];
}
public static void PH(String s, boolean reverse) {
prelen = s.length();
HashsArray[HashsArrayInd] = new int[prelen + 1];
prepow = new int[prelen];
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[0] = 1;
if (!reverse) {
for (int i = 1; i < prelen; i++) {
prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod);
}
for (int i = 0; i < prelen; i++) {
if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z')
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - 'a' + 1) * prepow[i]) % mod) % mod);
else if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z')
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - 'A' + 27) * prepow[i]) % mod) % mod);
else
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - '0' + 1) * prepow[prelen - 1 - i]) % mod) % mod);
}
} else {
for (int i = 1; i < prelen; i++) {
prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod);
}
for (int i = 0; i < prelen; i++) {
if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z')
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - 'a' + 1) * prepow[prelen - 1 - i]) % mod) % mod);
else if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z')
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - 'A' + 27) * prepow[prelen - 1 - i]) % mod) % mod);
else
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - '0' + 1) * prepow[prelen - 1 - i]) % mod) % mod);
}
}
HashsArrayInd++;
}
public static int PHV(int l, int r, int n, boolean reverse) {
if (l > r) {
return 0;
}
int val = (int) ((1l * HashsArray[n - 1][r] + mod - HashsArray[n - 1][l - 1]) % mod);
if (!reverse) {
val = (int) ((1l * val * prepow[prelen - l]) % mod);
} else {
val = (int) ((1l * val * prepow[r - 1]) % mod);
}
return val;
}
static int[][] HashsArray;
static int HashsArrayInd = 0;
static int[] prepow;
static int prelen = 0;
static int prime = 31;
static long fac[];
static int mod = 998244353;
static Random rn = new Random();
static Scanner sc = new Scanner(System.in);
static PrintWriter pw = new PrintWriter(System.out);
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | d3e1fc55237a9c9352447e69756b215c | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.*;
public class Main {
static class UnionFind {
List<Integer> Parent;
UnionFind(int N) {
Parent = new ArrayList<Integer>();
Integer[] values = new Integer[N];
Arrays.fill(values, -1);
Parent.addAll(Arrays.asList(values));
}
int root(int A) {
if (Parent.get(A) < 0)
return A;
int root = root(Parent.get(A));
Parent.set(A, root);
return root;
}
int size(int A) {
return -Parent.get(root(A));
}
boolean connect(int A, int B) {
A = root(A);
B = root(B);
if (A == B) {
return false;
}
if (size(A) < size(B)) {
int temp = A;
A = B;
B = temp;
}
Parent.set(A, Parent.get(A) + Parent.get(B));
Parent.set(B, A);
return true;
}
}
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
int k = in.nextInt();
int INF = 1<<17;
out.println("4 3");
out.println((INF+k)+" "+INF+" "+INF);
out.println((INF+k)+" "+k+" "+(INF+k));
out.println((INF+k)+" "+INF+" "+k);
out.println(INF+" "+INF+" "+k);
out.close();
}
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 int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 313038763b2b0b0538f690d2556aaf1e | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | //make sure to make new file!
import java.io.*;
import java.util.*;
public class D630{
public static void main(String[] args)throws IOException{
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int k = Integer.parseInt(f.readLine());
int N = 3;
out.println(N + " " + N);
int bb = biggestbit(k)/2;
out.println((k+bb*2) + " " + (bb*2) + " 0");
out.println(k + " " + (k+bb*2) + " 0");
out.println("0 " + k + " " + k);
out.close();
}
public static int biggestbit(int i){
if (i == 0)
return 0;
int msb = 0;
while (i != 0)
{
i = i / 2;
msb++;
}
return (1 << msb);
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 1331c8f340660d6a14b1aa4e8ff1c1af | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | /* / フフ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ム
/ )\⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ Y
(⠀⠀| ( ͡° ͜ʖ ͡°)⠀⌒(⠀ ノ
(⠀ ノ⌒ Y ⌒ヽ-く __/
| _⠀。ノ| ノ。 |/
(⠀ー '_人`ー ノ
⠀|\  ̄ _人'彡ノ
⠀ )\⠀⠀ 。⠀⠀ /
⠀⠀(\⠀ #⠀ /
⠀/⠀⠀⠀/ὣ====================D-
/⠀⠀⠀/⠀ \ \⠀⠀\
( (⠀)⠀⠀⠀⠀ ) ).⠀)
(⠀⠀)⠀⠀⠀⠀⠀( | /
|⠀ /⠀⠀⠀⠀⠀⠀ | /
[_] ⠀⠀⠀⠀⠀[___] */
// 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;
//Euclidean Algorithm
static long gcd(long A,long B){
return (B==0)?A:gcd(B,A%B);
}
//Modular Exponentiation
static long fastExpo(long x,long n){
if(n==0) return 1;
if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;
return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;
}
//Modular Inverse
static long inverse(long x) {
return fastExpo(x,MOD-2);
}
//Prime Number Algorithm
static boolean isPrime(long n){
if(n<=1) return false;
if(n<=3) return true;
if(n%2==0 || n%3==0) return false;
for(int i=5;i*i<=n;i+=6) if(n%i==0 || n%(i+2)==0) return false;
return true;
}
//Reverse an array
static void reverse(int arr[],int l,int r){
while(l<r) {
int tmp=arr[l];
arr[l++]=arr[r];
arr[r--]=tmp;
}
}
//Print array
static void print1d(int arr[]) {
out.println(Arrays.toString(arr));
}
static void print2d(int arr[][]) {
for(int a[]: arr) out.println(Arrays.toString(a));
}
// Pair
static class pair{
int x,y,z;
pair(int a,int b,int c){
this.x=a;
this.y=b;
this.z=c;
}
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 && this.z==p.z);
}
public int hashCode() {
return Objects.hash(x,y,z);
}
}
static FastReader sc=new FastReader();
static PrintWriter out=new PrintWriter(System.out);
//Main function(The main code starts from here
public static void main (String[] args) throws java.lang.Exception {
int test;
test=1;
//test=sc.nextInt();
while(test-->0){
int k=sc.nextInt();
int a=(1<<18)-1,d=a,b=k;
int c=(1<<((int)(Math.log(k)/Math.log(2))+1));
int e=0,f=k;
out.println("3 2");
out.println(a+" "+b);
out.println(c+" "+d);
out.println(e+" "+f);
}
out.flush();
out.close();
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 0ddac790701cd8b480913b9a70d2c531 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.*;
import java.io.*;
public class Main
{
public static void main(String fgfg[])throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw=new PrintWriter(System.out);
int k=Integer.parseInt(br.readLine());
pw.println("2 3");
pw.println(((int)Math.pow(2,17)+k)+" "+(int)Math.pow(2,17)+" 0");
pw.println(k+" "+((int)Math.pow(2,17)+k)+" "+k);
pw.flush();
pw.close();
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | bdd63693d9e85be8019e27089f8f15e6 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.*;
import java.util.*;
public class tr2 {
static PrintWriter out;
static StringBuilder sb;
static long mod = 1000000007;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
out = new PrintWriter(System.out);
int k = sc.nextInt();
if (k == 0) {
System.out.println(1 + " " + 1);
System.out.println(5);
return;
}
int x = 0;
int mx = 0;
int big = 0;
for (int i = 0; i < 20; i++)
if ((k & (1 << i)) == 0) {
x = 1 << i;
break;
}
mx = x | k;
int p = (int) (Math.log(mx) / Math.log(2));
big = 1 << (p + 1);
int st = big | mx;
//System.out.println(x + " " + mx + " " + big + " " + st);
out.println(3 + " " + 4);
out.println(st + " " + mx + " " + mx + " " + mx);
out.println(big + " " + mx + " " + mx + " " + x);
out.println(big + " " + big + " " + st + " " + mx);
// out.println(big+" "+mx+" "+mx+" "+mx);
out.flush();
}
static 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 char nextChar() throws IOException {
return next().charAt(0);
}
public Long nextLong() throws IOException {
return Long.parseLong(next());
}
public boolean ready() throws IOException {
return br.ready();
}
public void waitForInput() throws InterruptedException {
Thread.sleep(3000);
}
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 8bbd252d7ab2ed4c41a16c6e2e778132 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
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;
FastReader in = new FastReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
DWalkOnMatrix solver = new DWalkOnMatrix();
solver.solve(1, in, out);
out.close();
}
static class DWalkOnMatrix {
public void solve(int testNumber, FastReader s, PrintWriter w) {
int k = s.nextInt(), t = k;
ArrayList<Integer> unset = new ArrayList<>();
for (int i = 0; i < 18; i++) {
if ((t & 1) == 0) unset.add(i);
t >>= 1;
}
int[][] ans = new int[3][3];
ans[0][0] = (1 << 18) - 1;
ans[0][1] = ans[0][0];
for (int i : unset) ans[0][1] ^= 1 << i;
ans[1][0] = 1 << 17;
ans[1][1] = ans[0][0];
ans[1][2] = ans[0][1];
ans[2][2] = ans[0][1];
/*int ans1=ans[0][0]&ans[1][0], ans2=ans[0][0]&ans[0][1];
w.println(ans1+" "+ans2);
ans1&=ans[1][1];
ans2&=ans[1][1];
w.println(ans1+" "+ans2);*/
w.println(3 + " " + 3);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) w.print(ans[i][j] + " ");
w.println();
}
}
}
static class FastReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private FastReader.SpaceCharFilter filter;
public FastReader(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 - '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);
}
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 78a5b2e6613c38ba01b21424ea5e1aab | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | //created by Whiplash99
import java.io.*;
import java.util.*;
public class D
{
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,N,M;
int K=Integer.parseInt(br.readLine().trim());
N=M=3;
int a[][]=new int[N][M];
int num=1;
while (num<=K) num*=2;
a[0][0]=num*2-1;
a[0][1]=num-1;
a[0][2]=0;
a[1][0]=num;
a[1][1]=num-1;
a[1][2]=(num-1)-K;
a[2][0]=num;
a[2][1]=num*2-1;
a[2][2]=num-1;
System.out.println(N+" "+M);
for(i=0;i<N;i++)
{
for(int j=0;j<M;j++)
System.out.print(a[i][j]+" ");
System.out.println();
}
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 5aaa05e3ab069af391d8c5d0dc743299 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | //package Round630;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
/**
* @author sguar <shugangcao@gmail.com>
* strive for greatness
* Created on 2020-01-10
*/
public class D {
InputStream is;
PrintWriter out;
private static final String INPUT_FILE_NAME = "/Users/sguar/IdeaProjects/kotlinLearn/src/input.txt";
void solve() {
int k = ni();
int ans = 1;
while (ans <= k) {
ans = ans * 2;
}
int [][] map = new int[5][5];
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
map[i][j] = ans + k;
}
}
map[0][1] = ans;
map[1][0] = k;
map[4][4] = k;
out.println("5 5");
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
out.print(map[i][j] + " ");
}
out.println("");
}
}
void solveDP() {
int n = ni();
int m = ni();
int [][] a = new int[n + 1][m + 1];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
a[i][j] = ni();
}
}
int [][] dp = new int[n + 1][m + 1];
dp[0][1] = a[1][1];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
dp[i][j] = Math.max(dp[i - 1][j] & a[i][j], dp[i][j - 1] & a[i][j]);
}
}
debug(dp);
}
class Pair {
int x;
int y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return "x: " + x + ", y: " + y;
}
}
public static long invl(long a, long mod) {
long b = mod;
long p = 1, q = 0;
while (b > 0) {
long c = a / b;
long d;
d = a;
a = b;
b = d % b;
d = p;
p = q;
q = d - c * q;
}
return p < 0 ? p + mod : p;
}
void run() throws Exception {
is = oj ? System.in : new FileInputStream(INPUT_FILE_NAME);
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
debug(System.currentTimeMillis() - s + "ms");
}
public static void main(String[] args) throws Exception {
new D().run();
}
private byte[] inbuf = new byte[1024];
int lenbuf = 0;
int 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 boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void debug(Object... o) {
if (!oj) System.out.println(Arrays.deepToString(o));
}
private void debug(Object a, Object o) {
if (!oj) {
System.out.println(a.toString() + ": " + o.toString());
}
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | d7d2e4ee8214ec93c91ff1a8bcbf6bad | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author 404: Error Not Found
*/
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);
DWalkOnMatrix solver = new DWalkOnMatrix();
solver.solve(1, in, out);
out.close();
}
static class DWalkOnMatrix {
public void solve(int testNumber, InputReader c, OutputWriter w) {
int k = c.readInt();
int n = 500, m = 500;
int res[][] = new int[n][m];
res[0][0] = k | 131072;
for (int i = 1; i < m; i++) {
res[0][i] = res[0][0];
}
res[0][m - 1] = k;
for (int j = 1; j < n; j++) {
res[j][m - 1] = res[0][0];
}
res[n - 1][m - 1] = k;
int aa = res[0][0] ^ k;
for (int i = 1; i < n; i++) {
for (int j = 0; j < m - 1; j++) {
res[i][j] = aa;
}
}
w.printLine(n, m);
for (int i = 0; i < n; i++) {
w.printLine(res[i]);
}
//
// int dp[][] = new int[n][m];
// for(int i=0;i<n;i++) {
// for(int j=0;j<m;j++) {
// if(i == 0 && j == 0) {
// dp[i][j] = res[i][j];
// }
// else if(i == 0) {
// dp[i][j] = res[i][j]&dp[i][j-1];
// } else if (j == 0) dp[i][j] = res[i][j]&dp[i-1][j];
// else dp[i][j] = max(dp[i-1][j]&res[i][j],dp[i][j-1]&res[i][j]);
// }
// }
// w.printLine(dp[n-1][m-1]);
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.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);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void print(int[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void printLine(int[] array) {
print(array);
writer.println();
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | ac46918a14f9645c7cd2bedf56d12ae1 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.Scanner;
public class a {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int k = in.nextInt();
int max = 1 << 17;
System.out.println("" + 2 + " " + 3);
System.out.println("" + (max + k) + " " + k + " " + 0);
System.out.println("" + max + " " + (max + k) + " " + k);
in.close();
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 13750e03dd145020010d064b89d24c5c | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.*;
import java.util.*;
public class MainClass
{
public static void main(String[] args)throws IOException
{
Reader in = new Reader();
int k = in.nextInt();
StringBuilder stringBuilder = new StringBuilder();
if (k == 0)
{
stringBuilder.append("1 1\n1");
}
else
{
int u = (1 << 17) - 1;
int v = (1 << 18) - 1;
int[][] A = {{v, u, 0},
{u + 1, u, u - k},
{v, v, u}};
stringBuilder.append("3 3\n");
for (int i=0;i<3;i++)
{
for (int j=0;j<3;j++)
stringBuilder.append(A[i][j]).append(" ");
stringBuilder.append("\n");
}
}
System.out.println(stringBuilder);
}
}
class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 9910aa63ba0e464e475d6fdc2546bbc0 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 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_630_Div2 {
public static long MOD = 998244353;
public static void main(String[] args) throws FileNotFoundException {
// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
// "output.txt")));
PrintWriter out = new PrintWriter(System.out);
Scanner in = new Scanner();
int k = in.nextInt();
if (k == 0) {
out.println("1 1");
out.println(1);
} else {
int v = max(k);
out.println("2 3");
int[][] result = new int[2][3];
result[0][0] = (v | k);
result[1][0] = v;
result[0][1] = k;
result[1][1] = (v | k);
result[1][2] = k;
for (int i = 0; i < result.length; i++) {
for (int j = 0; j < result[i].length; j++) {
out.print(result[i][j] + " ");
}
out.println();
}
}
out.close();
}
static int max(int v) {
int result = Integer.highestOneBit(v);
return (result) << 1;
}
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 Integer.compare(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, int b) {
if (b == 0) {
return 1;
}
if (b == 1) {
return a;
}
long val = pow(a, b / 2);
if (b % 2 == 0) {
return val * val;
} else {
return val * (val * a);
}
}
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 | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 3e2030da65bf7b128b45ce5817e3ab9f | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 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_630_Div2 {
public static long MOD = 998244353;
public static void main(String[] args) throws FileNotFoundException {
// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
// "output.txt")));
PrintWriter out = new PrintWriter(System.out);
Scanner in = new Scanner();
int k = in.nextInt();
if(k == 0){
out.println("1 1");
out.println(1);
}else {
int v = max(k);
out.println("3 3");
int[][]result = new int[3][3];
result[0][0] = (v | k);
result[1][0] = v;
result[0][1] = k;
result[1][1] = k;
for(int i = 0; i < 2; i++){
result[2][i] = (v | k);
}
result[2][2] = k;
for(int i = 0; i < result.length; i++){
for(int j = 0; j < result[i].length; j++){
out.print(result[i][j] + " ");
}
out.println();
}
}
out.close();
}
static int max(int v){
int result = Integer.highestOneBit(v);
return (result) << 1;
}
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 Integer.compare(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, int b) {
if (b == 0) {
return 1;
}
if (b == 1) {
return a;
}
long val = pow(a, b / 2);
if (b % 2 == 0) {
return val * val;
} else {
return val * (val * a);
}
}
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 | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | c14414e7bf2b1d245371cd8806e86ed7 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes |
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class WalkOnMatrix implements Closeable {
private InputReader in = new InputReader(System.in);
private PrintWriter out = new PrintWriter(System.out);
public void solve() {
int k = in.ni();
int t = 1 << 17;
int[][] matrix = {{t + k, t, 0}, {k, t + k, k}};
out.println(matrix.length + " " + matrix[0].length);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
out.print(matrix[i][j]);
out.print(' ');
}
out.println();
}
}
@Override
public void close() throws IOException {
in.close();
out.close();
}
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 int ni() {
return Integer.parseInt(next());
}
public long nl() {
return Long.parseLong(next());
}
public void close() throws IOException {
reader.close();
}
}
public static void main(String[] args) throws IOException {
try (WalkOnMatrix instance = new WalkOnMatrix()) {
instance.solve();
}
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 6246b5bcc3305c6e0db1a0a791058b7d | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.awt.*;
import java.io.*;
import java.util.*;
public class Drogon {
public static void main(String[] args) throws Exception {
FastReader sc=new FastReader();
int k=sc.nextInt();
int ans[][]=new int[2][3];
ans[0][1]=(1<<17);ans[1][0]=k;ans[1][1]=(1<<17)+k;
ans[0][0]=(1<<17)+k;ans[1][2]=k;
StringBuilder sb=new StringBuilder();
System.out.println(2+" "+3);
for (int i=0;i<2;i++){
for (int j=0;j<3;j++)sb.append(ans[i][j]+" ");
sb.append("\n");
}
System.out.print(sb);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | e0a2e00636305a8beed7afd12f80f2ee | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.StringTokenizer;
import java.io.PrintWriter;
import java.io.*;
import java.util.stream.Collectors.*;
import java.lang.*;
import static java.util.stream.Collectors.*;
import static java.util.Map.Entry.*;
public class Ideo
{
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 power(int x,int y)
{
int res = 1; // Initialize result
// Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y%2==1)
res = (res*x);
// y must be even now
y = y>>1; // y = y/2
x = (x*x);
}
return res;
}
static long gcd(long a,long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static boolean compareSeq(char[] S, int x, int y, int n)
{
for (int i = 0; i < n; i++)
{
if (S[x] < S[y])
return true;
else if (S[x] > S[y])
return false;
x = (x + 1) % n;
y = (y + 1) % n;
}
return true;
}
static void build(long[] sum,int[] arr,int n)
{
for(int i=0;i<(1<<n);i++)
{
long total=0;
for(int j=0;j<n;j++)
{
if((i & (1 << j)) > 0)
total+=arr[j];
}
sum[i]=total;
}
}
static int parity(int a)
{
a^=a>>16;
a^=a>>8;
a^=a>>4;
a^=a>>2;
a^=a>>1;
return a&1;
}
/*
PriorityQueue<aksh> pq = new PriorityQueue<>((o1, o2) -> {
if (o1.p < o2.p)
return 1;
else if (o1.p > o2.p)
return -1;
else
return 0;
});//decreasing order acc to p*/
static int power(int x, int y, int m)
{
if (y == 0)
return 1;
int p = power(x, y / 2, m) % m;
p = (p * p) % m;
if (y % 2 == 0)
return p;
else
return (x * p) % m;
}
/*static int modinv(int a, int m)
{
int g = gcd(a, m);
if (g != 1)
return 0;
else
{
return power(a, m - 2, m);
}
//return 0;
} */
static int[] product(int[] nums) {
int[] result = new int[nums.length];
int[] t1 = new int[nums.length];
int[] t2 = new int[nums.length];
t1[0]=1;
t2[nums.length-1]=1;
//scan from left to right
for(int i=0; i<nums.length-1; i++){
t1[i+1] = nums[i] * t1[i];
}
//scan from right to left
for(int i=nums.length-1; i>0; i--){
t2[i-1] = t2[i] * nums[i];
}
for(int i=0;i<nums.length;i++)
{
System.out.print(t1[i]+" "+t2[i]);
System.out.println();
}
//multiply
for(int i=0; i<nums.length; i++){
result[i] = t1[i] * t2[i];
}
return result;
}
static int getsum(int[] bit,int ind)
{
int sum=0;
while(ind>0)
{
sum+=bit[ind];
ind-= ind & (-ind);
}
return sum;
}
static void update(int[] bit,int max,int ind,int val)
{
while(ind<=max)
{
bit[ind]+=val;
ind+= ind & (-ind);
}
}
//static ArrayList<Integer>[] adj;
static boolean check(long mid,long a,long b)
{
long count=1;
while(count<=mid)
{
count++;
if(a<b)
a+=count;
else
b+=count;
if(a==b)
return true;
}
return false;
}
static class aksh implements Comparable<aksh>
{
int x;
int y;
public aksh(int x,int y)
{
this.x=x;
this.y=y;
}
public int compareTo(aksh o)
{
if(x!=o.x)
return x-o.x;
else
return y-o.y;
}
}
static int get(int arr[], int n)
{
int result = 0;
int x, sum;
// Iterate through every bit
for(int i=0; i<32; i++)
{
// Find sum of set bits at ith position in all
// array elements
sum = 0;
x = (1 << i);
for(int j=0; j<n; j++)
{
if((arr[j] & x)!=0)
sum++;
}
if ((sum % 3)!=0)
result |= x;
}
return result;
}
static boolean isPrime(int n)
{
// Corner cases
if (n <= 1) return false;
if (n <= 3) return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static int nextPrime(int N)
{
// Base case
if (N <= 1)
return (2-N);
int prime = N;
boolean found = false;
while (!found)
{
if (isPrime(prime))
{
found = true;
break;
}
prime++;
}
return (prime-N);
}
static long product(long x)
{
long prod = 1;
while (x > 0)
{
prod *= (x % 10);
x /= 10;
}
return prod;
}
// This function returns the number having
// maximum product of the digits
static long findNumber(long l, long r)
{
// Converting both integers to strings
//string a = l.ToString();
String b = Long.toString(r);
// Let the current answer be r
long ans = r;
for (int i = 0; i < b.length(); i++)
{
if (b.charAt(i) == '0')
continue;
// Stores the current number having
// current digit one less than current
// digit in b
char[] curr = b.toCharArray();
curr[i] = (char)(((int)(curr[i] -
(int)'0') - 1) + (int)('0'));
// Replace all following digits with 9
// to maximise the product
for (int j = i + 1; j < curr.length; j++)
curr[j] = '9';
// Convert string to number
int num = 0;
for (int j = 0; j < curr.length; j++)
num = num * 10 + (curr[j] - '0');
// Check if it lies in range and its product
// is greater than max product
if (num >= l && product(ans) < product(num))
ans = num;
}
return product(ans);
}
static long mod=998244353;
static long pow(long in, long pow) {
if(pow == 0) return 1;
long out = pow(in, pow / 2);
out = (out * out) % mod;
if(pow % 2 == 1) out = (out * in) % mod;
return out;
}
static long inv(long in) {
return pow(in, mod - 2);
}
static void swap(int x,int y)
{
int temp=x;
x=y;
y=temp;
}
static int[] par;
static int[] size;
static int find(int i)
{
if (par[i] == i)
return i;
return par[i] = find(par[par[i]]);
}
static void union(int x, int y)
{
x = find(x);
y = find(y);
if (x == y)
return;
if (size[x] < size[y])
swap(x, y);
par[y] = x;
size[x] += size[y];
}
static void multisourcebfs(long[] arr,int n,int m)
{
//HashSet<Long> vis=new HashSet<>();
HashMap<Long,Long> dis=new HashMap<>();
Queue<Long> q=new LinkedList<>();
for(int i=0;i<arr.length;i++)
{
dis.put(arr[i],(long)0);
q.add(arr[i]);
//vis.add(arr[i]);
}
long[] res=new long[m];
long ans=0;
int k=0;
while(!q.isEmpty())
{
if(k==m)
break;
long x=q.remove();
if(dis.get(x)!=0)
{
ans+=dis.get(x);
res[k]=x;
k++;
}
if(dis.get(x-1)==null)
{
dis.put(x-1, dis.get(x)+1);
q.add(x-1);
//vis.add(x-1);
}
if(dis.get(x+1)==null)
{
dis.put(x+1, dis.get(x)+1);
q.add(x+1);
//vis.add(x+1);
}
}
System.out.println(ans);
for(int i=0;i<m;i++)
System.out.print(res[i]+" ");
}
static int x;
static int maxcount=0;
static void dfs(int node,int par,int dist)
{
if(dist>=maxcount)
{
maxcount=dist;
x=node;
}
List<Integer> l = adj[node];
for(Integer i: l)
{
if(i!=par)
dfs(i,node,dist+1);
}
}
static int h;
static int w;
static int bfs(char[][] ch,int i,int j)
{
Queue<aksh> q=new LinkedList<>();
q.add(new aksh(i,j));
int[][] dis=new int[h][w];
int[][] vis=new int[h][w];
vis[i][j]=1;
dis[i][j]=0;
while(!q.isEmpty())
{
aksh arr=q.poll();
int x1=arr.x;
int y1=arr.y;
if((x1-1)>=0 && ch[x1-1][y1]!='#' && vis[x1-1][y1]==0)
{
vis[x1-1][y1]=1;
q.add(new aksh(x1-1, y1));
dis[x1-1][y1]=Math.max(dis[x1-1][y1],dis[x1][y1]+1);
}
if((x1+1)<h && ch[x1+1][y1]!='#' && vis[x1+1][y1]==0)
{
vis[x1+1][y1]=1;
dis[x1+1][y1]=Math.max(dis[x1+1][y1],dis[x1][y1]+1);
q.add(new aksh(x1+1, y1));
}
if((y1-1)>=0 && ch[x1][y1-1]!='#' && vis[x1][y1-1]==0)
{
vis[x1][y1-1]=1;
dis[x1][y1-1]=Math.max(dis[x1][y1-1],dis[x1][y1]+1);
q.add(new aksh(x1,y1-1));
}
if((y1+1)<w && ch[x1][y1+1]!='#' && vis[x1][y1+1]==0)
{
vis[x1][y1+1]=1;
dis[x1][y1+1]=Math.max(dis[x1][y1+1],dis[x1][y1]+1);
q.add(new aksh(x1,y1+1));
}
}
int max=Integer.MIN_VALUE;
for(int x=0;x<h;x++)
{
for(int y=0;y<w;y++)
max=Math.max(dis[x][y],max);
}
return max;
}
static ArrayList<Integer> cnt;
static void primefact(int n)
{
for (int i=2;i*i<=n;i++)
{
while ((n % i)==0)
{
cnt.add(i);
n /= i;
}
}
if(n>1)
{
cnt.add(n);
}
}
static boolean hash[];
static void sieve(int n)
{
Arrays.fill(hash, true);
for (int p = 2; p * p < n; p++)
if (hash[p] == true)
for (int i = p * 2; i < n; i += p)
hash[i] = false;
}
static long div(long n)
{
long total = 1;
for (int p = 2; p <= n; p++)
{
if (hash[p])
{
int count = 0;
if (n % p == 0)
{
while (n % p == 0)
{
n = n / p;
count++;
}
total = total * (count + 1);
}
}
}
return total;
}
static int upperbound(ArrayList<Integer> array, int length, int value)
{
int low = 0;
int high = length;
while (low < high) {
final int mid = (low + high) / 2;
if (value >= array.get(mid))
{
low = mid + 1;
}
else
{
high = mid;
}
}
return low;
}
static int[][] dp;
static void func(int[][] a,int n,int k,int p)
{
for (int i = 1; i < n; i++)
for (int j = 1; j <= Math.min((i + 1) * k, p); j++)
for (int t2 = 0; t2 <= Math.min(k, Math.min(j, p)); t2++)
{
int aksh = 0;
if (t2!=0)
aksh = a[i][t2 - 1];
dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - t2] + aksh);
}
}
static final long INF = Long.MAX_VALUE/5;
static ArrayList<Integer>[] adj;
static long binpow(long a, long b)
{
long res = 1;
while (b > 0)
{
if ((b & 1) !=0)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
static int upper(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 ans=0;
static void bs(ArrayList<Integer> arr, int max, int k,int n)
{
int l= 1;
int h= max;
ans = h;
while (l<=h)
{
int m = (l+h)/2;
int r = 0;
for (int i = 0; i < n; ++i)
{
r += (arr.get(i) + m - 1) / m;
r--;
}
if(r <= k)
{
ans = m;
h = m - 1;
}
else
l=m+1;
}
}
static public void merge(int[][] arr)
{
int n=arr[0].length;
aksh[] a=new aksh[n];
for(int i=0;i<n;i++)
a[i]=new aksh(arr[i][0],arr[i][1]);
Arrays.sort(a);
Stack<aksh> s=new Stack<>();
s.push(a[0]);
for(int i=1;i<n;i++)
{
aksh temp=s.peek();
if(temp.y>a[i].x)
{
temp.y=a[i].y;
s.pop();
s.push(temp);
}
else if(temp.y<a[i].x)
{
s.push(a[i]);
System.out.println("hii");
}
}
int size=s.size();
int[][] ans=new int[size][2];
int j=0;
while(!s.isEmpty())
{
aksh temp=s.pop();
ans[j][0]=temp.x;
ans[j][1]=temp.y;
j++;
}
}
static boolean pal(String s)
{
int n=s.length();
int l=0;
int r=n-1;
int flag=0;
while(l<r)
{
if(s.charAt(l)==s.charAt(r))
{
l++;
r--;
}
else
{
flag=1;
break;
}
}
if(flag==1)
return false;
else
return true;
}
public static void main(String args[] ) throws Exception
{
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
FastReader sc=new FastReader();
int k=sc.nextInt();
if(k==0)
{
System.out.println("1"+" "+"1");
System.out.println("1");
}
else
{
System.out.println("3"+" "+"3");
System.out.println(((1<<18)-1)+" "+k+" "+"0");
System.out.println((1<<17)+" "+((1<<18)-1)+" "+k);
System.out.println("0"+" "+k+" "+k);
}
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | afceb6d7cd2d843d0ee06cbd2de38463 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve() {
int K = ni();
out.println(2+" "+3);
out.println(((1 << 17) + K)+" "+K+" "+0);
out.println(((1 << 17))+" "+((1 << 17) + K)+" "+K);
}
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();
}
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 static void tr(Object... o) {
System.out.println(Arrays.deepToString(o));
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | e51c0c2d213060c4e9fddfa2e1510cb9 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k = sc.nextInt();
int m = 0x00020000;
int[][] arr = new int[2][3];
arr[0][0] = m+k;
arr[0][1] = k;
arr[1][0] = m;
arr[1][1] = m+k;
arr[1][2] = k;
System.out.println("2 3");
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 9ae1e12a9a84f02c7ea94b3291cfe983 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.Scanner;
public class Main
{
static int[][] charOccurences;
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
// int nbTests = in.nextInt();
// while (nbTests-- > 0)
// {
int k = in.nextInt();
if (k == 0)
{
System.out.println("1 1");
System.out.println(0);
return;
}
System.out.println("2 3");
long a = (long) Math.pow(2, 17) + k;
long b = (long) Math.pow(2, 17);
String[] matrix = { a + " " + k + " " + 0, b + " " + a + " " + k };
for (String row : matrix)
{
System.out.println(row);
}
// }
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 77bd1299c53400ab78c8bcc63fe65db7 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | /*****Author: Satyajeet Singh, Delhi Technological University************************************/
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.math.*;
public class Main{
/*********************************************Constants******************************************/
static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static long mod=(long)1e9+7;
static long mod1=998244353;
static ArrayList<Integer> graph[];
static int pptr=0;
static String st[];
/*****************************************Solutions Begins***************************************/
public static void main(String args[]) throws Exception{
nl();
int k=pi();
if(k==0){
out.println(1+" "+1);
out.print(1);
out.flush();
out.close();
return ;
}
String str=Integer.toBinaryString(k);
int b=str.length();
int f1=-1;
int v=0;
for(int i=0;(1<<i)<=(int)2e5;i++){
if((k&(1<<i))==0){
b=i;
v|=(1<<i);
}
}
//debug(b,f1);
int n=3;
int m=4;
int output[][]=new int[n+1][m+1];
int z=v|k;
// printMask(v);
// printMask(z);
// printMask(k);
output[1][1]=z;
output[2][1]=v;
output[3][1]=v;
output[3][2]=v;
output[3][3]=z;
output[1][2]=k;
output[1][3]=k;
output[2][3]=k;
output[2][2]=k;
output[3][4]=k;
out.println(n+" "+m);
if(k==1){
output=new int[][]{{7 ,3, 3, 1},{4 ,8, 3, 6},{7 ,7, 7, 3}};
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(k==1)out.print(output[i-1][j-1]+" ");
else out.print(output[i][j]+" ");
}
out.println();
}
// int input[][]=output;
// int dp[][]=new int[n+1][m+1];
// dp[0][1]=input[1][1];
// for(int i=1;i<=n;i++){
// for(int j=1;j<=m;j++){
// // debug(i,j,n,m);
// dp[i][j]=Math.max(input[i][j]&dp[i-1][j],input[i][j]&dp[i][j-1]);
// out.print(dp[i][j]+" ");
// }
// out.println();
// }
// debug(dp[n][m]);
/****************************************Solutions Ends**************************************************/
out.flush();
out.close();
}
/****************************************Template Begins************************************************/
static void nl() throws Exception{
pptr=0;
st=br.readLine().split(" ");
}
static void nls() throws Exception{
pptr=0;
st=br.readLine().split("");
}
static int pi(){
return Integer.parseInt(st[pptr++]);
}
static long pl(){
return Long.parseLong(st[pptr++]);
}
static double pd(){
return Double.parseDouble(st[pptr++]);
}
static String ps(){
return st[pptr++];
}
/***************************************Precision Printing**********************************************/
static void printPrecision(double d){
DecimalFormat ft = new DecimalFormat("0.000000000000");
out.print(ft.format(d));
}
/**************************************Bit Manipulation**************************************************/
static void printMask(long mask){
System.out.println(Long.toBinaryString(mask));
}
static int countBit(long mask){
int ans=0;
while(mask!=0){
mask&=(mask-1);
ans++;
}
return ans;
}
/******************************************Graph*********************************************************/
static void Makegraph(int n){
graph=new ArrayList[n];
for(int i=0;i<n;i++){
graph[i]=new ArrayList<>();
}
}
static void addEdge(int a,int b){
graph[a].add(b);
}
// static void addEdge(int a,int b,int c){
// graph[a].add(new Pair(b,c));
// }
/*********************************************PAIR********************************************************/
static class Pair implements Comparable<Pair> {
int u;
int v;
int index=-1;
public Pair(int u, int v) {
this.u = u;
this.v = v;
}
public int hashCode() {
int hu = (int) (u ^ (u >>> 32));
int hv = (int) (v ^ (v >>> 32));
return 31 * hu + hv;
}
public boolean equals(Object o) {
Pair other = (Pair) o;
return u == other.u && v == other.v;
}
public int compareTo(Pair other) {
if(index!=other.index)
return Long.compare(index, other.index);
return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
}
public String toString() {
return "[u=" + u + ", v=" + v + "]";
}
}
/******************************************Long Pair*******************************************************/
static class Pairl implements Comparable<Pairl> {
long u;
long v;
int index=-1;
public Pairl(long u, long v) {
this.u = u;
this.v = v;
}
public int hashCode() {
int hu = (int) (u ^ (u >>> 32));
int hv = (int) (v ^ (v >>> 32));
return 31 * hu + hv;
}
public boolean equals(Object o) {
Pairl other = (Pairl) o;
return u == other.u && v == other.v;
}
public int compareTo(Pairl other) {
if(index!=other.index)
return Long.compare(index, other.index);
return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
}
public String toString() {
return "[u=" + u + ", v=" + v + "]";
}
}
/*****************************************DEBUG***********************************************************/
public static void debug(Object... o){
System.out.println(Arrays.deepToString(o));
}
/************************************MODULAR EXPONENTIATION***********************************************/
static long modulo(long a,long b,long c){
long x=1;
long y=a%c;
while(b > 0){
if(b%2 == 1)
x=(x*y)%c;
y = (y*y)%c;
b /= 2;
}
return x%c;
}
/********************************************GCD**********************************************************/
static long gcd(long x, long y){
if(x==0)
return y;
if(y==0)
return x;
long r=0, a, b;
a = (x > y) ? x : y;
b = (x < y) ? x : y;
r = b;
while(a % b != 0){
r = a % b;
a = b;
b = r;
}
return r;
}
/********************************************End***********************************************************/
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | fc99114071d1f75a015ce971aa46fd0e | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
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);
solve(in, out);
out.close();
}
static String reverse(String s) {
return (new StringBuilder(s)).reverse().toString();
}
static void sort(int ar[]) {
int n = ar.length;
ArrayList<Integer> a = new ArrayList<>();
for (int i = 0; i < n; i++)
a.add(ar[i]);
Collections.sort(a);
for (int i = 0; i < n; i++)
ar[i] = a.get(i);
}
static long ncr(long n, long r, long mod) {
if (r == 0)
return 1;
long val = ncr(n - 1, r - 1, mod);
val = (n * val) % mod;
val = (val * modInverse(r, mod)) % mod;
return val;
}
public static void solve(InputReader sc, PrintWriter pw) {
int i, j = 0;
int t = 1;
// int t=sc.nextInt();
u: while (t-- > 0) {
int k=sc.nextInt();
long n=1;
while(n<=k){
n*=2;
}
pw.println("2 3");
pw.println((n+k)+" "+k+" "+0);
pw.println(n+" "+(n+k)+" "+k);
}
}
static class Pair implements Comparable<Pair> {
int a;
int b;
// int i;
Pair(int a, int b) {
this.a = a;
this.b = b;
// this.i=i;
}
public int compareTo(Pair p) {
if (a != p.a)
return (a - p.a);
return (b - p.b);
}
}
static boolean isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static long fast_pow(long base, long n, long M) {
if (n == 0)
return 1;
if (n == 1)
return base % M;
long halfn = fast_pow(base, n / 2, M);
if (n % 2 == 0)
return (halfn * halfn) % M;
else
return (((halfn * halfn) % M) * base) % M;
}
static long modInverse(long n, long M) {
return fast_pow(n, M - 2, M);
}
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 int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | a72064e21f2f28a45dea40d1d04a6fe5 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.*;
import java.io.*;
import java.security.acl.Owner;
public class codeforces {
public static void main(String[] args) throws Exception {
int n=sc.nextInt();
int infinity=262143;
int smaller_infinity=131072;
int N=infinity^n;
pw.println(2+" "+3);
pw.println(infinity+" "+N+" "+infinity);
pw.println(n+" "+infinity+" "+n);
pw.close();
}
static class Scanner {
private InputStream in;
private byte[] buffer = new byte[1024];
private int curbuf;
private int lenbuf;
public Scanner(InputStream in) {
this.in = in;
this.curbuf = this.lenbuf = 0;
}
public boolean hasNextByte() {
if (curbuf >= lenbuf) {
curbuf = 0;
try {
lenbuf = in.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return false;
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[curbuf++];
else
return -1;
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private void skip() {
while (hasNextByte() && isSpaceChar(buffer[curbuf]))
curbuf++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (!isSpaceChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
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;
}
}
static class pair implements Comparable<pair> {
int x;
int y;
public pair(int x, int y) {
this.x = x;
this.y = y;
}
public String toString() {
return x + " " + y;
}
public int compareTo(pair other) {
if (this.x == other.x) {
return this.y - other.y;
} else {
return 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) {
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, int e, int mod) // O(log e)
{
a %= mod;
long res = 1;
while (e > 0) {
if ((e & 1) == 1)
res = (res * a) % mod;
a = (a * a) % mod;
e >>= 1;
}
return res;
}
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;
}
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];
}
public static void PH(String s, boolean reverse) {
prelen = s.length();
HashsArray[HashsArrayInd] = new int[prelen + 1];
prepow = new int[prelen];
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[0] = 1;
if (!reverse) {
for (int i = 1; i < prelen; i++) {
prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod);
}
for (int i = 0; i < prelen; i++) {
if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z')
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - 'a' + 1) * prepow[i]) % mod) % mod);
else if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z')
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - 'A' + 27) * prepow[i]) % mod) % mod);
else
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - '0' + 1) * prepow[prelen - 1 - i]) % mod) % mod);
}
} else {
for (int i = 1; i < prelen; i++) {
prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod);
}
for (int i = 0; i < prelen; i++) {
if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z')
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - 'a' + 1) * prepow[prelen - 1 - i]) % mod) % mod);
else if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z')
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - 'A' + 27) * prepow[prelen - 1 - i]) % mod) % mod);
else
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - '0' + 1) * prepow[prelen - 1 - i]) % mod) % mod);
}
}
HashsArrayInd++;
}
public static int PHV(int l, int r, int n, boolean reverse) {
if (l > r) {
return 0;
}
int val = (int) ((1l * HashsArray[n - 1][r] + mod - HashsArray[n - 1][l - 1]) % mod);
if (!reverse) {
val = (int) ((1l * val * prepow[prelen - l]) % mod);
} else {
val = (int) ((1l * val * prepow[r - 1]) % mod);
}
return val;
}
static int[][] HashsArray;
static int HashsArrayInd = 0;
static int[] prepow;
static int prelen = 0;
static int prime = 31;
static long fac[];
static int mod = 998244353;
static Random rn = new Random();
static Scanner sc = new Scanner(System.in);
static PrintWriter pw = new PrintWriter(System.out);
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | ce29f9b8936ba872af328d055e70f57e | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | // coded by Krishna Sundar //
import java.lang.*;
import java.io.*;
import java.util.*;
public class Main {
public void solve(Read input, Write output) throws Exception {
int K = input.readInt();
output.printLine(2 + " " + 3);
output.printLine(((1l<<17)+K) + " " + K + " " + 0);
output.printLine((1l<<17) + " " + ((1l<<17)+K) + " " + K);
}
public static void main(String[] args) throws Exception {
Read input = new Read();
Write output = new Write();
Main D = new Main();
D.solve(input, output);
output.flush();
output.close();
}
// java fast io reader and writer
// taken from various sources and customized
static class Read {
private byte[] buffer =new byte[10*1024];
private int index;
private InputStream input_stream;
private int total;
public Read() {
input_stream = System.in;
}
public int read()throws IOException {
if(total<0)
throw new InputMismatchException();
if(index>=total) {
index=0;
total= input_stream.read(buffer);
if(total<=0)
return -1;
}
return buffer[index++];
}
public long readLong() throws IOException {
long number=0;
int n= read();
while(isWhiteSpace(n))
n= read();
long neg=1l;
if(n=='-') {
neg=-1l;
n= read();
}
while(!isWhiteSpace(n)) {
if(n>='0'&&n<='9') {
number*=10l;
number+=(long)(n-'0');
n= read();
}
else throw new InputMismatchException();
}
return neg*number;
}
public int readInt() throws IOException {
int integer=0;
int n= read();
while(isWhiteSpace(n))
n= read();
int neg=1;
if(n=='-') {
neg=-1;
n= read();
}
while(!isWhiteSpace(n)) {
if(n>='0'&&n<='9') {
integer*=10;
integer+=n-'0';
n= read();
}
else throw new InputMismatchException();
}
return neg*integer;
}
public double readDouble()throws IOException {
double doub=0;
int n= read();
while(isWhiteSpace(n))
n= read();
int neg=1;
if(n=='-') {
neg=-1;
n= read();
}
while(!isWhiteSpace(n)&&n!='.') {
if(n>='0'&&n<='9') {
doub*=10;
doub+=n-'0';
n= read();
}
else throw new InputMismatchException();
}
if(n=='.') {
n= read();
double temp=1;
while(!isWhiteSpace(n)) {
if(n>='0'&&n<='9') {
temp/=10;
doub+=(n-'0')*temp;
n= read();
}
else throw new InputMismatchException();
}
}
return doub*neg;
}
public String readString()throws IOException {
StringBuilder sb = new StringBuilder();
int n = read();
while (isWhiteSpace(n))
n = read();
while (!isWhiteSpace(n)) {
sb.append((char)n);
n = read();
}
return sb.toString();
}
private boolean isWhiteSpace(int n) {
if(n==' '|| n=='\n'|| n=='\r'|| n=='\t'|| n==-1)
return true;
return false;
}
}
static class Write {
private final BufferedWriter bw;
public Write() {
bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(String str) throws IOException {
bw.append(str);
}
public void printLine(String str) throws IOException {
print(str);
bw.append("\n");
}
public void close()throws IOException {
bw.close();
}
public void flush()throws IOException {
bw.flush();
}
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 2cfc6ed2b7b1705a403b2e33720e8e2c | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.Scanner;
public class codeforces1332D
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int k = s.nextInt();
int j=k+131072;
System.out.println(2+" "+3);
System.out.println(j+" "+k+" "+0);
System.out.println(131072+" "+j+" "+k);
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | e3de2611b68a24dce1aee4129057ddfd | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Sparsh Sanchorawala
*/
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);
DWalkOnMatrix solver = new DWalkOnMatrix();
solver.solve(1, in, out);
out.close();
}
static class DWalkOnMatrix {
public void solve(int testNumber, InputReader s, PrintWriter w) {
int k = s.nextInt();
int[][] a = new int[3][2];
a[0][0] = (1 << 18) - 1;
a[0][1] = (1 << 17) - 1;
a[1][0] = 1 << 17;
a[1][1] = (1 << 18) - 1;
a[2][0] = 0;
a[2][1] = k;
w.println(3 + " " + 2);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++)
w.print(a[i][j] + " ");
w.println();
}
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.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 nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
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 | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | f23a1a530cf141f958d1129bce068305 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes |
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Round630D {
public static void solve() {
int k = s.nextInt();
if(k == 0) {
out.println(1+" "+1);
out.println(10);
return;
}
out.println(3+" "+2);
int complement = 0;
for(int i = 0; i < 18; i++) {
if((k&(1<<i)) == 0) {
complement |= (1<<i);
}
}
int total = complement|k;
out.println(total+" "+complement);
out.println(k+" "+total);
out.println(0+" "+k);
}
public static void main(String[] args) {
out = new PrintWriter(new BufferedOutputStream(System.out));
s = new FastReader();
solve();
out.close();
}
public static FastReader s;
public static PrintWriter out;
public static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | aadd295e4132617f579e8bcadaa4a899 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | // Utilities
import java.io.*;
import java.util.*;
public class Main {
static int K;
public static void main(String[] args) throws IOException {
INPUT in = new INPUT(System.in);
K = in.iscan();
if (K == 0) {
System.out.println(1 + " " + 1);
System.out.println(300000);
System.exit(0);
}
System.out.println(2 + " " + 3);
int x = (1 << 18) - 1, y = 1 << 17;
System.out.println(x + " " + K + " " + 0);
System.out.println(y + " " + x + " " + K);
}
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 | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 12e2c000d024825c9c4f5668fec45b6e | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | /*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;
public class D
{
public static void main(String omkar[]) throws Exception
{
BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(infile.readLine());
int K = Integer.parseInt(st.nextToken());
StringBuilder sb = new StringBuilder();
//think about bits
//I hate this
//burn this
int start = K+(1<<17);
int[][] grid = new int[2][3];
grid[0][0] = start;
grid[1][0] = K;
grid[0][1] = 1 << 17;
grid[1][1] = start;
grid[0][2] = 0;
grid[1][2] = K;
System.out.println("2 3");
for(int i=0; i < 2; i++)
{
for(int x: grid[i])
System.out.print(x+" ");
System.out.println();
}
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 37543c64062c163e0969b407a57a9520 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
static int MOD = 1000000007;
public static void main(String[] args) throws IOException {
Main m = new Main();
m.solve();
m.close();
}
void close() throws IOException {
pw.flush();
pw.close();
br.close();
}
int ri() throws IOException {
return Integer.parseInt(br.readLine());
}
long rl() throws IOException {
return Long.parseLong(br.readLine());
}
int[] ril(int n) throws IOException {
int[] nums = new int[n];
int c = 0;
for (int i = 0; i < n; i++) {
int sign = 1;
c = br.read();
int x = 0;
if (c == '-') {
sign = -1;
c = br.read();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = br.read();
}
nums[i] = x * sign;
}
while (c != '\n' && c != -1) c = br.read();
return nums;
}
long[] rll(int n) throws IOException {
long[] nums = new long[n];
int c = 0;
for (int i = 0; i < n; i++) {
int sign = 1;
c = br.read();
long x = 0;
if (c == '-') {
sign = -1;
c = br.read();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = br.read();
}
nums[i] = x * sign;
}
while (c != '\n' && c != -1) c = br.read();
return nums;
}
char[] rs() throws IOException {
return br.readLine().toCharArray();
}
void solve() throws IOException {
int k = ri();
int a = (1 << 18) - 1;
int b = 1 << 17;
pw.println("3 3");
pw.println(a + " " + b + " " + b);
pw.println(k + " " + b + " " + b);
pw.println(k + " " + a + " " + k);
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 5fe1c8b1befde6dfe0c78fccdc5a2e10 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.*;
import java.io.*;
public class Solution{
public static class pair{
int x;
int y;
}
public static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
public String next() {
while (st == null || !st.hasMoreElements())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) {
a[i]=nextInt();
}
return a;
}public double nextDouble() {
return Double.parseDouble(next());
}
}
public static void main(String[] args) throws IOException{
FastScanner fs=new FastScanner();
// int t=fs.nextInt();
PrintWriter out=new PrintWriter(System.out);
// while(t-->0){
int n=fs.nextInt();
int[][] arr=new int[3][4];
arr[0][0]=262143;
arr[0][1]=131071;
arr[0][2]=131071;
arr[1][2]=131071;
arr[2][3]=131071;
arr[0][3]=1;
arr[1][0]=131072;
arr[1][1]=0;
arr[2][0]=262143;
arr[2][1]=262143;
arr[2][2]=262143;
arr[1][3]=131071-n;
System.out.println("3 4");
for(int i=0;i<3;i++){
for(int j=0;j<4;j++){
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
// }
out.close();
}
public static void fost(String b,ArrayList<Character> list){
for(int i=1;i<b.length();i++){
list.add(b.charAt(i));
}
}
public static String com(String s1,String s2){
if(s1.compareTo(s2)>0){
return s1;
}else{
return s2;
}
}
public static void fost(HashMap<Integer,ArrayList<Integer>> map,int n,int n1){
ArrayList<Integer> s=map.get(n);
// System.out.println(s);
for(int i=0;i<s.size();i++){
if(s.get(i)==n1){
s.remove(i);
break;
}
}
// System.out.println(s);
for(int i=0;i<s.size();i++){
fost(map,s.get(i),n);
}
}
public static long calc(long n,long b){
if(b==1){
return Long.MAX_VALUE;
}
long val=(long)Math.ceil(n/b);
long p=2;
long ans=val;
while(val!=0){
val=(long)Math.ceil((long)n/(long)Math.pow(b,p));
p++;
ans+=val;
}
return ans;
}
public static long quala(long b){
long val=(long)Math.ceil(Math.pow(1+(8*b),0.5));
if(val%2==0){
long va=(long)(2+val)/(long)2;
return va;
}else{
long va=(long)(1+val)/(long)2;
return va;
}
}
public static String find(int a,int b){
if(a==3){
if(b==1){
return "abb";
}else if(b==2){
return "bab";
}else{
return "bba";
}
}
int v=((a-1)*(a-2))/2;
if(b<=v){
String s=find(a-1,b);
StringBuffer sb=new StringBuffer(s);
int diff=a-s.length();
while(diff-->0){
sb.insert(0,"a");
}
return sb.toString();
}else{
int diff=b-v;
StringBuffer sb=new StringBuffer();
sb.append("b");
for(int i=0;i<a-diff-1;i++){
sb.append("a");
}
sb.append("b");
for(int i=0;i<diff-1;i++){
sb.append("a");
}
return sb.toString();
}
// return new String("a"+s);
}
public static long z(long val){
long p=1;
while(val!=0){
long rem=val%10;
p*=rem;
val=val/10;
}
return p;
}
public static int[] soe(int n){
int[] arr=new int[n];
arr[0]=0;
for(int i=1;i<n;i++){
if(arr[i]==0){
for(int j=(2*(i+1))-1;j<n;j=j+i+1){
arr[j]=1;
}
}
}
return arr;
}
public static int[][] floydWarshall(int graph[][],int V){
int dist[][] = new int[V][V];
int i, j, k;
for (i = 0; i < V; i++){
for (j = 0; j < V; j++){
dist[i][j] = graph[i][j];
}
}
for (k = 0; k < V; k++) {
for (i = 0; i < V; i++){
for (j = 0; j < V; j++){
if (dist[i][k] + dist[k][j] < dist[i][j]){
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
return dist;
}
public static class Comp implements Comparator<pair>{
public int compare(pair a,pair b){
if(a.x!=b.x){
return b.x-a.x;
}else{
return a.y-b.y;
}
}
}
public static long gcd(long a,long b){
if (b == 0)
return a;
return gcd(b, a % b);
}
public static int lcm(int a,int b){
int x=Math.max(a,b);
int y=Math.min(a,b);
long ans=x;
while(ans%y!=0){
ans+=x;
}
if(ans>Integer.MAX_VALUE){
return -1;
}
return (int)ans;
}
public static long fact(int n){
long ans=1;
for(int i=1;i<=n;i++){
ans*=i;
}
return ans;
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | a4f6061884cee13add4b89ffca2c4371 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes |
import java.util.*;
import java.io.*;
public class Main {
static FastReader in=new FastReader();
static StringBuilder Sd=new StringBuilder();
static List<Integer>Gr[];
static int a[],b[];
static boolean visit[];
public static void main(String [] args) {
//Dir by MohammedElkady
int t=1;
while(t-->0) {
int k=in.nextInt();
if(k==0) {
Soutln("1 1");
Soutln("20");
}
else {
Soutln("2 3");
int a[][]=new int[2][3];
int max=0,lole=0,x=1,sum=0;
for(int i=0;i<25;i++) {
sum+=x;
if(x>k) {
lole=x;
a[0][2]=lole;
a[0][0]=(lole*2)|lole|k;
a[1][1]=(lole*2)|lole|k;
a[1][0]=(lole*2);
a[0][1]=lole|k;
a[1][2]=lole|k;
if(a[0][0]<=300000&&k>10) {
Soutln(a[0][0]+" "+a[0][1]+" "+a[0][2]);
Soutln(a[1][0]+" "+a[1][1]+" "+a[1][2]);
}
else {
a[0][0]=sum;
a[1][1]=sum;
a[0][1]=sum-x;
a[0][2]=sum-x-k;
a[1][0]=x;
a[1][2]=sum-x;
Soutln(a[0][0]+" "+a[0][1]+" "+a[0][2]);
Soutln(a[1][0]+" "+a[1][1]+" "+a[1][2]);
}
break;}
x*=2;
}
}
}
Sclose();
}
static long gcd(long g,long x){
if(x<1)return g;
else return gcd(x,g%x);
}
//array fill
static long[]filllong(int n){long a[]=new long[n];for(int i=0;i<n;i++)a[i]=in.nextLong();return a;}
static int[]fillint(int n){int a[]=new int[n];for(int i=0;i<n;i++)a[i]=in.nextInt();return a;}
//OutPut Line
static void Sout(String S) {Sd.append(S);}
static void Soutln(String S) {Sd.append(S+"\n");}
static void Soutf(String S) {Sd.insert(0, S);}
static void Sclose() {System.out.println(Sd);}
static void Sclean() {Sd=new StringBuilder();}
}
class tosolve{
ArrayList<node>no=new ArrayList();
void sort() {
Collections.sort(no);
}
void add(node o) {
no.add(o);
}
}
class node implements Comparable<node>{
int l,r;
node(int x,int p){
this.l=x;
this.r=p;
}
@Override
public int compareTo(node o) {
return (l-o.l);
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
class Sorting{
public static int[] bucketSort(int[] array, int bucketCount) {
if (bucketCount <= 0) throw new IllegalArgumentException("Invalid bucket count");
if (array.length <= 1) return array; //trivially sorted
int high = array[0];
int low = array[0];
for (int i = 1; i < array.length; i++) { //find the range of input elements
if (array[i] > high) high = array[i];
if (array[i] < low) low = array[i];
}
double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket
ArrayList<Integer> buckets[] = new ArrayList[bucketCount];
for (int i = 0; i < bucketCount; i++) { //initialize buckets
buckets[i] = new ArrayList();
}
for (int i = 0; i < array.length; i++) { //partition the input array
buckets[(int)((array[i] - low)/interval)].add(array[i]);
}
int pointer = 0;
for (int i = 0; i < buckets.length; i++) {
Collections.sort(buckets[i]); //mergeSort
for (int j = 0; j < buckets[i].size(); j++) { //merge the buckets
array[pointer] = buckets[i].get(j);
pointer++;
}
}
return array;
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | f989609def79143cae1023a447f1b9b6 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | // package Div2_630;
import java.io.*;
import java.util.InputMismatchException;
public class D implements Runnable
{
@Override
public void run() {
InputReader in = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int t = in.nextInt();
getRes(t, w);
w.flush();
w.close();
}
private static void getRes(int k, PrintWriter w) {
int add = (1 << 17);
int upFirst = add + k;
int upSecond = k;
int botFirst = add;
int botSecond = add + k;
w.println(2 + " " + 3);
w.println(upFirst + " " + upSecond + " " + 0);
w.println(botFirst + " " + botSecond + " " + k);
}
// the base is n. The prime mod is mod.
final static int p =(int) (1e9 + 7);
public static long[] getInvArray(int n) {
long[] inv = new long[n + 1];
inv[1] = 1;
for (int i = 2; i <= n; i++) {
inv[i] = ((p - p / i) * inv[p % i] % p + p) % p;
}
return inv;
}
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
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 String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
public int nextInt()
{
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.')
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.')
{
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
public static void main(String args[]) throws Exception
{
new Thread(null, new D(),"Main",1<<27).start();
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 9a0616b7a0f439258335e535f0e60dc9 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.*;
import java.util.*;
/**
* Created by Katushka on 11.03.2020.
*/
public class B {
static int[] readArray(int size, InputReader in) {
int[] a = new int[size];
for (int i = 0; i < size; i++) {
a[i] = in.nextInt();
}
return a;
}
static long[] readLongArray(int size, InputReader in) {
long[] a = new long[size];
for (int i = 0; i < size; i++) {
a[i] = in.nextLong();
}
return a;
}
private static int gcd(int a, int b) {
while (b != 0) {
int t = b;
b = a % b;
a = t;
}
return a;
}
public static void main(String[] args) throws FileNotFoundException {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int k = in.nextInt();
long d = 1;
int k1 = k;
while (k1 > 0) {
k1 /= 2;
d *= 2;
}
out.println(3 + " " + 2);
out.println((d * 2 - 1) + " " + (d));
out.println(k + " " + (d * 2 - 1));
out.println(0 + " " + k);
out.close();
}
private 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 String nextString() {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public char nextChar() {
return next().charAt(0);
}
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 4d3a0eac7569125ca0a6025313f42150 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
PrintWriter out = new PrintWriter(System.out);
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tok = new StringTokenizer("");
String next() throws IOException {
if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
return tok.nextToken();
}
int ni() throws IOException { return Integer.parseInt(next()); }
long nl() throws IOException { return Long.parseLong(next()); }
void solve() throws IOException {
int k=ni();
int a=1<<18;
a--;
int b=a&(~k);
out.println("3 3");
out.println(a+" "+k+" 0");
out.println(b+" "+k+" 0");
out.println(b+" "+a+" "+k);
/*int[][]A=new int[4][4];
A[1][0]=a;
A[1][1]=a;
A[1][2]=a&k;
A[1][3]=A[1][2]&0;
A[2][1]=a&b;
A[2][2]=Math.max(A[1][2]&k,A[2][1]&k);
A[2][3]=0;
A[3][1]=A[2][1]&b;
A[3][2]=Math.max(A[3][1]&a,A[2][2]&a);
A[3][3]=Math.max(A[3][2]&k,A[2][3]&k);
out.println(A[3][1]);
out.println(A[3][2]);
out.println(A[3][3]);*/
out.flush();
}
public static void main(String[] args) throws IOException {
new Main().solve();
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 1cd048d3895cdb12a10d8de81e0d163e | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.*;
import java.util.Random;
import java.util.StringTokenizer;
public class D {
public static void main(String[] args) {
FastReader scan = new FastReader();
PrintWriter out = new PrintWriter(System.out);
Task solver = new Task();
int t = 1;
for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out);
out.close();
}
static class Task {
public void solve(int testNumber, FastReader scan, PrintWriter out) {
int max = (int) (3e5);
int k = scan.nextInt();
int fill = 1;
while(fill <= max) fill *= 2;
int b = fill / 4;
fill = fill / 2 - 1;
out.println("3 3");
out.println(fill + " " + fill + " " + b);
out.println(fill + " " + k + " " + fill);
out.println(b + " " + fill + " " + k);
}
}
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 | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 8e352211d2223b0b3f571de9b1785318 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import javax.swing.*;
import java.io.*;
import java.util.*;
import java.math.*;
import static java.util.Comparator.*;
public class Main {
public static void main(String[] args) throws IOException {
FastReader s = new FastReader();
int k=s.nextInt();
// System.out.println(Integer.toBinaryString((int) Math.pow(10,5)));
int x= (int) Math.pow(2,17);
// System.out.println(Integer.toBinaryString(x));
System.out.println(2+" "+3);
System.out.println((x+k)+" "+k+" 0");
System.out.println((x)+" "+(x+k)+" "+k);
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | fa31873c741cb29aa7bce5c8ba83dfaf | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.function.IntConsumer;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskD solver = new TaskD(in, out);
try {
solver.solve();
} catch (ExitException ignored) {
}
out.close();
}
static class TaskD {
FastScanner sc;
PrintWriter out;
public TaskD(FastScanner sc, PrintWriter out) {
this.sc = sc;
this.out = out;
}
public void solve() {
times(1, this::solve);
}
public void solve(int time) {
int k = sc.nextInt();
int max = (1 << 18) - 1;
int m2 = 1 << 17;
int m3 = (1 << 17) - 1;
writeln("3 2");
writeln(max + " " + m3);
writeln(m2 + " " + max);
writeln(max + " " + k);
}
private void writeln(Object obj) {
out.println(obj);
}
private void times(int n, IntConsumer consumer) {
for (int i = 0; i < n; i++) {
try {
consumer.accept(i);
} catch (ExitException ignored) {
}
}
}
}
static class FastScanner {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastScanner(InputStream stream) {
this.stream = stream;
}
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++];
}
boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public int nextInt() {
return Integer.parseInt(next());
}
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();
}
}
static class ExitException extends RuntimeException {
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 4412a1a14b5a62a5bae8211655b734de | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.Scanner;
/**
*
* k will be obtained by having dp solution value 0
*
*
* 2^10 + k 2^10 0
* k 2^10+k k
*/
public class c6
{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int k=sc.nextInt();
System.out.println(2 +" "+ 3);
int x=(int)Math.pow(2, 17);
int a=x^k;
int b=x;
int c=0;
System.out.println(a+" "+b+" "+c);
System.out.println(k+" "+a+" "+k);
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 4034b90ebaec7a939cd4067acdea16a8 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes |
import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Inet4Address;
import java.nio.charset.IllegalCharsetNameException;
import java.time.temporal.Temporal;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
public class Main {
public static void main(String[] args) throws IOException{
Reader.init(System.in);
int t =1;
while (t-->0){
solve();
}
}
static LinkedList<Integer>[] g;
static class Node{
long dif;
long cur;
long cnt;
public Node(long dif, long cur, long cnt) {
this.dif = dif;
this.cur = cur;
this.cnt = cnt;
}
}
static int[] d ;
static int[] arr;
static int n;
static TreeSet<Integer> set;
static void solve()throws IOException {
int k = Reader.nextInt();
int max = 0;
for (int i =0 ; i < 32 ; i++){
if (Math.pow(2,i)-1 <= 3*100000){
max = (int)(Math.pow(2,i))-1;
}
}
System.out.println(3 + " " + 3);
int[][] arr = new int[3][3];
arr[0][0] = max;
arr[0][1] = k^max;
arr[1][0] = k;
arr[1][1] = max;
arr[2][1] = k;
arr[2][2] = max;
for (int i = 0 ; i < 3 ; i++){
for (int j = 0 ; j < 3 ; j++){
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
// System.out.println(arr[0][0]&arr[0][1]&arr[1][1]&arr[2][1]&arr[2][2]);
// System.out.println(arr[0][0]&arr[1][0]&arr[1][1]&arr[2][1]&arr[2][2]);
}
static long fun(int sum,int size){
long[][][] dp = new long[n+1][sum+1][size+1];
dp[0][0][0] = 1;
for (int i = 1 ; i<= n ; i++){
for (int j = 0 ; j<= sum ; j++){
for (int k = 0 ; k<= size ; k++){
if (arr[i-1]>j){
dp[i][j][k] = dp[i-1][j][k];
}
else{
if (k!=0) {
dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - arr[i - 1]][k - 1];
}
else{
dp[i][j][k] = dp[i - 1][j][k] + 0;
}
}
}
}
}
return dp[n][sum][size];
}
static long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
public static int stringCompare(String str1, String str2)
{
int l1 = str1.length();
int l2 = str2.length();
int lmin = Math.min(l1, l2);
for (int i = 0; i < lmin; i++) {
int str1_ch = (int)str1.charAt(i);
int str2_ch = (int)str2.charAt(i);
if (str1_ch != str2_ch) {
return str1_ch - str2_ch;
}
}
// Edge case for strings like
// String 1="Geeks" and String 2="Geeksforgeeks"
if (l1 != l2) {
return l1 - l2;
}
// If none of the above conditions is true,
// it implies both the strings are equal
else {
return 0;
}
}
static int next(long[] arr, long target)
{
int start = 0, end = arr.length - 1;
int ans = -1;
while (start <= end) {
int mid = (start + end) / 2;
// Move to right side if target is
// greater.
if (arr[mid] <= target) {
start = mid + 1;
}
// Move left side.
else {
ans = mid;
end = mid - 1;
}
}
return ans;
}
// static int find(int x) {
// return parent[x] == x ? x : (parent[x] = find(parent[x]));
// }
// static boolean merge(int x, int y) {
// x = find(x);
// y = find(y);
// if (x==y){
// return false;
// }
// parent[x] = y;
// return true;
// }
public static void sortbyColumn(int arr[][], int col)
{
// Using built-in sort function Arrays.sort
Arrays.sort(arr, new Comparator<int[]>() {
@Override
// Compare values according to columns
public int compare(final int[] entry1,
final int[] entry2) {
// To sort in descending order revert
// the '>' Operator
if (entry1[col] > entry2[col])
return 1;
else
return -1;
}
}); // End of function call sort().
}
}
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static long nextLong() throws IOException {
return Long.parseLong( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
class Pair{
int a;
int b;
public Pair(int a, int b) {
this.a = a;
this.b = b;
}
}
class MergeSort
{
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
int L[] = new int [n1];
int R[] = new int [n2];
/*Copy data to temp arrays*/
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];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
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++;
}
/* Copy remaining elements of L[] if any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
// Main function that sorts arr[l..r] using
// merge()
void sort(int arr[], int l, int r)
{
if (l < r)
{
// Find the middle point
int m = (l+r)/2;
// Sort first and second halves
sort(arr, l, m);
sort(arr , m+1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
/* A utility function to print array of size n */
static void printArray(int arr[])
{
int n = arr.length;
for (int i=0; i<n; ++i)
System.out.print(arr[i] + " ");
System.out.println();
}
// Driver method
}
class Node implements Comparable<Node>{
int a;
int b;
Node (int a , int b){
this.a = a;
this.b = b;
}
public int compareTo(Node o) {
if ((this.a%2) == (o.a%2)){
return (this.b - o.b);
}
else{
return this.a - o.a;
}
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 288ab6318945cfc720806072b641e759 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.*;
import java.io.*;
public class D_1332 {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int k = sc.nextInt();
int x = 1;
while(x <= k)
x <<= 1;
int m = x + k;
int[][] ans = new int[3][3];
ans[0][0] = ans[0][1] = ans[1][0] = ans[1][2] = ans[2][1] = m;
ans[1][1] = ans[2][2] = k;
ans[0][2] = ans[2][0] = x;
pw.println("3 3");
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
pw.print(ans[i][j] + (j == 2 ? " \n" : " "));
pw.flush();
}
public static 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 char nextChar() throws IOException {
return next().charAt(0);
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public int[] nextIntArray(int n) throws IOException {
int[] array = new int[n];
for (int i = 0; i < n; i++)
array[i] = nextInt();
return array;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] array = new Integer[n];
for (int i = 0; i < n; i++)
array[i] = new Integer(nextInt());
return array;
}
public long[] nextLongArray(int n) throws IOException {
long[] array = new long[n];
for (int i = 0; i < n; i++)
array[i] = nextLong();
return array;
}
public double[] nextDoubleArray(int n) throws IOException {
double[] array = new double[n];
for (int i = 0; i < n; i++)
array[i] = nextDouble();
return array;
}
public static int[] shuffle(int[] a) {
int n = a.length;
Random rand = new Random();
for (int i = 0; i < n; i++) {
int tmpIdx = rand.nextInt(n);
int tmp = a[i];
a[i] = a[tmpIdx];
a[tmpIdx] = tmp;
}
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
public void waitForInput() throws InterruptedException {
Thread.sleep(3000);
}
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 7a6fc73c97d5d6fb7c17a753f4cfb137 | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class S{
static class Pair implements Comparable<Pair>{
int a;
int b;
public Pair(int x,int y){a=x;b=y;}
public Pair(){}
public int compareTo(Pair p1){
if(a == p1.a)
return b - p1.b;
return a - p1.a;
}
}
static class TrieNode{
TrieNode[]child;
int w;
boolean term;
TrieNode(){
child = new TrieNode[26];
}
}
public static int gcd(int a,int b)
{
if(a<b)
return gcd(b,a);
if(b==0)
return a;
return gcd(b,a%b);
}
//static long ans = 0;
static long mod =(long)( 1e9 + 7);
public static void main(String[] args) throws Exception {
new Thread(null, null, "Anshum Gupta", 99999999) {
public void run() {
try {
solve();
} catch(Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}.start();
}
static long[][]dp;
static int maxV;
static void dfs
(ArrayList<ArrayList<Integer>>adj,int sv,boolean[]vis,int[]x){}
static TrieNode root;
public static void solve() throws Exception {
// solve the problem here
MyScanner s = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out), true);
int t = 1;//s.nextInt();
int tc = 0;
maxV = 300000;
while(tc++<t){
int k = s.nextInt();
out.println("3 3");
out.println(((1<<18)-1)+" "+((1<<18)-1)+" "+(1<<17));
out.println(((1<<18)-1)+" "+k+" "+((1<<17)+k));
out.println(((1<<17))+" "+((1<<17)+k)+" "+(k));
}
out.flush();
}
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble() { return Double.parseDouble(next()); }
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//--------------------------------------------------------
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 84203d0cfc0c9d0863876171ce939d2a | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.*;
import java.io.*;
public class Solution{
long rem = 998244353L;
public void solve(int test, Scanner sc){
int k = sc.nextInt();
if(k == 0){
System.out.println("1 1");
System.out.println("1");
return;
}
int n = 2;
int m = 3;
int set = 0;
int num = k;
while(num > 0){
set++;
num = num>>1;
}
int sec = k+(1<<set);
System.out.println(n + " " + m);
System.out.print(sec + " ");
System.out.print(k + " ");
System.out.println("0");
System.out.print((1<<(set)) + " ");
System.out.print(sec + " ");
System.out.println(k);
}
public Solution(){
Scanner sc = new Scanner(System.in);
int tests = 1;
for(int t=1; t<=tests; t++){
solve(t, sc);
}
}
public static void main(String[] args){
new Solution();
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | fe02e48f5467cd2674d844dd0fd9459a | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class Main {
private static final int MAXN = 5000;
private static final String NO = "No";
private static final String YES = "Yes";
InputStream is;
PrintWriter out;
String INPUT = "";
private static long MOD = 1000000009;
private static final int MAX = Integer.MAX_VALUE / 4;
void solve() {
int N = ni();
if (N == 0) {
out.println("1 1\r1");
return;
}
int a[][] = new int[3][3];
a[0][1] = a[1][2] = a[2][1] = a[2][2] = N;
int h = Integer.highestOneBit(N);
a[0][0] = a[1][1] = N | (h<<1);
a[1][0] = (h<<1);
out.println("3 3");
for (int r = 0; r < 3; r++) {
for (int c = 0; c < 3; c++)
out.print(a[r][c] + " ");
out.println();
}
}
long power(long a, long b) {
long x = 1, y = a;
while (b > 0) {
if (b % 2 != 0) {
x = (x * y) % MOD;
}
y = (y * y) % MOD;
b /= 2;
}
return x % MOD;
}
private long gcd(long a, long b) {
while (a != 0) {
long tmp = b % a;
b = a;
a = tmp;
}
return 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();
}
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) {
if (!(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 Integer[] na2(int n) {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = ni();
return a;
}
private int[][] na(int n, int m) {
int[][] a = new int[n][];
for (int i = 0; i < n; i++)
a[i] = na(m);
return a;
}
private Integer[][] na2(int n, int m) {
Integer[][] a = new Integer[n][];
for (int i = 0; i < n; i++)
a[i] = na2(m);
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(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nl();
return a;
}
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 static void tr(Object... o) {
System.out.println(Arrays.deepToString(o));
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | a739d9aa286d9a37158610507c6d1e7d | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.util.Scanner;
public class D {
public static void main(String[] args) {
new D();
}
public D() {
Scanner sc = new Scanner(System.in);
int k = sc.nextInt();
int x = 1<<17;
System.out.println("2 3");
System.out.println((x+k) + " " + k + " 0");
System.out.println(x + " " + (x+k) + " " + k);
sc.close();
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | fb167019f717c3121760d91f2214724f | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.util.*;
import java.lang.*;
import java.util.HashMap;
import java.util.PriorityQueue;
public class Solution implements Runnable
{
static class pair implements Comparable
{
int f;
int s;
pair(int fi, int se)
{
f=fi;
s=se;
}
public int compareTo(Object o)//desc order
{
pair pr=(pair)o;
if(s>pr.s)
return -1;
if(s==pr.s)
{
if(f>pr.f)
return 1;
else
return -1;
}
else
return 1;
}
public boolean equals(Object o)
{
pair ob=(pair)o;
if(o!=null)
{
if((ob.f==this.f)&&(ob.s==this.s))
return true;
}
return false;
}
public int hashCode()
{
return (this.f+" "+this.s).hashCode();
}
}
public class triplet implements Comparable
{
int f;
int s;
int t;
triplet(int f,int s,int t)
{
this.f=f;
this.s=s;
this.t=t;
}
public boolean equals(Object o)
{
triplet ob=(triplet)o;
if(o!=null)
{
if((ob.f==this.f)&&(ob.s==this.s)&&(ob.t==this.t))
return true;
}
return false;
}
public int hashCode()
{
return (this.f+" "+this.s+" "+this.t).hashCode();
}
public int compareTo(Object o)//asc order
{
triplet tr=(triplet)o;
if(t>tr.t)
return 1;
else
return -1;
}
}
void merge1(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++;
}
}
void sort1(int arr[], int l, int r)
{
if (l < r)
{
int m = (l+r)/2;
sort1(arr, l, m);
sort1(arr , m+1, r);
merge1(arr, l, m, r);
}
}
public static void main(String args[])throws Exception
{
new Thread(null,new Solution(),"Solution",1<<27).start();
}
public void run()
{
try
{
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int k=in.ni();
int x=1,y=1;
while(true)
{
x=2*x+1;
if(x>300000)
break;
y=x;
}
x=(y+1)/2;
int a[][]=new int[3][3];
a[0][0]=y;
a[0][1]=y;
a[1][0]=y;
a[1][1]=k;
a[2][0]=x;
a[2][1]=y;
a[2][2]=k;
a[0][2]=x;
a[1][2]=y;
out.println("3 3");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
out.print(a[i][j]+" ");
out.println();
}
out.close();
}
catch(Exception e){
System.out.println(e);
}
}
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
public InputReader(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 ni() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nl() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
public String readString() {
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;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
} | Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | 363bfdae2199131cbeeaea6cb8f28d7d | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class D {
public static void main(String[] args) throws Exception {
new D().run();
}
public void run() throws Exception {
FastScanner f = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int n = f.nextInt();
int MAX = (1 << 18) - 1;
int[][] mat = new int[3][3];
mat[0][0] = mat[2][1] = mat[1][2] = MAX;
mat[0][1] = mat[0][2] = mat[2][2] = n;
mat[1][0] = mat[1][1] = mat[2][0] = MAX-n;
out.println("3 3");
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) out.print(mat[i][j] + " ");
out.println();
}
///
out.flush();
}
///
static class FastScanner {
public BufferedReader reader;
public StringTokenizer tokenizer;
public FastScanner() {
reader = new BufferedReader(new InputStreamReader(System.in), 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());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
try {
return reader.readLine();
} catch(IOException e) {
throw new RuntimeException(e);
}
}
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | ec46c470dcb03432ecac5bd5e9f4452e | train_001.jsonl | 1585661700 | Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that $$$1 \le n,m \le 500$$$ (as Bob hates large matrix); $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers); the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it! | 512 megabytes | // Magic. Do not touch.
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
static class FastReader
{
private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;}
public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
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 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 long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
public int i(){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 double d() throws IOException {return Double.parseDouble(next()) ;}
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; }
public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i();}}
public void scanIntIndexArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i()-1;}}
public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}}
public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } }
public int swapIntegers(int a,int b){return a;} //Call it like this: a=swapIntegers(b,b=a)
}
public static void main(String[] args) throws IOException {
FastReader fr = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
/*
inputCopy
0
outputCopy
1 1
300000
inputCopy
1
outputCopy
3 4
7 3 3 1
4 8 3 6
7 7 7 3
*/
//Press Ctrl+Win+Alt+L for reformatting indentation
int t = 1;
for (int ti = 0; ti < t; ++ti) {
int k = fr.i();
int[][] res = new int[3][3];
int filler = 262143;
for (int[] arr : res)
Arrays.fill(arr, filler);
res[0][2] = filler - k;
res[1][1] = k;
res[2][0] = filler - k;
res[2][2] = k;
pw.println(3 + " " + 3);
for (int i = 0; i < res.length; ++i) {
for (int j = 0; j < res[i].length; ++j)
pw.print(res[i][j] + " ");
pw.println();
}
}
pw.flush();
pw.close();
}
}
| Java | ["0", "1"] | 2 seconds | ["1 1\n300000", "3 4\n7 3 3 1\n4 8 3 6\n7 7 7 3"] | NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$. | Java 8 | standard input | [
"constructive algorithms",
"bitmasks",
"math"
] | fc0442e5cda2498a1818702e5e3eeec4 | The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$). | 1,700 | Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix. Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column. | standard output | |
PASSED | ef6c8937fa7158a064f13a0e1f88c8d6 | train_001.jsonl | 1583573700 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values. | 512 megabytes | import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
// Problem 398B: Painting the Wall
public class P1323A
{
/* Template code starts here. */
public static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8));
public static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in,StandardCharsets.UTF_8));
public static class Pair<T1, T2>
{
public T1 left; public T2 right;
public Pair(T1 pLeft, T2 pRight)
{ this.left = pLeft; this.right = pRight; }
}
public static int gcd(int a, int b)
{ while(b != 0) { int t = a; a = b; b = t % b; } return a; }
public static Integer[] strToIntArr(String s)
{
List<Integer> list = new ArrayList<>();
Arrays.asList(s.split(" ")).forEach(s1 -> list.add(Integer.parseInt(s1)));
return list.toArray(new Integer[0]);
}
/* Template code ends here. */
public static int t;
public static int n;
public static void main(String[] args) throws IOException
{
t = Integer.parseInt(br.readLine());
int i, count, first;
boolean out;
for(int testCase = 0; testCase < t; ++testCase)
{
n = Integer.parseInt(br.readLine());
Integer[] array = strToIntArr(br.readLine());
count = 0;
first = 0;
out = false;
for(i = 0; !out && i < n; ++i)
{
if(array[i] % 2 == 0)
{
bw.write(1 + "\n" + (i + 1) + "\n");
out = true;
}
else
{
if(count == 0)
{
first = i+1;
++count;
}
else
{
bw.write(2 + "\n" + first + " " + (i+1) + "\n");
out = true;
}
}
}
if(!out)
bw.write("-1\n");
bw.flush();
}
bw.close();
br.close();
}
}
| Java | ["3\n3\n1 4 3\n1\n15\n2\n3 5"] | 1 second | ["1\n2\n-1\n2\n1 2"] | NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum. | Java 11 | standard input | [
"dp",
"implementation",
"greedy",
"brute force"
] | 3fe51d644621962fe41c32a2d90c7f94 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates). | 800 | For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them. | standard output | |
PASSED | 351d87b53bb3e908c2f08c8e1cf3f239 | train_001.jsonl | 1583573700 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values. | 512 megabytes | import java.util.*;
public class problem1372A25 {
private static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
int t=sc.nextInt();
while(t>0) {
int n=sc.nextInt();
int[] arr=new int[n];
for (int i = 0; i <n ; i++)
arr[i]=sc.nextInt();
int sum=0;
List<Integer> list=new ArrayList<>();
boolean flag=false,flag2=false;
int temp=0;
for (int i = 0; i <n ; i++) {
if(arr[i]%2==0)
{
flag=true;
temp=i+1;
break;
}
else
{list.add(i+1);
sum+=arr[i];
if(sum%2==0) {
flag2=true;
break;
}
}
}
if (flag||flag2)
{
if(flag)
{
System.out.println(1);
System.out.print(temp);
}
else
{
System.out.println(list.size());
for(Integer i:list)
System.out.print(i+" ");
}
}
else
System.out.print(-1);
System.out.println();
t--;
}
}
} | Java | ["3\n3\n1 4 3\n1\n15\n2\n3 5"] | 1 second | ["1\n2\n-1\n2\n1 2"] | NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum. | Java 11 | standard input | [
"dp",
"implementation",
"greedy",
"brute force"
] | 3fe51d644621962fe41c32a2d90c7f94 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates). | 800 | For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them. | standard output | |
PASSED | d5fc98fdf1f8a38a5da8c3bbf0b1a410 | train_001.jsonl | 1583573700 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values. | 512 megabytes | import java.util.*;
public class P1{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
boolean flag=false;
int ans=0;
int[] a=new int[n];
for (int i=0;i<n ;++i) {
a[i]=sc.nextInt();
if (a[i]%2==0) {
flag=true;
ans=i;
}
}
if (flag) {
System.out.println("1");
System.out.println(ans+1);
}
else{
if (n==1) {
System.out.println("-1");
}
else{
System.out.println("2");
System.out.println("1 2");
}
}
}
}
} | Java | ["3\n3\n1 4 3\n1\n15\n2\n3 5"] | 1 second | ["1\n2\n-1\n2\n1 2"] | NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum. | Java 11 | standard input | [
"dp",
"implementation",
"greedy",
"brute force"
] | 3fe51d644621962fe41c32a2d90c7f94 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates). | 800 | For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them. | standard output | |
PASSED | d06f73bdae82558e693b064bd2b95d44 | train_001.jsonl | 1583573700 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values. | 512 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
import java.util.*;
import static java.lang.System.*;
/*
Shortcut-->
Arrays.stream(n).parallel().sum();
string builder fast_output -->
*/
public class cf_hai1 {
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
public static void main(String[] args) throws IOException {
FastScanner sc = new FastScanner();
int test_case=sc.nextInt();
// int test_case=1;
for(int j=0;j<test_case;j++) {
int n= sc.nextInt();
int arr[]= new int[n];
for (int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
solve(n,arr);
}
}
private static void solve(int n, int[] ar) {
int ind=-1;
for(int i=0;i<n;i++){
if(ar[i]%2 == 0)
{
ind=i;
}
}
if(ind==-1 && n!=1){
out.println("2");
out.println("1 2");
}
else if(ind==-1 && n==1)
out.println("-1");
else{
out.println("1");
out.println((ind+1));
}}
}
| Java | ["3\n3\n1 4 3\n1\n15\n2\n3 5"] | 1 second | ["1\n2\n-1\n2\n1 2"] | NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum. | Java 11 | standard input | [
"dp",
"implementation",
"greedy",
"brute force"
] | 3fe51d644621962fe41c32a2d90c7f94 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates). | 800 | For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.