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 | af84f23dc9fb20510b510257c6640fad | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
FastReader sc=new FastReader ();
int t =sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int m=sc.nextInt();
System.out.println((int)Math.round(n/2 +1)+" "+(int)Math.round(m/2 +1));
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | d7cddefc2a6871d2010fe18f1a8d3630 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
import java.io.*;
public class A_Immobile_Knight {
// For fast input output
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{ try {br = new BufferedReader(
new FileReader("input.txt"));
PrintStream out = new PrintStream(new FileOutputStream("output.txt"));
System.setOut(out);}
catch(Exception e) { 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;
}
}
// end of fast i/o code
public static void main(String[] args) {
FastReader in = new FastReader();
int t = in.nextInt();
while(t-->0){
String str[] = in.nextLine().split(" ");
int a = Integer.parseInt(str[0]);
int b = Integer.parseInt(str[1]);
// if(a>=2 && b>=3){
// if(a==3 && b==3){
// System.out.println(2+" "+2);
// }
// if(a==2 && b==3){
// System.out.println(1+" "+1);
// }
// else{
// System.out.println(a+" "+b);
// }
// }
// else{
// System.out.println(a+" "+b);
// }
System.out.println(((a-1==0)?1:a-1)+" "+((b-1==0)?1:b-1));
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 122597d59dd0cf205c8e53865c271ced | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class SolveJava{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while(t-- > 0){
int n = in.nextInt();
int m = in.nextInt();
if(n == 1 || m == 1) System.out.println("1 " + m);
else System.out.println(--n + " " + --m);
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 3df43e08c2a29f8db7d4628d08c7922c | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int testCsesNumber = scanner.nextInt();
for (int k = 0; k <testCsesNumber ; k++) {
int rows = scanner.nextInt();
int coloms = scanner.nextInt();
int i = rows / 2;
int j = coloms / 2;
if(rows%2 !=0) i ++;
if(coloms%2!=0) j++ ;
if (i - 1 < 0 || i - 2 < 0 || i + 1 > rows || i + 2 > rows) {
if (j - 1 < 0 || j - 2 < 0 || j + 1 > coloms || j + 2 > coloms) {
System.out.println(i + " " + j);
} else {
System.out.println(rows + " " + coloms);
}
} else {
System.out.println(rows + " " + coloms);
}
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 813dfe8679d06ae3cb868f999bcbb193 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes |
import java.util.Scanner;
public class Practise {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t > 0) {
t --;
int r,c;
r = sc.nextInt();
c = sc.nextInt();
boolean found = false;
for (int i=0; i < r ;i++) {
for (int j = 0; j < c; j++) {
boolean validMoveAvailable = checkIfValidMoveAvailable(r, c, i, j);
if (!validMoveAvailable) {
found = true;
System.out.println((i + 1) + " " + (j + 1));
break;
}
}
if (found) {
break;
}
}
if (!found) {
System.out.println("1 1");
}
}
}
private static boolean checkIfValidMoveAvailable(int r, int c, int x, int y) {
// i + 2, j + 1
if ((x + 2) < r && (y + 1) < c) {
return true;
}
// i + 2, j - 1
if ((x + 2) < r && (y - 1) >= 0) {
return true;
}
// i -2, j + 1
if ((x - 2) >= 0 && (y + 1) < c) {
return true;
}
// i - 2, j - 1
if ((x - 2) >= 0 && (y - 1) >= 0) {
return true;
}
// i + 1, j + 2
if ((x + 1) < r && (y + 2) < c) {
return true;
}
// i - 1, j + 2
if ((x - 1) >= 0 && (y + 2) < c) {
return true;
}
// i + 1, j - 2
if ((x + 1) < r && (y - 2) >= 0) {
return true;
}
// i-1, j - 2
if ((x - 1) >= 0 && (y - 2) >= 0) {
return true;
}
return false;
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 9d8c5edef8a4f9398a778e332828d755 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
public class Isolated {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
//number of tests
int n = input.nextInt();
for (int i = 0; i < n; i++) {
int x = input.nextInt();
int y = input.nextInt();
if ((x == 2 && y == 3) || (x == 3 && y == 2) || (x == 3 && y == 3)) { // 3 x 2 or 3 x 3
System.out.println("2 2");
} else {
System.out.println("1 1");
}
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 615fe2e20cbdc80d3d60e59bd55481d9 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class A
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0)
{
int r = sc.nextInt();
int k = sc.nextInt();
System.out.println(Math.min(r,2)+" "+Math.min(k,2));
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 06128c5d05aae9f1b5a5d27f37ce836e | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class A
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0)
{
int n = sc.nextInt();
int k = sc.nextInt();
System.out.println(Math.min(n,2)+" "+Math.min(k,2));
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 439f910e5fad68cb6e065521e562ee3b | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class A
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0)
{
int n = sc.nextInt();
int m = sc.nextInt();
System.out.println(Math.min(n,2)+" "+Math.min(m,2));
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 643a239772d3b4be2714de68aed91511 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.*;
import java.util.*;
public class Mainn {
static long M = (long) (1e9 + 7);
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
if (st.hasMoreTokens()) {
str = st.nextToken("\n");
} else {
str = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void swap(long[] a, long i, long j) {
long temp = a[(int) i];
a[(int) i] = a[(int) j];
a[(int) j] = (int) temp;
}
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) {
return (int) (a * b / gcd(a, b));
}
public static String sortString(String inputString) {
char[] tempArray = inputString.toCharArray();
Arrays.sort(tempArray);
return new String(tempArray);
}
static boolean isSquare(int n) {
int v = (int) Math.sqrt(n);
return v * v == n;
}
static boolean PowerOfTwo(int n) {
if (n == 0) return false;
return (int) (Math.ceil((Math.log(n) / Math.log(2)))) ==
(int) (Math.floor(((Math.log(n) / Math.log(2)))));
}
static int power(long a, long b) {
long res = 1;
while (b > 0) {
if (b % 2 == 1) {
res = (res * a) % M;
}
a = ((a * a) % M);
b = b / 2;
}
return (int) res;
}
public static boolean isPrime(int n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0) {
return false;
}
return true;
}
static long computeXOR(long n) {
if (n % 4 == 0)
return n;
if (n % 4 == 1)
return 1;
if (n % 4 == 2)
return n + 1;
return 0;
}
static long binaryToInteger(String binary) {
char[] numbers = binary.toCharArray();
long result = 0;
for (int i = numbers.length - 1; i >= 0; i--)
if (numbers[i] == '1')
result += Math.pow(2, (numbers.length - i - 1));
return result;
}
static String reverseString(String str) {
char ch[] = str.toCharArray();
String rev = "";
for (int i = ch.length - 1; i >= 0; i--) {
rev += ch[i];
}
return rev;
}
static int countFreq(int[] arr, int n) {
HashMap<Integer, Integer> map = new HashMap<>();
int x = 0;
for (int i = 0; i < n; i++) {
map.put(arr[i], map.getOrDefault(arr[i], 0) + 1);
}
for (int i = 0; i < n; i++) {
if (map.get(arr[i]) == 1)
x++;
}
return x;
}
static void reverse(int[] arr, int l, int r) {
int d = (r - l + 1) / 2;
for (int i = 0; i < d; i++) {
int t = arr[l + i];
arr[l + i] = arr[r - i];
arr[r - i] = t;
}
}
static void sort(String[] s, int n) {
for (int i = 1; i < n; i++) {
String temp = s[i];
int j = i - 1;
while (j >= 0 && temp.length() < s[j].length()) {
s[j + 1] = s[j];
j--;
}
s[j + 1] = temp;
}
}
static int sqr(int n) {
double x = Math.sqrt(n);
if ((int) x == x)
return (int) x;
else
return (int) (x + 1);
}
static int set_bits_count(int num) {
int count = 0;
while (num > 0) {
num &= (num - 1);
count++;
}
return count;
}
static double factorial(double n) {
double f = 1;
for (int i = 1; i <= n; i++) {
f = f * i;
}
return f;
}
static boolean palindrome(int arr[], int n) {
boolean flag = true;
for (int i = 0; i <= n / 2 && n != 0; i++) {
if (arr[i] != arr[n - i - 1]) {
flag = false;
break;
}
}
return flag;
}
public static boolean isSorted(int[] a) {
if (a == null || a.length <= 1) {
return true;
}
for (int i = 0; i < a.length - 1; i++) {
if (a[i] > a[i + 1]) {
return false;
}
}
return true;
}
public static boolean Consecutive(List<Integer> a, int[] b, int n, int m) {
int i = 0, j = 0;
while (i < n && j < m) {
if (Objects.equals(a.get(i), b[j])) {
i++;
j++;
if (j == m)
return true;
} else {
i = i - j + 1;
j = 0;
}
}
return false;
}
static class Pair {
int l;
int r;
public Pair(int l, int r) {
this.l = l;
this.r = r;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
FastReader sc = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-- != 0) {
int n = sc.nextInt();
int m = sc.nextInt();
int x = (n / 2) + 1;
int y = (m / 2) + 1;
int x1 = n-x;
int y1 = m-y;
if(x1==1 || x1==2 || y1==1 || y1==2)
System.out.println(x + " " + y);
else {
System.out.println(1 + " " + 1);
}
}
}
static void solve() throws IOException {
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 995cbdae88a10d28a83dae486ab3571d | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class Solution {
static boolean check(int i,int j,int r,int c){
if(i<1 || j<1 || i>r || j>c)return false;
return true;
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t-->0){
int r = s.nextInt();
int c = s.nextInt();
int ansr=1,ansc=1;
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
if(check(i+2,j+1,r,c) || check(i-2,j+1,r,c) || check(i+2,j-1,r,c) || check(i-2,j-1,r,c) || check(i+1,j-2,r,c) || check(i+1,j+2,r,c) || check(i-1,j-2,r,c) || check(i-1,j+2,r,c)){
continue;
}
else{
ansr = i;
ansc = j;
break;
}
}
}
System.out.println(ansr+" "+ansc);
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 1df4bdfc3be34597f42ffc940733537c | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | /* package codeForces; // don't place package name! */
// algo_messiah23 , NIT RKL ...
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import static java.lang.System.*;
import java.util.stream.IntStream;
import java.util.Map.Entry;
/* Name of the class has to be "Main" only if the class is public. */
public class CodeForces {
static PrintWriter out = new PrintWriter((System.out));
static FastReader in = new FastReader();
static int INF = Integer.MAX_VALUE;
static int NINF = Integer.MIN_VALUE;
public static void main(String[] args) throws java.lang.Exception {
// your code goes here
int t = 1;
t = i();
while (t-- > 0)
algo_messiah23();
out.close();
}
public static void algo_messiah23() {
int n = i();
int m = i();
out.println((n/2+1)+" "+(m/2+1));
}
static String rev(String s) {
StringBuilder st = new StringBuilder(s);
st.reverse();
String ans = st.toString();
return ans;
}
static int[] input(int N) {
int[] A = new int[N];
for (int i = 0; i < N; i++)
A[i] = in.nextInt();
return A;
}
public static void print(int[] arr) {
int n = arr.length;
for (int i = 0; i < n; i++) {
out.print(arr[i] + " ");
}
out.println();
}
public static void sort(int[] arr) {
ArrayList<Integer> ls = new ArrayList<>();
for (int x : arr) {
ls.add(x);
}
Collections.sort(ls);
for (int i = 0; i < arr.length; i++) {
arr[i] = ls.get(i);
}
}
public static void reverse(int[] arr) {
int n = arr.length;
for (int i = 0; i < n / 2; i++) {
int temp = arr[i];
arr[i] = arr[n - 1 - i];
arr[n - 1 - i] = temp;
}
}
public static void reverse(long[] arr) {
int n = arr.length;
for (int i = 0; i < n / 2; i++) {
long temp = arr[i];
arr[i] = arr[n - 1 - i];
arr[n - 1 - i] = temp;
}
}
public static void print(ArrayList<Integer> arr) {
int n = arr.size();
for (int i = 0; i < n; i++) {
out.print(arr.get(i) + " ");
}
out.println();
}
static int i() {
return in.nextInt();
}
static long l() {
return in.nextLong();
}
static char ich() {
return in.next().charAt(0);
}
static String is() {
return in.next();
}
static String isl() {
return in.nextLine();
}
public static int max(int[] arr) {
int max = -1;
int n = arr.length;
for (int i = 0; i < n; i++)
max = Math.max(max, arr[i]);
return max;
}
public static int min(int[] arr) {
int min = INF;
int n = arr.length;
for (int i = 0; i < n; i++)
min = Math.min(min, arr[i]);
return min;
}
public static int gcd(int x, int y) {
if (y == 0) {
return x;
}
return gcd(y, x % y);
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | bf13971f24ccad8b3652540e340a5fd4 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
public class HelloWorld {
public static void main(String args[]) {
Scanner scanner=new Scanner(System.in);
int t=scanner.nextInt();
while(t-->0) {
int n=scanner.nextInt();
int m=scanner.nextInt();
String s="1 1";
outer: for(int i=1;i<n+1;i++) {
for(int j=1;j<m+1;j++) {
if(!check(i,j,m,n)) {
s=i+" "+j;
break outer;
}
}
}
System.out.println(s);
}
scanner.close();
}
static boolean check(int x,int y,int m,int n) {
if((x+2<=n || x-2>0) && (y+1<=m || y-1>0))
return true;
if((y+2<=m || y-2>0) && (x+1<=n || x-1>0))
return true;
return false;
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 1559fddb368ab7fe10fcd0c57db91bdc | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.Math.PI;
import static java.lang.Math.min;
import static java.lang.System.arraycopy;
import static java.lang.System.exit;
import static java.util.Arrays.copyOf;
import java.util.LinkedList;
import java.util.List;
import java.util.Iterator;
import java.io.FileReader;
import java.io.FileWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Deque;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Comparator;
import java.lang.StringBuilder;
import java.util.Collections;
import java.util.*;
import java.text.DecimalFormat;
public class Solution {
// static class Edge{
// int u, v, w;
// Edge(int u, int v, int w){
// this.u = u;
// this.v = v;
// this.w = w;
// }
// }
static class Pair{
int first; int second;
Pair(int first, int second){
this.first = first;
this.second = second;
}
@Override
public String toString(){
return (this.first+" "+this.second);
}
}
static class Tuple{
int first, second, third;
Tuple(int first, int second, int third){
this.first = first;
this.second =second;
this.third = third;
}
@Override
public String toString(){
return first+" "+second+" "+third;
}
}
static class Point{
int x, y;
Point(int x, int y){
this.x = x;
this.y = y;
}
@Override
public String toString(){
return x+" "+y;
}
void minus(Point p){ //pointA.minus(pointB)
this.x -= p.x;
this.y -= p.y;
}
void plus(Point p){ //pointA.plus(pointB)
this.x += p.x;
this.y += p.y;
}
long cross(Point p){//p1.crossProduct(p2), p1 is left if returned value<0
return ((long)this.x*p.y)-((long)p.x*this.y);
}
long triangle(Point p2, Point p3){ //p1.triangle(p2, p3);
// out.println("point1: "+this+" point2: "+p2+" point3: "+p3);
p2.minus(this);
p3.minus(this);
long cross = p2.cross(p3);
p2.plus(this);
p3.plus(this);
return cross;
}
}
static BufferedReader in;
static PrintWriter out;
static StringTokenizer tok;
static int dx[] = {0, -1, 0, 1}; //left up right down
static int dy[] = {-1, 0, 1, 0};
static long MOD = (long)1e9+7, INF = (int)1e9;
static long LINF = (long)1e18+5;
static boolean vis[];
static ArrayList<Integer> adj[];
static int[] knX = {2, 2, 1, -1, -2, -2, -1, 1};
static int[] knY = {-1, 1, 2, 2, 1, -1, -2, -2};
private static void solve() throws IOException{
int N = scanInt(), M = scanInt();
for(int i = 1; i<=N; ++i){
for(int j = 1; j<M; ++j){
boolean flag = false;
for(int k = 0; k<8; ++k){
int nx = knX[k]+i;
int ny = knY[k]+j;
if(!(nx < 1 || nx > N || ny<1 || ny>M))
flag = true;
}
if(!flag){
out.println(i+" "+j);
return;
}
}
}
out.println("1 1");
}
private static int[] inputArray(int n) throws IOException {
int arr[] = new int[n];
for(int i=0; i<n; ++i)
arr[i] = scanInt();
return arr;
}
private static void displayArray(int arr[]){
for(int i = 0; i<arr.length; ++i)
out.print(arr[i]+" ");
out.println();
}
public static void main(String[] args) {
try {
long startTime = System.currentTimeMillis();
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
//in = new BufferedReader(new FileReader("input.txt"));
//out = new PrintWriter(new FileWriter("output.txt"));
int test = scanInt();
for(int t=1; t<=test; t++){
// out.print("Case #"+t+": ");
solve();
}
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
//out.println(totalTime+"---------- "+System.currentTimeMillis() );
in.close();
out.close();
} catch (Throwable e) {
e.printStackTrace();
exit(1);
}
}
static int scanInt() throws IOException {
return parseInt(scanString());
}
static long scanLong() throws IOException {
return parseLong(scanString());
}
static double scanDouble() throws IOException {
return parseDouble(scanString());
}
static String scanString() throws IOException {
if (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
static String scanLine() throws IOException {
return in.readLine();
}
private static void sort(int arr[]){
mergeSort(arr, 0, arr.length-1);
}
private static void sort(int arr[], int start, int end){
mergeSort(arr, start, end-1);
}
private static void mergeSort(int arr[], int start, int end){
if(start >= end)
return;
int mid = (start+end)/2;
mergeSort(arr, start, mid);
mergeSort(arr, mid+1, end);
merge(arr, start, mid, end);
}
private static void merge(int arr[], int start, int mid, int end){
int n1 = mid - start+1;
int n2 = end - mid;
int left[] = new int[n1];
int right[] = new int[n2];
for(int i = 0; i<n1; ++i){
left[i] = arr[i+start];
}
for(int i = 0; i<n2; ++i){
right[i] = arr[mid+1+i];
}
int i = 0, j = 0, curr = start;
while(i <n1 && j <n2){
if(left[i] <= right[j]){
arr[curr] = left[i];
++i;
}
else{
arr[curr] = right[j];
++j;
}
++curr;
}
while(i<n1){
arr[curr] = left[i];
++i; ++curr;
}
while(j<n2){
arr[curr] = right[j];
++j; ++curr;
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | e1b29de99ddb747b6a855edb23294286 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws FileNotFoundException,IOException, InterruptedException {
Scanner s=new Scanner(System.in);
PrintWriter pw=new PrintWriter(System.out);
int t=s.nextInt();
for (int tt=1; tt<=t;tt++)
{
int n=s.nextInt(), m=s.nextInt();
pw.println((n==3?2:n)+" "+(m==3?2:m));
}
pw.flush();
}
public static void shuffle(char []a)
{
for (int i=0; i<a.length;i++)
{
int randIndex=(int)(Math.random()*a.length);
char temp=a[i];
a[i]=a[randIndex];
a[randIndex]=temp;
}
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public Scanner(String s) throws FileNotFoundException
{
br =new BufferedReader(new FileReader(s));
}
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public double nextDouble() throws IOException
{
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if(x.charAt(0) == '-')
{
neg = true;
start++;
}
for(int i = start; i < x.length(); i++)
if(x.charAt(i) == '.')
{
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
}
else
{
sb.append(x.charAt(i));
if(dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg?-1:1);
}
public long[] nextLongArr(int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++)
arr[i] = nextLong();
return arr;
}
public int[] nextIntArr(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = nextInt();
return arr;
}
public boolean ready() throws IOException {return br.ready();}
} //end scanner
}
class Pair implements Comparable{
int x;
int y;
Pair(int x, int y)
{
this.x=x;
this.y=y;
}
@Override
// public int compareTo(Object o) {
// Pair p=(Pair)o;
// return this.x-p.x;
// }
public int compareTo(Object o)
{
Pair p=(Pair)o;
return this.x==p.x?this.y-p.y:this.x-p.x;
}
public String toString()
{
return "("+x+","+y+")";
}
}
class Edge implements Comparable<Edge> {
int node, cost; //node to go to
Edge(int a, int b) {
node = a;
cost = b;
}
public int compareTo(Edge e) {
return cost - e.cost;
}
public String toString()
{
return "{ "+this.node+","+this.cost+" }";
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 00d650c5f880c2e9c2647d822fe9a4d8 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public final class Codeforces1
{
public static void main (String[] args) throws java.lang.Exception
{
FastReader sc = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int m = sc.nextInt();
if(n == 3 && m == 3 || (n == 2 && m == 3) || (n == 3 && m == 2)){
pw.println(2+" "+2);
} else {
pw.println(1+" "+1);
}
}
pw.flush();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | c8c59d8c90701ca63f2601be06102060 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static int INF = 0x3f3f3f3f, mod = 1000000007, mod9 = 998244353;
public static void main(String args[]){
try {
PrintWriter o = new PrintWriter(System.out);
boolean multiTest = true;
// init
if(multiTest) {
int t = fReader.nextInt(), loop = 0;
while (loop < t) {loop++;solve(o);}
} else solve(o);
o.close();
} catch (Exception e) {e.printStackTrace();}
}
static void solve(PrintWriter o) {
try {
int n = fReader.nextInt(), m = fReader.nextInt();
if(n == 1 || m == 1) {
o.println(1 + " " + 1);
}
else {
o.println(2 + " " + 2);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static int upper_bound(List<Integer> a, int val){
int l = 0, r = a.size();
while(l < r){
int mid = l + (r - l) / 2;
if(a.get(mid) <= val) l = mid + 1;
else r = mid;
}
return l;
}
public static int lower_bound(List<Integer> a, int val){
int l = 0, r = a.size();
while(l < r){
int mid = l + (r - l) / 2;
if(a.get(mid) < val) l = mid + 1;
else r = mid;
}
return l;
}
public static long gcd(long a, long b){
return b == 0 ? a : gcd(b, a%b);
}
public static long lcm(long a, long b){
return a / gcd(a,b)*b;
}
public static boolean isPrime(long x){
boolean ok = true;
for(long i=2;i<=Math.sqrt(x);i++){
if(x % i == 0){
ok = false;
break;
}
}
return ok;
}
public static void reverse(int[] array){
reverse(array, 0 , array.length-1);
}
public static void reverse(int[] array, int left, int right) {
if (array != null) {
int i = left;
for(int j = right; j > i; ++i) {
int tmp = array[j];
array[j] = array[i];
array[i] = tmp;
--j;
}
}
}
public static long qpow(long a, long n){
long ret = 1l;
while(n > 0){
if((n & 1) == 1){
ret = ret * a % mod;
}
n >>= 1;
a = a * a % mod;
}
return ret;
}
public static class DSU {
int[] parent;
int[] size;
int n;
public DSU(int n){
this.n = n;
parent = new int[n];
size = new int[n];
for(int i=0;i<n;i++){
parent[i] = i;
size[i] = 1;
}
}
public int find(int p){
while(parent[p] != p){
parent[p] = parent[parent[p]];
p = parent[p];
}
return p;
}
public void union(int p, int q){
int root_p = find(p);
int root_q = find(q);
if(root_p == root_q) return;
if(size[root_p] >= size[root_q]){
parent[root_q] = root_p;
size[root_p] += size[root_q];
size[root_q] = 0;
}
else{
parent[root_p] = root_q;
size[root_q] += size[root_p];
size[root_p] = 0;
}
n--;
}
public int getTotalComNum(){
return n;
}
public int getSize(int i){
return size[find(i)];
}
}
public static class FenWick {
int n;
long[] tree;
public FenWick(int n){
this.n = n;
tree = new long[n+1];
}
private void add(int x, long val){
while(x <= n){
tree[x] += val;
x += x&-x;
}
}
private long query(int x){
long ret = 0l;
while(x > 0){
ret += tree[x];
x -= x&-x;
}
return ret;
}
}
public static class Node implements Comparable<Node> {
Long fst;
Integer snd;
public Node(Long fst, Integer snd) {
this.fst = fst;
this.snd = snd;
}
@Override
public int hashCode() {
int prime = 31, res = 1;
res = prime*res + fst.hashCode();
res = prime*res + snd.hashCode();
return res;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof Node) {
return fst.equals(((Node) obj).fst) && snd.equals(((Node) obj).snd);
}
return false;
}
@Override
public int compareTo(Node node) {
int result = Long.compare(fst, node.fst);
return result == 0 ? Integer.compare(snd, node.snd) : result;
}
}
public static class fReader {
private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
private static StringTokenizer tokenizer = new StringTokenizer("");
private static String next() throws IOException{
while(!tokenizer.hasMoreTokens()){tokenizer = new StringTokenizer(reader.readLine());}
return tokenizer.nextToken();
}
public static int nextInt() throws IOException {return Integer.parseInt(next());}
public static Long nextLong() throws IOException {return Long.parseLong(next());}
public static double nextDouble() throws IOException {return Double.parseDouble(next());}
public static char nextChar() throws IOException {return next().toCharArray()[0];}
public static String nextString() throws IOException {return next();}
public static String nextLine() throws IOException {return reader.readLine();}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | d021c8927ec6ce5c4614a78578ff7d42 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static int INF = 0x3f3f3f3f, mod = 1000000007, mod9 = 998244353;
public static void main(String args[]){
try {
PrintWriter o = new PrintWriter(System.out);
boolean multiTest = true;
// init
if(multiTest) {
int t = fReader.nextInt(), loop = 0;
while (loop < t) {loop++;solve(o);}
} else solve(o);
o.close();
} catch (Exception e) {e.printStackTrace();}
}
static void solve(PrintWriter o) {
try {
int n = fReader.nextInt(), m = fReader.nextInt();
boolean ok = true;
int x = -1, y = -1;
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
if(!(isValid(i-1, j-2, n, m) || isValid(i-2, j-1, n, m)
|| isValid(i-2, j+1, n, m) || isValid(i-1, j+2, n, m)
|| isValid(i+1, j+2, n, m) || isValid(i+2, j+1, n, m)
|| isValid(i+2, j-1, n, m) || isValid(i+1, j-2, n, m))) {
x = i;
y = j;
ok = false;
}
}
}
if(!ok) {
o.println(x + " " + y);
}
else o.println(1 + " " + 1);
} catch (Exception e) {
e.printStackTrace();
}
}
public static boolean isValid(int x, int y, int n, int m) {
if(x >= 1 && x <= n && y >= 1 && y <= m) return true;
return false;
}
public static int upper_bound(List<Integer> a, int val){
int l = 0, r = a.size();
while(l < r){
int mid = l + (r - l) / 2;
if(a.get(mid) <= val) l = mid + 1;
else r = mid;
}
return l;
}
public static int lower_bound(List<Integer> a, int val){
int l = 0, r = a.size();
while(l < r){
int mid = l + (r - l) / 2;
if(a.get(mid) < val) l = mid + 1;
else r = mid;
}
return l;
}
public static long gcd(long a, long b){
return b == 0 ? a : gcd(b, a%b);
}
public static long lcm(long a, long b){
return a / gcd(a,b)*b;
}
public static boolean isPrime(long x){
boolean ok = true;
for(long i=2;i<=Math.sqrt(x);i++){
if(x % i == 0){
ok = false;
break;
}
}
return ok;
}
public static void reverse(int[] array){
reverse(array, 0 , array.length-1);
}
public static void reverse(int[] array, int left, int right) {
if (array != null) {
int i = left;
for(int j = right; j > i; ++i) {
int tmp = array[j];
array[j] = array[i];
array[i] = tmp;
--j;
}
}
}
public static long qpow(long a, long n){
long ret = 1l;
while(n > 0){
if((n & 1) == 1){
ret = ret * a % mod;
}
n >>= 1;
a = a * a % mod;
}
return ret;
}
public static class DSU {
int[] parent;
int[] size;
int n;
public DSU(int n){
this.n = n;
parent = new int[n];
size = new int[n];
for(int i=0;i<n;i++){
parent[i] = i;
size[i] = 1;
}
}
public int find(int p){
while(parent[p] != p){
parent[p] = parent[parent[p]];
p = parent[p];
}
return p;
}
public void union(int p, int q){
int root_p = find(p);
int root_q = find(q);
if(root_p == root_q) return;
if(size[root_p] >= size[root_q]){
parent[root_q] = root_p;
size[root_p] += size[root_q];
size[root_q] = 0;
}
else{
parent[root_p] = root_q;
size[root_q] += size[root_p];
size[root_p] = 0;
}
n--;
}
public int getTotalComNum(){
return n;
}
public int getSize(int i){
return size[find(i)];
}
}
public static class FenWick {
int n;
long[] tree;
public FenWick(int n){
this.n = n;
tree = new long[n+1];
}
private void add(int x, long val){
while(x <= n){
tree[x] += val;
x += x&-x;
}
}
private long query(int x){
long ret = 0l;
while(x > 0){
ret += tree[x];
x -= x&-x;
}
return ret;
}
}
public static class Node implements Comparable<Node> {
Long fst;
Integer snd;
public Node(Long fst, Integer snd) {
this.fst = fst;
this.snd = snd;
}
@Override
public int hashCode() {
int prime = 31, res = 1;
res = prime*res + fst.hashCode();
res = prime*res + snd.hashCode();
return res;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof Node) {
return fst.equals(((Node) obj).fst) && snd.equals(((Node) obj).snd);
}
return false;
}
@Override
public int compareTo(Node node) {
int result = Long.compare(fst, node.fst);
return result == 0 ? Integer.compare(snd, node.snd) : result;
}
}
public static class fReader {
private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
private static StringTokenizer tokenizer = new StringTokenizer("");
private static String next() throws IOException{
while(!tokenizer.hasMoreTokens()){tokenizer = new StringTokenizer(reader.readLine());}
return tokenizer.nextToken();
}
public static int nextInt() throws IOException {return Integer.parseInt(next());}
public static Long nextLong() throws IOException {return Long.parseLong(next());}
public static double nextDouble() throws IOException {return Double.parseDouble(next());}
public static char nextChar() throws IOException {return next().toCharArray()[0];}
public static String nextString() throws IOException {return next();}
public static String nextLine() throws IOException {return reader.readLine();}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 68d8494d2eef184fa928081a35b1bc51 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
static final long MOD=(long)1e9+7;
static final int MAX_TC=(int)1e5+6;
static final boolean MULTI_TC = true;
static FastReader sc;
//===========================MAIN======================================//
public static void main(String[] args) {
sc=new FastReader();
int t=(MULTI_TC)?sc.nextInt():1;
for(int tc=1;tc<=t;++tc){
solve();
}
}
//==========================SOLVE=====================================//
static void solve(){
int n= sc.nextInt();
int m=sc.nextInt();
if(n==1 || m==1){
System.out.println(1+" "+1);
} else if((n==2 || m==2) && Math.max(n,m)==3){
System.out.println((n-1)+" "+(m-1));
} else if(n==3 && m==3){
System.out.println(2+" "+2);
} else {
System.out.println(1+" "+m);
}
}
//============================PAIR====================================//
static class Pair {
int first;
int second;
public Pair(int first, int second) {
this.first = first;
this.second = second;
}
}
static class SortByFirst implements Comparator<Pair> {
@Override
public int compare(Pair o1, Pair o2) {
return o1.first - o2.first;
}
}
static class SortBySecond implements Comparator<Pair> {
@Override
public int compare(Pair o1, Pair o2) {
return o1.second - o2.second;
}
}
//====================================================================//
static long modPow(long a,long b) {
if(b==0)
return 1;
if(b==1)
return a%MOD;
else{
return (a%MOD*modPow(a,b-1)%MOD)%MOD;
}
}
static void sort(int[] arr) {
ArrayList<Integer> ls=new ArrayList<Integer>();
for(int x:arr)
ls.add(x);
Collections.sort(ls); //To reverse Collections.reverseOrder()
for(int i=0;i<arr.length;++i) {
arr[i]=ls.get(i);
}
}
static int countSetBits(int n) {
int count=0;
while(n>0) {
count+=n&1;
n=n>>1;
}
return count;
}
//====================================================================//
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(st==null || !st.hasMoreElements()){
try{
st=new StringTokenizer(br.readLine());
}
catch(IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 7339e51268af249d50908d460ace1426 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt(); //число наборов входных данных
String ans[] = new String[t]; //массив ответов
for(int i = 0; i < t; i++){//если клетки не нашлось, выведется любая
ans[i] = 1 + " " + 1;
}
for(int l = 0; l < t; l++){
int n = in.nextInt(); //строки
int m = in.nextInt(); //столбцы
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if (!(i - 2 >= 0 && j + 1 < m) && !(i - 2 >= 0 && j - 1 >= 0) && !(i + 2 < n && j + 1 < m) && !(i + 2 < n && j - 1 >= 0) &&
!(j - 2 >= 0 && i - 1 >= 0) && !(j - 2 >= 0 && i + 1 > n) && !(j + 2 < m && i + 1 < n) && !(j + 2 < m && i - 1 >= 0)){
ans[l] = (i + 1) + " " + (j + 1);
i = n;
j = m;
}
}
}
}
for(String x : ans){
System.out.println(x);
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 25c68752610ec6c84783b70fbbdafbb3 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner reader=new Scanner(System.in);
int T=reader.nextInt();
while (T-->0)
{
int n=reader.nextInt();
int m=reader.nextInt();
if (n==1 || m==1)
System.out.println(1+" "+1);
else if (n<=3 && m<=3)
{
System.out.println(2+" "+2);
}
else
System.out.println(n+" "+m);
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 00ec9ed49347727f9fc5dcc94dd87b18 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
public class MyClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0)
{
int n = sc.nextInt();
int m = sc.nextInt();
boolean flag = true;
for(int i=1;i<=n;i++)
{
flag = true;
for(int j=1;j<=m;j++)
{
if( (i-2)<1 && (i+2)>n && (j-2)<1 && (j+2)>m )
{
System.out.println(i+" "+j);
flag = false;
break;
}
}
if(!flag)
break;
}
if(flag)
System.out.println(n+" "+m);
t--;
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 96e7bf46b02a64d8239a80a8cca447be | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class ques1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
int l = sc.nextInt();
if((n>3 && l==3) ||(n==3&&l>3) ) {
System.out.println(n+" "+l);
continue;
}else if(n==3 && l==3){
System.out.println(2+" "+2);
}else{
if(l==1||n==1){
System.out.println(1+" "+1);
continue;
}else if(l==2&&n==3||n==2&&l==3) {
System.out.println(2+" "+2);
}else {
System.out.println(1+" "+1);
}
}
}
sc.close();
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | bb4649e70bb2de79ccc93e408c4d0c34 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | // Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class UtopianLord {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
if(st !=null && st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static String solve(int n,int m)
{
StringBuilder sb = new StringBuilder();
// All possible moves of a knight
int X[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int Y[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
int p=n-1,q=m-1;
if((n>=2 && m>=3) || (n>=3 && m>=2))
{
// int count = 0;
// Check if each possible move is valid or not
for (int i = 0; i < 8; i++) {
// Position of knight after move
int x = p + X[i];
int y = q + Y[i];
// count valid moves
if (x >= 0 && y >= 0 && x < n && y < m)
{
// count++;
sb.append(x+1).append(" ").append(y+1);
break;
}
}
return sb.toString();
}
// else if(m>=3)
// {
// // int count = 0;
// // Check if each possible move is valid or not
// for (int i = 0; i < 8; i++) {
// // Position of knight after move
// int x = p + X[i];
// int y = q + Y[i];
// // count valid moves
// if (x >= 0 && y >= 0 && x < n && y < m)
// {
// // count++;
// sb.append(x+1).append(" ").append(y+1);
// }
// }
// return sb.toString();
// }
sb.append(n).append(" ").append(m);
// Return number of possible moves
return sb.toString();
}
public static void main(String[] args)
{
FastReader in = new FastReader();
int tc = in.nextInt();
while(--tc >= 0)
{
int n = in.nextInt();
int m = in.nextInt();
if(n == 3 && m==3)
System.out.println("2 2");
else
{
StringBuilder sb = new StringBuilder();
int i = n/2 +1;
int j = m/2 +1;
sb.append(i).append(" ").append(j);
System.out.println(sb.toString());
}
}
}
}
/*
*/ | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | a2e3ea118ba6f2447a9af46f94f13c4f | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner ai = new Scanner(System.in);
int a = ai.nextInt();
for(int i = 0; i < a; i++) {
int n = ai.nextInt();
int m = ai.nextInt();
if(n == 1 || m == 1 || n == 2 && m == 2) {
System.out.println(n + " " + m);
}
else if(n == 2 && m > 3 || m == 2 && n > 3){
System.out.println(n + " " + m);
}
else if(n == 3 && m == 2 || n == 2 && m == 3){
System.out.println(n - 1 + " " + (m - 1));
}
else if(n > 3 && m == 3 || m > 3 && n == 3){
System.out.println(n + " " + m);
}
else if(n > 3 && m > 3){
System.out.println(n + " " + m);
}
else if(n == 3 && m == 3){
System.out.println((n - 1) + " " + (m - 1));
}
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 5dfe6b198bec45482c7902108009f278 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class Solution1 {
static Scanner scn = new Scanner(System.in);
public static void main(String[] ScoobyDoobyDo) {
int t = scn.nextInt();
// int t = 1;
for (int tests = 0; tests < t; tests++)
solve();
}
public static void solve() {
int n = scn.nextInt();
int x = scn.nextInt();
// int y=scn.nextInt();
if ((n > 3 || x > 3) || (x == 1 || n == 1))
System.out.println(n + " " + x);
else
System.out.println(2 + " " + 2);
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 81876abb37951c1373f5689169791545 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes |
import java.util.*;
public class Solution {
static Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
int t = scn.nextInt();
int temp = t;
while (t-->0) {
int n = scn.nextInt();
int m = scn.nextInt();
boolean flag = false;
for(int i = 1 ; i<=n ; i++){
for(int j = 1 ; j<=m ; j++){
if(!flag && check(i,j,n,m) == false){
System.out.println(i+" "+j);
flag = true;
break;
}
}
}
if(!flag) {
System.out.println(1 + " " + 1);
}
}
}
public static boolean check(int r, int c,int n ,int m){
int[][] arr= new int[][]{{2,1},{2,-1},{1,2},{1,-2},{-2,1},{-2,-1},{-1,2},{-1,-2}};
for(int[] element:arr){
//if anything is found that is in the bounds of the chess board then we simply return a true
if((r+2<=n && r+2>=1) && (c+1<=m && c+1>=1)){
return true;
}
if((r+2<=n && r+2>=1) && (c-1<=m && c-1>=1)){
return true;
}
if((r-2<=n && r-2>=1) && (c+1<=m && c+1>=1)){
return true;
}
if((r-2<=n && r-2>=1) && (c-1<=m && c-1>=1)){
return true;
}
if((r-1<=n && r-1>=1) && (c+2<=m && c+2>=1)){
return true;
}
if((r-1<=n && r-1>=1) && (c-2<=m && c-2>=1)){
return true;
}
if((r+1<=n && r+1>=1) && (c+2<=m && c+2>=1)){
return true;
}
if((r+1<=n && r+1>=1) && (c-2<=m && c-2>=1)){
return true;
}
}
// System.out.println("hi");
return false;
}
}
class Node{
int val;
int days;
Node(int _val , int _days){
val = _val;
days = _days;
}
public int getDays() {
return days;
}
public int getVal() {
return val;
}
}
/*
4 3
1 3 5
2
the end of the array will be in decreasing order
we have to perform a binary search on the last elements of all the arraylists and find
*/ | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | c51dd21d3d1ceeaa469adc3a4efc1f53 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- >0){
int n = sc.nextInt();
int m = sc.nextInt();
if(n==3 && m==3){
System.out.println("2 2");
} else if(n==2&&m<3) {
System.out.println("2 1");
} else if(m==2 && n<3){
System.out.println("1 2");
} else if(m==2 && n==3) {
System.out.println("2 2");
} else if(n==2 && m==3){
System.out.println("2 2");
} else {
System.out.println("1 1");
}
}
}
public static int maxFrequencyNumber(int[] arr){
if(arr.length == 0)
return -1;
int maxFreq = 0;
int number = -1;
HashMap<Integer,Integer> map = new HashMap<>();
for(int i=0;i<arr.length;i++)
{
if(map.containsKey(arr[i]))
{
map.put(arr[i],map.get(arr[i])+1);
}
else {
map.put(arr[i], 1);
}
}
// using set data structure
Set<Integer> keySet = map.keySet();
for(Integer i:keySet)
{
if(map.get(i) > maxFreq)
{
number = i;
maxFreq = map.get(i);
}
}
return number;
}
public static boolean isPrime(int n)
{
if (n <= 1)
return false;
// Check if n=2 or n=3
if (n == 2 || n == 3)
return true;
// Check whether n is divisible by 2 or 3
if (n % 2 == 0 || n % 3 == 0)
return false;
// Check from 5 to square root of n
// Iterate i by (i+6)
for (int i = 5; i <= Math.sqrt(n); i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | c185a427b79a3f896d48fd5dfc076439 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.StringTokenizer;
public class Codechef {
public static void main(String[] args) {
FastReader sc=new FastReader();
PrintWriter out=new PrintWriter(System.out);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int m=sc.nextInt();
if(n>3 || m>3) {
out.println(n+" "+m);
continue;
}
if(n==1 || m==1) {
out.println(n+" "+m);
continue;
}
if(n==3 && m==3) {
out.println(2+" "+2);
continue;
}
if(n==2 || m==2) {
out.println((n-1)+" "+(m-1));
continue;
}
}
out.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
}
static long gcd(long a, long b) {
if (b==0) return a;
return gcd(b, a%b);
}
static final Random random=new Random();
static final int mod=998244353;
static void ruffleSort(int[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static long add(long a, long b) {
return (a+b)%mod;
}
static long sub(long a, long b) {
return ((a-b)%mod+mod)%mod;
}
static long mul(long a, long b) {
return (a*b)%mod;
}
static long exp(long base, long exp) {
if (exp==0) return 1;
long half=exp(base, exp/2);
if (exp%2==0) return mul(half, half);
return mul(half, mul(half, base));
}
static boolean isPrime(long n){
if(n < 2) return false;
if(n == 2 || n == 3) return true;
if(n%2 == 0 || n%3 == 0) return false;
long sqrtN = (long)Math.sqrt(n)+1;
for(long i = 6L; i <= sqrtN; i += 6) {
if(n%(i-1) == 0 || n%(i+1) == 0) return false;
}
return true;
}
static ArrayList<Integer> findDiv(int N)
{
ArrayList<Integer> ls1 = new ArrayList<Integer>();
ArrayList<Integer> ls2 = new ArrayList<Integer>();
for(int i=1; i <= (int)(Math.sqrt(N)+0.00000001); i++)
if(N%i == 0)
{
ls1.add(i);
ls2.add(N/i);
}
Collections.reverse(ls2);
for(int b: ls2)
if(b != ls1.get(ls1.size()-1))
ls1.add(b);
return ls1;
}
static long power(long x, long y, long p)
{
long res = 1L;
x = x%p;
while(y > 0)
{
if((y&1)==1)
res = (res*x)%p;
y >>= 1;
x = (x*x)%p;
}
return res;
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 8869ffa8a4c08331849600230ef14b6d | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class codeforces {
static PrintWriter pw = new PrintWriter(System.out);
static FastReader sc = new FastReader();
public static void main(String[] args) throws Exception {
int tc = sc.nextInt();
for (int i = 0; i < tc; i++) {
solve();
}
pw.close();
}
public static void solve() {
int n = sc.nextInt();
int m = sc.nextInt();
// if ((n >= 2 && m >= 4) || (n >= 4 && m >= 2)) {
// pw.println(n + " " + m);
// } else
if (n == 3 && m == 3) {
pw.println("2 2");
} else if ((n == 2 && m == 3) || (m == 2 && n == 3)) {
pw.println("2 2");
} else {
pw.println(n + " " + m);
}
}
static boolean isEven(int n) {
if ((n ^ 1) == n + 1)
return true;
else
return false;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | ca771a975f8684d7ba91891a25b3c0ae | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import static java.lang.Math.*;
import static java.lang.System.*;
import java.io.*;
import java.util.*;
public class Q1{
public static void main(String[] args)throws IOException {
// Use one of them
Scanner sc = new Scanner(System.in);
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = sc.nextInt();
for(int z=0;z<t;z++){
int n = sc.nextInt();
int m = sc.nextInt();
int temp = n;
n = min(n, m);
m = max(temp, m);
if(n == 1 || m == 1)
System.out.println("1 1");
else if( n>=2 && m >=4)
System.out.println("1 1");
else
System.out.println("2 2");
}
sc.close();
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 1e372e25356b5d8364a5e21158c0aeee | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | /*
IF I HAD CHOICE, I WOULD HAVE BEEN A PIRATE, LOL XD ;
_____________#############
_____________##___________##
______________#____________#
_______________#____________#_##
_______________#__###############
_____##############______________#
_____##____________#_____################
______#______##############______________#
______##_____##___________#______________##
_______#______#____PARTH___#______________#
______##_______#___________##____________#
______###########__________##___________##
___________#_#_##________###_____########_____###
___________#_#_###########_#######_______#####__#########
######_____#_#______##_#_______#_#########___########
##___#########______##_#____#######________#####
__##________##################____##______###
____#____________________________##_#____##
_____#_____###_____##_____###_____###___##
______#___##_##___##_#____#_##__________#
______##____##_____###_____##__________##
________##___________________________##
___________#########################
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main2 {
static PrintWriter out = new PrintWriter(System.out);
static FastReader sc = new FastReader();
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args)
{
int tes = sc.nextInt();
while(tes-->0){
solve();
}
out.close();
}
private static void solve() {
int a1 = sc.nextInt();
int b1 = sc.nextInt();
int a = a1;
int b = b1;
if(a>b) {
int t = a;
a=b;
b=t;
}
if(a==1) {
out.println(a1+" "+b1);
return;
}
if(a==2&&b<4) {
out.println(2+" "+2);
return;
}
if(a==3&&b<4) {
out.println(2+" "+2);
return;
}
out.println(a1+" "+b1);
}
}
/* Test case 0 :-
*/ | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | b1b19a098b9eea11c006c9517420473c | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class cp {
public static void main(String[] args) {
int t = inp();
while(t-->0){
var tmp = inp(2);
out((tmp[0]%2==1?(tmp[0]+1)/2:tmp[0]/2)+" "+(tmp[1]%2==1?(tmp[1]+1)/2:tmp[1]/2),false);
}
}
public static long fd(long n){
return n%10;
}
public static long[] inpla(int n){
var o = new long[n];
for(int i=0;i<n;++i) {
o[i]=sc.hasNextLong()?sc.nextLong():0L;
}
return o;
}
public static void swap(int[] a, int p, int i){
var tmp=a[p];
a[p]=a[i];
a[i]=tmp;
}
public static ArrayList<Integer> conv(int[] a){
var tmp = new ArrayList<Integer>();
for(int i=0;i<a.length;++i){
tmp.add(a[i]);
}
return tmp;
}
public static int intma(){
return Integer.MAX_VALUE;
}
public static int intmi(){
return Integer.MIN_VALUE;
}
public static int range(int[] ps, int n, int l, int r) {
return ps[r]-(l==0?0:ps[l-1]);
}
public static int lower_bound(int[]a,int n,int tar) {
int k = -1;
for(int b=n/2;b>=1;b/=2)
while(k+b<n&&a[k+b]<tar) k+=b;
return k+1;
}
public static int upper_bound(int[] a,int n,int tar) {
int k = 0;
for(int b = n/2; b>=1; b/=2)
while(k+b<n&&a[k+b]<=tar) k+=b;
return k;
}
public static int mod=(int)1e9+7;
public static Scanner sc = new Scanner(System.in);
public static String str() {
return sc.hasNextLine()?sc.nextLine():"";
}
public static int inp() {
int n = sc.hasNextInt()?sc.nextInt():0; sc.nextLine();
return n;
}
public static void sort(int[] a){
Arrays.sort(a);
}
public static int bs(int[] a, int k) {
return Arrays.binarySearch(a,k);
}
public static int[] inp(int n) {
int[] a = new int[n];
for(int i=0;i<n;++i)
a[i]=sc.hasNextInt()?sc.nextInt():0;
sc.nextLine();
return a;
}
public static String inp(boolean s) {
return sc.hasNextLine()?sc.nextLine():"";
}
public static void out(String s, boolean chk) {
if(!chk) System.out.println(s);
else System.out.print(s);
}
public static void nl() {
System.out.print("\n");
}
public static void out(int[] a) {
for(int i=0;i<a.length;++i) System.out.print(a[i]+" ");
System.out.print("\n");
}
public static void out(long[] a) {
for(int i=0;i<a.length;++i) System.out.print(a[i]+" ");
System.out.print("\n");
}
public static void out(int n) {
System.out.println(n);
}
public static void out(long n) {
System.out.println(n);
}
public static int max(int a, int b) {
return Math.max(a,b);
}
public static long max(long a, long b) {
return Math.max(a,b);
}
public static int min(int a, int b) {
return Math.min(a,b);
}
public static long min(long a, long b) {
return Math.min(a,b);
}
public static int[] cprange(int[] a, int f, int t) {
return Arrays.copyOfRange(a,f,t+1);
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 071074273122a31a2ae8431a4324a01c | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class A {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = fs.nextInt();
while (t-- > 0) {
int n=fs.nextInt();
int m=fs.nextInt();
check(n,m);
}
out.close();
}
public static void check(int n,int m){
if(n==3 && m==3){
System.out.println(2+" "+2);
return;
}
if(n==3 && m==2){
System.out.println(2+" "+1);
return;
}
if(n==2 && m==3){
System.out.println(2+" "+2);
return;
}
else{
System.out.println(n+" "+m);
return;
}
}
/* HELPER FUNCTION's */
static final Random random = new Random();
static final int mod = 1_000_000_007;
static void ruffleSort(int[] a) {
int n = a.length;//shuffle, then sort
for (int i = 0; i < n; i++) {
int oi = random.nextInt(n), temp = a[oi];
a[oi] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
static long add(long a, long b) {
return (a + b) % mod;
}
static long sub(long a, long b) {
return ((a - b) % mod + mod) % mod;
}
static long mul(long a, long b) {
return (a * b) % mod;
}
/* fast exponentiation */
static long exp(long base, long exp) {
if (exp == 0) return 1;
long half = exp(base, exp / 2);
if (exp % 2 == 0) return mul(half, half);
return mul(half, mul(half, base));
}
/* end of fast exponentiation */
static long[] factorials = new long[2_000_001];
static long[] invFactorials = new long[2_000_001];
static void precompFacts() {
factorials[0] = invFactorials[0] = 1;
for (int i = 1; i < factorials.length; i++) factorials[i] = mul(factorials[i - 1], i);
invFactorials[factorials.length - 1] = exp(factorials[factorials.length - 1], mod - 2);
for (int i = invFactorials.length - 2; i >= 0; i--)
invFactorials[i] = mul(invFactorials[i + 1], i + 1);
}
static long nCk(int n, int k) {
return mul(factorials[n], mul(invFactorials[k], invFactorials[n - k]));
}
/* sort ascending and descending both */
static void sort(int[] a,int x) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a) l.add(i);
if(x==0) {
Collections.sort(l);
}
if(x==1){
Collections.sort(l,Collections.reverseOrder());
}
for (int i = 0; i < a.length; i++) a[i] = l.get(i);
}
/* sort String acc. to character */
static String sortString(String s){
char ch[]=s.toCharArray();
Arrays.sort(ch);
String s1=String.valueOf(ch);
return s1;
}
// lcm(a,b) * gcd(a,b) = a * b
public static long _lcm(long a, long b) {
return (a / _gcd(a, b)) * b;
}
// euclidean algorithm time O(max (loga ,logb))
public static long _gcd(long a, long b) {
while (a > 0) {
long x = a;
a = b % a;
b = x;
}
return b;
}
/* Pair Class implementation */
static class Pair<K, V> {
K ff;
V ss;
public Pair(K ff, V ss) {
this.ff = ff;
this.ss = ss;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
Pair<?, ?> pair = (Pair<?, ?>) o;
return ff.equals(pair.ff) && ss.equals(pair.ss);
}
@Override
public int hashCode() {
return Objects.hash(ff, ss);
}
@Override
public String toString() {
return ff.toString() + " " + ss.toString();
}
}
/* pair class ends here */
/* fast input output class */
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[] readArrayL(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | f0a46f3ce67959b87a21b23b245b6bf2 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes |
import java.io.*;
import java.util.*;
public class Solution {
public static long gcd(long a,long b) {
if(a==0) return b;
return gcd(b%a,a);
}
public static long lcm(long a,long b) {
return (a*b)/gcd(a,b);
}
public static long [] arrayInput(BufferedReader br,int n) throws java.lang.Exception {
long out[]=new long[n];
String input[]=br.readLine().split(" ");
for(int i=0;i<n;i++) {
out[i]=Long.parseLong(input[i]);
}
return out;
}
public static long [] simpleInput(BufferedReader br,int n) throws java.lang.Exception{
long ans[]=new long[n];
String input[]=br.readLine().split(" ");
for(int i=0;i<n;i++) {
ans[i]=Long.parseLong(input[i]);
}
return ans;
}
public static void main(String[] args) throws java.lang.Exception {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter out=new PrintWriter(System.out);
int testCases=Integer.parseInt(br.readLine());
while(testCases-->0) {
long input[]=simpleInput(br, 2);
long n=input[0];
long m=input[1];
long mr=(n+1)/2;
long mc=(m+1)/2;
out.println(mr+" "+mc);
}
out.close();
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 68c2ab49273a9e98eea704cf987b5d1c | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes |
import java.io.*;
import java.math.BigInteger;
import java.util.*;
/**
*
* @author eslam
*/
public class Solution {
// Beginning of the solution
static Kattio input = new Kattio();
static BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
static ArrayList<ArrayList<Integer>> powerSet = new ArrayList<>();
static ArrayList<LinkedList<Integer>> allprem = new ArrayList<>();
static ArrayList<LinkedList<String>> allprems = new ArrayList<>();
static ArrayList<Long> luc = new ArrayList<>();
static long mod = (long) (Math.pow(10, 9) + 7);
static int grid[][] = {{0, 0, 1, -1, 1, 1, -1, -1}, {1, -1, 0, 0, 1, -1, 1, -1}};
static int dp[][][];
static double cmp = 0.000000001;
static long b[];
public static void main(String[] args) throws IOException {
//Kattio input = new Kattio("input");
// BufferedWriter log = new BufferedWriter(new FileWriter("output.txt"));
int test = input.nextInt();
loop:
for (int o = 1; o <= test; o++) {
int n = input.nextInt();
int m = input.nextInt();
log.write((n / 2 + n % 2) + " " + (m / 2 + m % 2) + "\n");
}
log.flush();
}
static boolean can(long n, long k, long a[]) {
if (k < 0) {
return false;
}
if (k % 3 == 0) {
Arrays.sort(a);
long an = (a[2] - a[1]) + (a[2] - a[0]);
if (an > n) {
return false;
}
n -= an;
if (n % 3 != 0) {
return false;
}
} else {
return false;
}
return true;
}
static void prefixSum2D(long arr[][]) {
for (int i = 0; i < arr.length; i++) {
prefixSum(arr[i]);
}
for (int i = 0; i < arr[0].length; i++) {
for (int j = 1; j < arr.length; j++) {
arr[j][i] += arr[j - 1][i];
}
}
}
public static long baseToDecimal(String w, long base) {
long r = 0;
long l = 0;
for (int i = w.length() - 1; i > -1; i--) {
long x = (w.charAt(i) - '0') * (long) Math.pow(base, l);
r = r + x;
l++;
}
return r;
}
static int bs(int v, ArrayList<Integer> a) {
int max = a.size() - 1;
int min = 0;
int ans = 0;
while (max >= min) {
int mid = (max + min) / 2;
if (a.get(mid) >= v) {
ans = a.size() - mid;
max = mid - 1;
} else {
min = mid + 1;
}
}
return ans;
}
static Comparator<tri> cmpTri() {
Comparator<tri> c = new Comparator<tri>() {
@Override
public int compare(tri o1, tri o2) {
if (o1.x > o2.x) {
return 1;
} else if (o1.x < o2.x) {
return -1;
} else {
if (o1.y > o2.y) {
return 1;
} else if (o1.y < o2.y) {
return -1;
} else {
if (o1.z > o2.z) {
return 1;
} else if (o1.z < o2.z) {
return -1;
} else {
return 0;
}
}
}
}
};
return c;
}
static Comparator<pair> cmpPair2() {
Comparator<pair> c = new Comparator<pair>() {
@Override
public int compare(pair o1, pair o2) {
if (o1.y > o2.y) {
return 1;
} else if (o1.y < o2.y) {
return -1;
} else {
if (o1.x > o2.x) {
return 1;
} else if (o1.x < o2.x) {
return -1;
} else {
return 0;
}
}
}
};
return c;
}
static Comparator<pair> cmpPair() {
Comparator<pair> c = new Comparator<pair>() {
@Override
public int compare(pair o1, pair o2) {
if (o1.x > o2.x) {
return 1;
} else if (o1.x < o2.x) {
return -1;
} else {
if (o1.y > o2.y) {
return 1;
} else if (o1.y < o2.y) {
return -1;
} else {
return 0;
}
}
}
};
return c;
}
static class rec {
long x1;
long x2;
long y1;
long y2;
public rec(long x1, long y1, long x2, long y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public long getArea() {
return (x2 - x1) * (y2 - y1);
}
}
static long sumOfRange(int x1, int y1, int x2, int y2, long a[][]) {
return (a[x2][y2] - a[x1 - 1][y2] - a[x2][y1 - 1]) + a[x1 - 1][y1 - 1];
}
public static int[][] bfs(int i, int j, String w[]) {
Queue<pair> q = new ArrayDeque<>();
q.add(new pair(i, j));
int dis[][] = new int[w.length][w[0].length()];
for (int k = 0; k < w.length; k++) {
Arrays.fill(dis[k], -1);
}
dis[i][j] = 0;
while (!q.isEmpty()) {
pair p = q.poll();
int cost = dis[p.x][p.y];
for (int k = 0; k < 4; k++) {
int nx = p.x + grid[0][k];
int ny = p.y + grid[1][k];
if (isValid(nx, ny, w.length, w[0].length())) {
if (dis[nx][ny] == -1 && w[nx].charAt(ny) == '.') {
q.add(new pair(nx, ny));
dis[nx][ny] = cost + 1;
}
}
}
}
return dis;
}
public static void dfs(int node, ArrayList<Integer> a[], boolean vi[]) {
vi[node] = true;
for (Integer ch : a[node]) {
if (!vi[ch]) {
dfs(ch, a, vi);
}
}
}
public static void graphRepresintion(ArrayList<Integer>[] a, int q) throws IOException {
for (int i = 0; i < a.length; i++) {
a[i] = new ArrayList<>();
}
while (q-- > 0) {
int x = input.nextInt();
int y = input.nextInt();
a[x].add(y);
a[y].add(x);
}
}
public static boolean isValid(int i, int j, int n, int m) {
return (i > -1 && i < n) && (j > -1 && j < m);
}
// present in the left and right indices
public static int[] swap(int data[], int left, int right) {
// Swap the data
int temp = data[left];
data[left] = data[right];
data[right] = temp;
// Return the updated array
return data;
}
// Function to reverse the sub-array
// starting from left to the right
// both inclusive
public static int[] reverse(int data[], int left, int right) {
// Reverse the sub-array
while (left < right) {
int temp = data[left];
data[left++] = data[right];
data[right--] = temp;
}
// Return the updated array
return data;
}
// Function to find the next permutation
// of the given integer array
public static boolean findNextPermutation(int data[]) {
// If the given dataset is empty
// or contains only one element
// next_permutation is not possible
if (data.length <= 1) {
return false;
}
int last = data.length - 2;
// find the longest non-increasing suffix
// and find the pivot
while (last >= 0) {
if (data[last] < data[last + 1]) {
break;
}
last--;
}
// If there is no increasing pair
// there is no higher order permutation
if (last < 0) {
return false;
}
int nextGreater = data.length - 1;
// Find the rightmost successor to the pivot
for (int i = data.length - 1; i > last; i--) {
if (data[i] > data[last]) {
nextGreater = i;
break;
}
}
// Swap the successor and the pivot
data = swap(data, nextGreater, last);
// Reverse the suffix
data = reverse(data, last + 1, data.length - 1);
// Return true as the next_permutation is done
return true;
}
public static pair[] dijkstra(int node, ArrayList<pair> a[]) {
PriorityQueue<tri> q = new PriorityQueue<>(new Comparator<tri>() {
@Override
public int compare(tri o1, tri o2) {
if (o1.y > o2.y) {
return 1;
} else if (o1.y < o2.y) {
return -1;
} else {
return 0;
}
}
});
q.add(new tri(node, 0, -1));
pair distance[] = new pair[a.length];
while (!q.isEmpty()) {
tri p = q.poll();
int cost = p.y;
if (distance[p.x] != null) {
continue;
}
distance[p.x] = new pair(p.z, cost);
ArrayList<pair> nodes = a[p.x];
for (pair node1 : nodes) {
if (distance[node1.x] == null) {
tri pa = new tri(node1.x, cost + node1.y, p.x);
q.add(pa);
}
}
}
return distance;
}
public static String revs(String w) {
String ans = "";
for (int i = w.length() - 1; i > -1; i--) {
ans += w.charAt(i);
}
return ans;
}
public static boolean isPalindrome(String w) {
for (int i = 0; i < w.length() / 2; i++) {
if (w.charAt(i) != w.charAt(w.length() - i - 1)) {
return false;
}
}
return true;
}
public static void getPowerSet(Queue<Integer> a) {
int n = a.poll();
if (!a.isEmpty()) {
getPowerSet(a);
}
int s = powerSet.size();
for (int i = 0; i < s; i++) {
ArrayList<Integer> ne = new ArrayList<>();
ne.add(n);
for (int j = 0; j < powerSet.get(i).size(); j++) {
ne.add(powerSet.get(i).get(j));
}
powerSet.add(ne);
}
ArrayList<Integer> p = new ArrayList<>();
p.add(n);
powerSet.add(p);
}
public static int getlo(int va) {
int v = 1;
while (v <= va) {
if ((va&v) != 0) {
return v;
}
v <<= 1;
}
return 0;
}
static long fast_pow(long a, long p, long mod) {
long res = 1;
while (p > 0) {
if (p % 2 == 0) {
a = (a * a) % mod;
p /= 2;
} else {
res = (res * a) % mod;
p--;
}
}
return res;
}
public static int countPrimeInRange(int n, boolean isPrime[]) {
int cnt = 0;
Arrays.fill(isPrime, true);
for (int i = 2; i * i <= n; i++) {
if (isPrime[i]) {
for (int j = i * 2; j <= n; j += i) {
isPrime[j] = false;
}
}
}
for (int i = 2; i <= n; i++) {
if (isPrime[i]) {
cnt++;
}
}
return cnt;
}
public static void create(long num) {
luc.add(num);
if (num > power(10, 9)) {
return;
}
create(num * 10 + 4);
create(num * 10 + 7);
}
public static long ceil(long a, long b) {
return (a + b - 1) / b;
}
public static long round(long a, long b) {
if (a < 0) {
return (a - b / 2) / b;
}
return (a + b / 2) / b;
}
public static void allPremutationsst(LinkedList<String> l, boolean visited[], ArrayList<String> st) {
if (l.size() == st.size()) {
allprems.add(l);
}
for (int i = 0; i < st.size(); i++) {
if (!visited[i]) {
visited[i] = true;
LinkedList<String> nl = new LinkedList<>();
for (String x : l) {
nl.add(x);
}
nl.add(st.get(i));
allPremutationsst(nl, visited, st);
visited[i] = false;
}
}
}
public static void allPremutations(LinkedList<Integer> l, boolean visited[], int a[]) {
if (l.size() == a.length) {
allprem.add(l);
}
for (int i = 0; i < a.length; i++) {
if (!visited[i]) {
visited[i] = true;
LinkedList<Integer> nl = new LinkedList<>();
for (Integer x : l) {
nl.add(x);
}
nl.add(a[i]);
allPremutations(nl, visited, a);
visited[i] = false;
}
}
}
public static int binarySearch(long[] a, long value) {
int l = 0;
int r = a.length - 1;
while (l <= r) {
int m = (l + r) / 2;
if (a[m] == value) {
return m;
} else if (a[m] > value) {
r = m - 1;
} else {
l = m + 1;
}
}
return -1;
}
public static void reverse(int l, int r, char ch[]) {
for (int i = 0; i < r / 2; i++) {
char c = ch[i];
ch[i] = ch[r - i - 1];
ch[r - i - 1] = c;
}
}
public static int logK(long v, long k) {
int ans = 0;
while (v > 1) {
ans++;
v /= k;
}
return ans;
}
public static long power(long a, long n) {
if (n == 1) {
return a;
}
long pow = power(a, n / 2);
pow *= pow;
if (n % 2 != 0) {
pow *= a;
}
return pow;
}
public static long get(long max, long x) {
if (x == 1) {
return max;
}
int cnt = 0;
while (max > 0) {
cnt++;
max /= x;
}
return cnt;
}
public static int numOF0(long v) {
long x = 1;
int cnt = 0;
while (x <= v) {
if ((x & v) == 0) {
cnt++;
}
x <<= 1;
}
return cnt;
}
public static int log2(double n) {
int cnt = 0;
while (n > 1) {
n /= 2;
cnt++;
}
return cnt;
}
public static int[] bfs(int node, ArrayList<Integer> a[]) {
Queue<Integer> q = new LinkedList<>();
q.add(node);
int distances[] = new int[a.length];
Arrays.fill(distances, -1);
distances[node] = 0;
while (!q.isEmpty()) {
int parent = q.poll();
ArrayList<Integer> nodes = a[parent];
int cost = distances[parent];
for (Integer node1 : nodes) {
if (distances[node1] == -1) {
q.add(node1);
distances[node1] = cost + 1;
}
}
}
return distances;
}
public static void primeFactors(int n, HashMap<Integer, ArrayList<Integer>> h, int ind) {
boolean ca = true;
while (n % 2 == 0) {
if (ca) {
if (h.get(2) == null) {
h.put(2, new ArrayList<>());
}
h.get(2).add(ind);
ca = false;
}
n /= 2;
}
for (int i = 3; i <= Math.sqrt(n); i += 2) {
ca = true;
while (n % i == 0) {
if (ca) {
if (h.get(i) == null) {
h.put(i, new ArrayList<>());
}
h.get(i).add(ind);
ca = false;
}
n /= i;
}
if (n < i) {
break;
}
}
if (n > 2) {
if (h.get(n) == null) {
h.put(n, new ArrayList<>());
}
h.get(n).add(ind);
}
}
// end of solution
public static BigInteger f(long n) {
if (n <= 1) {
return BigInteger.ONE;
}
long t = n - 1;
BigInteger b = new BigInteger(t + "");
BigInteger ans = new BigInteger(n + "");
while (t > 1) {
ans = ans.multiply(b);
b = b.subtract(BigInteger.ONE);
t--;
}
return ans;
}
public static long factorial(long n) {
if (n <= 1) {
return 1;
}
long t = n - 1;
while (t > 1) {
n = mod((mod(n, mod) * mod(t, mod)), mod);
t--;
}
return n;
}
public static long rev(long n) {
long t = n;
long ans = 0;
while (t > 0) {
ans = ans * 10 + t % 10;
t /= 10;
}
return ans;
}
public static boolean isPalindrome(int n) {
int t = n;
int ans = 0;
while (t > 0) {
ans = ans * 10 + t % 10;
t /= 10;
}
return ans == n;
}
static class tri {
int x, y, z;
public tri(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
@Override
public String toString() {
return x + " " + y + " " + z;
}
}
static boolean isPrime(long num) {
if (num == 1) {
return false;
}
if (num == 2) {
return true;
}
if (num % 2 == 0) {
return false;
}
if (num == 3) {
return true;
}
for (int i = 3; i <= Math.sqrt(num) + 1; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
public static void prefixSum(long[] a) {
for (int i = 1; i < a.length; i++) {
a[i] = a[i] + a[i - 1];
}
}
public static void suffixSum(long[] a) {
for (int i = a.length - 2; i > -1; i--) {
a[i] = a[i] + a[i + 1];
}
}
static long mod(long a, long b) {
long r = a % b;
return r < 0 ? r + b : r;
}
public static long binaryToDecimal(String w) {
long r = 0;
long l = 0;
for (int i = w.length() - 1; i > -1; i--) {
long x = (w.charAt(i) - '0') * (long) Math.pow(2, l);
r = r + x;
l++;
}
return r;
}
public static String decimalAnyBase(long n, long base) {
String w = "";
while (n > 0) {
w = n % base + w;
n /= base;
}
return w;
}
public static String decimalToBinary(long n) {
String w = "";
while (n > 0) {
w = n % 2 + w;
n /= 2;
}
return w;
}
public static boolean isSorted(int[] a) {
for (int i = 0; i < a.length - 1; i++) {
if (a[i] >= a[i + 1]) {
return false;
}
}
return true;
}
public static void print(long[] a) throws IOException {
for (int i = 0; i < a.length; i++) {
log.write(a[i] + " ");
}
log.write("\n");
}
public static void read(int[] a) {
for (int i = 0; i < a.length; i++) {
a[i] = input.nextInt();
}
}
static class gepair {
long x;
long y;
public gepair(long x, long y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return x + " " + y;
}
}
static class pair {
int x;
int y;
public pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return x + " " + y;
}
}
static class pai {
long x;
int y;
public pai(long x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return x + " " + y;
}
}
public static long LCM(long x, long y) {
return x / GCD(x, y) * y;
}
public static long GCD(long x, long y) {
if (y == 0) {
return x;
}
return GCD(y, x % y);
}
public static void simplifyTheFraction(int a, int b) {
long GCD = GCD(a, b);
System.out.println(a / GCD + " " + b / GCD);
}
static class Kattio extends PrintWriter {
private BufferedReader r;
private StringTokenizer st;
// standard input
public Kattio() {
this(System.in, System.out);
}
public Kattio(InputStream i, OutputStream o) {
super(o);
r = new BufferedReader(new InputStreamReader(i));
}
// USACO-style file input
public Kattio(String problemName) throws IOException {
super(problemName + ".out");
r = new BufferedReader(new FileReader(problemName + ".in"));
}
// returns null if no more input
String nextLine() {
String str = "";
try {
str = r.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public String next() {
try {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(r.readLine());
}
return st.nextToken();
} catch (Exception e) {
}
return null;
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 6efa44772bb2262d8cd89b84612a20af | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 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 dauom
*/
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);
AImmobileKnight solver = new AImmobileKnight();
int testCount = Integer.parseInt(in.next());
for (int i = 1; i <= testCount; i++)
solver.solve(i, in, out);
out.close();
}
static class AImmobileKnight {
public final void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int m = in.nextInt();
if (n > m) {
int t = n;
n = m;
m = t;
}
if (n >= 2 && n <= 3 && m >= 2 && m <= 3) {
out.println("2 2");
return;
}
out.println("1 1");
}
}
static final class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[1 << 18];
private int curChar;
private int numChars;
public InputReader() {
this.stream = System.in;
}
public InputReader(final InputStream stream) {
this.stream = stream;
}
private int read() {
if (this.numChars == -1) {
throw new UnknownError();
} else {
if (this.curChar >= this.numChars) {
this.curChar = 0;
try {
this.numChars = this.stream.read(this.buf);
} catch (IOException ex) {
throw new InputMismatchException();
}
if (this.numChars <= 0) {
return -1;
}
}
return this.buf[this.curChar++];
}
}
public final int nextInt() {
int c;
for (c = this.read(); isSpaceChar(c); c = this.read()) {
}
byte sgn = 1;
if (c == 45) { // 45 == '-'
sgn = -1;
c = this.read();
}
int res = 0;
while (c >= 48 && c <= 57) { // 48 == '0', 57 == '9'
res *= 10;
res += c - 48; // 48 == '0'
c = this.read();
if (isSpaceChar(c)) {
return res * sgn;
}
}
throw new InputMismatchException();
}
public final String next() {
int c;
while (isSpaceChar(c = this.read())) {
}
StringBuilder result = new StringBuilder();
result.appendCodePoint(c);
while (!isSpaceChar(c = this.read())) {
result.appendCodePoint(c);
}
return result.toString();
}
private static boolean isSpaceChar(final int c) {
return c == 32 || c == 10 || c == 13 || c == 9 || c == -1; // 32 == ' ', 10 == '\n', 13 == '\r', 9 == '\t'
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 7ffe36e784b151709d1f1d308e2e5655 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
static long mod = (int)1e9+7;
// static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
public static void main (String[] args) throws java.lang.Exception
{
FastReader sc =new FastReader();
int t=sc.nextInt();
// int t=1;
outer : while(t-->0)
{
int n = sc.nextInt();
int m = sc.nextInt();
if((n == 3 && m == 3) || (n == 2 && m == 3) || (n == 3 && m == 2))
{
System.out.println(2+" "+2);
}
else
{
System.out.println(n+" "+m);
}
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
float nextFloat()
{
return Float.parseFloat(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] readArrayLong(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
}
static class FenwickTree
{
//Binary Indexed Tree
//1 indexed
public int[] tree;
public int size;
public FenwickTree(int size)
{
this.size = size;
tree = new int[size+5];
}
public void add(int i, int v)
{
while(i <= size)
{
tree[i] += v;
i += i&-i;
}
}
public int find(int i)
{
int res = 0;
while(i >= 1)
{
res += tree[i];
i -= i&-i;
}
return res;
}
public int find(int l, int r)
{
return find(r)-find(l-1);
}
}
public static int[] radixSort2(int[] a)
{
int n = a.length;
int[] c0 = new int[0x101];
int[] c1 = new int[0x101];
int[] c2 = new int[0x101];
int[] c3 = new int[0x101];
for(int v : a) {
c0[(v&0xff)+1]++;
c1[(v>>>8&0xff)+1]++;
c2[(v>>>16&0xff)+1]++;
c3[(v>>>24^0x80)+1]++;
}
for(int i = 0;i < 0xff;i++) {
c0[i+1] += c0[i];
c1[i+1] += c1[i];
c2[i+1] += c2[i];
c3[i+1] += c3[i];
}
int[] t = new int[n];
for(int v : a)t[c0[v&0xff]++] = v;
for(int v : t)a[c1[v>>>8&0xff]++] = v;
for(int v : a)t[c2[v>>>16&0xff]++] = v;
for(int v : t)a[c3[v>>>24^0x80]++] = v;
return a;
}
private static long mergeAndCount(int[] arr, int l,
int m, int r)
{
// Left subarray
int[] left = Arrays.copyOfRange(arr, l, m + 1);
// Right subarray
int[] right = Arrays.copyOfRange(arr, m + 1, r + 1);
int i = 0, j = 0, k = l;long swaps = 0;
while (i < left.length && j < right.length) {
if (left[i] < right[j])
arr[k++] = left[i++];
else {
arr[k++] = right[j++];
swaps += (m + 1) - (l + i);
}
}
while (i < left.length)
arr[k++] = left[i++];
while (j < right.length)
arr[k++] = right[j++];
return swaps;
}
// Merge sort function
private static long mergeSortAndCount(int[] arr, int l,
int r)
{
// Keeps track of the inversion count at a
// particular node of the recursion tree
long count = 0;
if (l < r) {
int m = (l + r) / 2;
// Total inversion count = left subarray count
// + right subarray count + merge count
// Left subarray count
count += mergeSortAndCount(arr, l, m);
// Right subarray count
count += mergeSortAndCount(arr, m + 1, r);
// Merge count
count += mergeAndCount(arr, l, m, r);
}
return count;
}
static void my_sort(long[] arr)
{
ArrayList<Long> list = new ArrayList<>();
for(int i=0;i<arr.length;i++)
{
list.add(arr[i]);
}
Collections.sort(list);
for(int i=0;i<arr.length;i++)
{
arr[i] = list.get(i);
}
}
static void reverse_sorted(int[] arr)
{
ArrayList<Integer> list = new ArrayList<>();
for(int i=0;i<arr.length;i++)
{
list.add(arr[i]);
}
Collections.sort(list , Collections.reverseOrder());
for(int i=0;i<arr.length;i++)
{
arr[i] = list.get(i);
}
}
static int LowerBound(int a[], int x) { // x is the target value or key
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]>=x) r=m;
else l=m;
}
return r;
}
static int UpperBound(ArrayList<Integer> list, int x) {// x is the key or target value
int l=-1,r=list.size();
while(l+1<r) {
int m=(l+r)>>>1;
if(list.get(m)<=x) l=m;
else r=m;
}
return l+1;
}
public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm)
{
// Create a list from elements of HashMap
List<Map.Entry<Integer, Integer> > list =
new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet());
// Sort the list
Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() {
public int compare(Map.Entry<Integer, Integer> o1,
Map.Entry<Integer, Integer> o2)
{
return (o1.getValue()).compareTo(o2.getValue());
}
});
// put data from sorted list to hashmap
HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> aa : list) {
temp.put(aa.getKey(), aa.getValue());
}
return temp;
}
static class Queue_Pair implements Comparable<Queue_Pair> {
int first , second;
public Queue_Pair(int first, int second) {
this.first=first;
this.second=second;
}
public int compareTo(Queue_Pair o) {
return Integer.compare(o.first, first);
}
}
static void leftRotate(int arr[], int d, int n)
{
for (int i = 0; i < d; i++)
leftRotatebyOne(arr, n);
}
static void leftRotatebyOne(int arr[], int n)
{
int i, temp;
temp = arr[0];
for (i = 0; i < n - 1; i++)
arr[i] = arr[i + 1];
arr[n-1] = temp;
}
static boolean isPalindrome(String str)
{
// Pointers pointing to the beginning
// and the end of the string
int i = 0, j = str.length() - 1;
// While there are characters to compare
while (i < j) {
// If there is a mismatch
if (str.charAt(i) != str.charAt(j))
return false;
// Increment first pointer and
// decrement the other
i++;
j--;
}
// Given string is a palindrome
return true;
}
static boolean palindrome_array(char arr[], int n)
{
// Initialise flag to zero.
int flag = 0;
// Loop till array size n/2.
for (int i = 0; i <= n / 2 && n != 0; i++) {
// Check if first and last element are different
// Then set flag to 1.
if (arr[i] != arr[n - i - 1]) {
flag = 1;
break;
}
}
// If flag is set then print Not Palindrome
// else print Palindrome.
if (flag == 1)
return false;
else
return true;
}
static boolean allElementsEqual(int[] arr,int n)
{
int z=0;
for(int i=0;i<n-1;i++)
{
if(arr[i]==arr[i+1])
{
z++;
}
}
if(z==n-1)
{
return true;
}
else
{
return false;
}
}
static boolean allElementsDistinct(int[] arr,int n)
{
int z=0;
for(int i=0;i<n-1;i++)
{
if(arr[i]!=arr[i+1])
{
z++;
}
}
if(z==n-1)
{
return true;
}
else
{
return false;
}
}
public static void reverse(int[] array)
{
// Length of the array
int n = array.length;
// Swaping the first half elements with last half
// elements
for (int i = 0; i < n / 2; i++) {
// Storing the first half elements temporarily
int temp = array[i];
// Assigning the first half to the last half
array[i] = array[n - i - 1];
// Assigning the last half to the first half
array[n - i - 1] = temp;
}
}
public static void reverse_Long(long[] array)
{
// Length of the array
int n = array.length;
// Swaping the first half elements with last half
// elements
for (int i = 0; i < n / 2; i++) {
// Storing the first half elements temporarily
long temp = array[i];
// Assigning the first half to the last half
array[i] = array[n - i - 1];
// Assigning the last half to the first half
array[n - i - 1] = temp;
}
}
static boolean isSorted(int[] a)
{
for (int i = 0; i < a.length - 1; i++)
{
if (a[i] > a[i + 1]) {
return false;
}
}
return true;
}
static boolean isReverseSorted(int[] a)
{
for (int i = 0; i < a.length - 1; i++)
{
if (a[i] < a[i + 1]) {
return false;
}
}
return true;
}
static int[] rearrangeEvenAndOdd(int arr[], int n)
{
ArrayList<Integer> list = new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
{
list.add(arr[i]);
}
}
for(int i=0;i<n;i++)
{
if(arr[i]%2!=0)
{
list.add(arr[i]);
}
}
int len = list.size();
int[] array = list.stream().mapToInt(i->i).toArray();
return array;
}
static long[] rearrangeEvenAndOddLong(long arr[], int n)
{
ArrayList<Long> list = new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
{
list.add(arr[i]);
}
}
for(int i=0;i<n;i++)
{
if(arr[i]%2!=0)
{
list.add(arr[i]);
}
}
int len = list.size();
long[] array = list.stream().mapToLong(i->i).toArray();
return array;
}
static boolean isPrime(long n)
{
// Check if number is less than
// equal to 1
if (n <= 1)
return false;
// Check if number is 2
else if (n == 2)
return true;
// Check if n is a multiple of 2
else if (n % 2 == 0)
return false;
// If not, then just check the odds
for (long i = 3; i <= Math.sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
static long getSum(long n)
{
long sum = 0;
while (n != 0)
{
sum = sum + n % 10;
n = n/10;
}
return sum;
}
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static long gcdLong(long a, long b)
{
if (b == 0)
return a;
return gcdLong(b, a % b);
}
static void swap(int i, int j)
{
int temp = i;
i = j;
j = temp;
}
static int countDigit(int n)
{
return (int)Math.floor(Math.log10(n) + 1);
}
}
class Pair
{
int first;
int second;
Pair(int first , int second)
{
this.first = first;
this.second = second;
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 1a0d040aceaafc518083d36f46684672 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | /**
* @author Nitin Bhakar
*
*/
import java.io.*;
import java.util.*;
public class Codeforces{
static long mod = 1000000007L;
static int ninf = Integer.MIN_VALUE;
static int inf = Integer.MAX_VALUE;
static void swap(int[] a,int i,int j) {int temp = a[i]; a[i] = a[j]; a[j] = temp;}
static void priArr(int[] a) {for(int i=0;i<a.length;i++) out.print(a[i] + " ");out.println();}
static long gcd(long a,long b){if(b==0) return a; return gcd(b,a%b);}
static int gcd(int a,int b){ if(b==0) return a;return gcd(b,a%b);}
static void sieve(boolean[] a, int n) {a[1] = false; for(int i=2;i*i<=n;i++) { if(a[i]) { for(int j=i*i;j<=n;j+=i) a[j] = false;}}}
static int getRanNum(int lo, int hi) {return (int)Math.random()*(hi-lo+1)+lo;}
private static void sort(int[] arr) {List<Integer> list = new ArrayList<>();for (int i=0; i<arr.length; i++)list.add(arr[i]);Collections.sort(list);for (int i = 0; i < arr.length; i++)arr[i] = list.get(i);}
// private static long power(int n, int m) {long res = 1;while(m>0) {if(m%2 != 0) {res *= n; m--;}n *=n;m/=2;}return res;}
//map.put(a[i],map.getOrDefault(a[i],0)+1);
// map.putIfAbsent;
// StringBuilder ans = new StringBuilder();
static MyScanner sc = new MyScanner();
static int[][] dp;
//<----------------------------------------------WRITE HERE------------------------------------------->
static void solve(){
int n = sc.nextInt()/2;
int m = sc.nextInt()/2;
n++;
m++;
out.println(n+" "+m);
}
static int intLen(int n) {
int s = 0;
while(n>0) {
n /= 10;
s++;
}
return s;
}
//<----------------------------------------------WRITE HERE------------------------------------------->
static class Pair implements Comparable<Pair> {
int v1;
int v2;
Pair(){}
Pair(int v,int f){
v1 = v;
v2 = f;
}
public int compareTo(Pair p){
if(this.v1 == p.v1) return p.v2-this.v2;
return this.v1-p.v1;
}
}
public static void main(String[] args) {
out = new PrintWriter(new BufferedOutputStream(System.out));
int t = sc.nextInt();
// int t= 1;
while(t-- >0){
solve();
}
// Stop writing your solution here. -------------------------------------
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();
}
public int[] readIntArray(int n){
int arr[] = new int[n];
for(int i = 0;i<n;i++){
arr[i] = Integer.parseInt(next());
}
return arr;
}
int[] reverse(int arr[]){
int n= arr.length;
int i = 0;
int j = n-1;
while(i<j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
j--;i++;
}
return arr;
}
long[] readLongArray(int n){
long arr[] = new long[n];
for(int i = 0;i<n;i++){
arr[i] = Long.parseLong(next());
}
return arr;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | c04f9deb2f5b7631ed3d452f48852d63 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
import java.io.*;
public class practice {
static char vowels[] = new char[]{'a', 'e', 'i', 'o', 'u'};
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new PrintWriter(System.out)));
StringBuilder sb = new StringBuilder();
int t = Integer.parseInt(br.readLine());
while (t --> 0) {
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
if (n == 1 || m == 1) sb.append(1).append(" ").append(1);
else if (n == 2 && m == 2) sb.append(1).append(" ").append(1);
else if (n == 3 && m == 3) sb.append(2).append(" ").append(2);
else sb.append(2).append(" ").append(2);
sb.append("\n");
}
pw.println(sb.toString().trim());
pw.close();
br.close();
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 350f71c51cd8da3b4b4d12d6f027c28b | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in= new Scanner (System.in);
int t=in.nextInt();
while(t--!=0){
int r=in.nextInt();
int c=in.nextInt();
if(r==1 || c==1)
System.out.println(r+" "+c);
else if(c==2 && r<=3)
System.out.println(2+" "+1);
else if(r==2 && c<=3)
System.out.println(1+" "+2);
else if(r==3 && c==3){
System.out.println(2+" "+2);}
else
System.out.println(r+" "+c);
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | caed59a4ba10293b5972b551188d79b2 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;
public class Hello {
static long mod = Long.MAX_VALUE;
public static void main(String[] args) {
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
FastReader f = new FastReader();
int t = f.nextInt();
while(t-- > 0){
solve(f, out);
}
out.close();
}
public static void solve(FastReader f, PrintWriter out) {
int n = f.nextInt();
int m = f.nextInt();
out.println((n/2 + 1) + " " + (m/2 + 1));
}
// Sort an array
public static void sort(int arr[]) {
ArrayList<Integer> al = new ArrayList<>();
for(int i: arr) {
al.add(i);
}
Collections.sort(al);
for(int i = 0; i < arr.length; i++) {
arr[i] = al.get(i);
}
}
// Find all divisors of n
public static void allDivisors(int n) {
for(int i = 1; i*i <= n; i++) {
if(n%i == 0) {
System.out.println(i + " ");
if(i != n/i) {
System.out.println(n/i + " ");
}
}
}
}
// Check if n is prime or not
public static boolean isPrime(int n) {
if(n < 1) return false;
if(n == 2 || n == 3) return true;
if(n % 2 == 0 || n % 3 == 0) return false;
for(int i = 5; i*i <= n; i += 6) {
if(n % i == 0 || n % (i+2) == 0) {
return false;
}
}
return true;
}
// Find gcd of a and b
public static long gcd(long a, long b) {
long dividend = a > b ? a : b;
long divisor = a < b ? a : b;
while(divisor > 0) {
long reminder = dividend % divisor;
dividend = divisor;
divisor = reminder;
}
return dividend;
}
// Find lcm of a and b
public static long lcm(long a, long b) {
long lcm = gcd(a, b);
long hcf = (a * b) / lcm;
return hcf;
}
// Find factorial in O(n) time
public static long fact(int n) {
long res = 1;
for(int i = 2; i <= n; i++) {
res = res * i;
}
return res;
}
// Find power in O(logb) time
public static long power(long a, long b) {
long res = 1;
while(b > 0) {
if((b&1) == 1) {
res = (res * a)%mod;
}
a = (a * a)%mod;
b >>= 1;
}
return res;
}
// Find nCr
public static long nCr(int n, int r) {
if(r < 0 || r > n) {
return 0;
}
long ans = fact(n) / (fact(r) * fact(n-r));
return ans;
}
// Find nPr
public static long nPr(int n, int r) {
if(r < 0 || r > n) {
return 0;
}
long ans = fact(n) / fact(r);
return ans;
}
// sort all characters of a string
public static String sortString(String inputString) {
char tempArray[] = inputString.toCharArray();
Arrays.sort(tempArray);
return new String(tempArray);
}
// User defined class for fast I/O
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
boolean hasNext() {
if (st != null && st.hasMoreTokens()) {
return true;
}
String tmp;
try {
br.mark(1000);
tmp = br.readLine();
if (tmp == null) {
return false;
}
br.reset();
} catch (IOException e) {
return false;
}
return true;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
float nextFloat() {
return Float.parseFloat(next());
}
boolean nextBoolean() {
return Boolean.parseBoolean(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] nextArray(int n) {
int[] a = new int[n];
for(int i=0; i<n; i++) {
a[i] = nextInt();
}
return a;
}
}
}
/**
Dec Char Dec Char Dec Char Dec Char
--------- --------- --------- ----------
0 NUL (null) 32 SPACE 64 @ 96 `
1 SOH (start of heading) 33 ! 65 A 97 a
2 STX (start of text) 34 " 66 B 98 b
3 ETX (end of text) 35 # 67 C 99 c
4 EOT (end of transmission) 36 $ 68 D 100 d
5 ENQ (enquiry) 37 % 69 E 101 e
6 ACK (acknowledge) 38 & 70 F 102 f
7 BEL (bell) 39 ' 71 G 103 g
8 BS (backspace) 40 ( 72 H 104 h
9 TAB (horizontal tab) 41 ) 73 I 105 i
10 LF (NL line feed, new line) 42 * 74 J 106 j
11 VT (vertical tab) 43 + 75 K 107 k
12 FF (NP form feed, new page) 44 , 76 L 108 l
13 CR (carriage return) 45 - 77 M 109 m
14 SO (shift out) 46 . 78 N 110 n
15 SI (shift in) 47 / 79 O 111 o
16 DLE (data link escape) 48 0 80 P 112 p
17 DC1 (device control 1) 49 1 81 Q 113 q
18 DC2 (device control 2) 50 2 82 R 114 r
19 DC3 (device control 3) 51 3 83 S 115 s
20 DC4 (device control 4) 52 4 84 T 116 t
21 NAK (negative acknowledge) 53 5 85 U 117 u
22 SYN (synchronous idle) 54 6 86 V 118 v
23 ETB (end of trans. block) 55 7 87 W 119 w
24 CAN (cancel) 56 8 88 X 120 x
25 EM (end of medium) 57 9 89 Y 121 y
26 SUB (substitute) 58 : 90 Z 122 z
27 ESC (escape) 59 ; 91 [ 123 {
28 FS (file separator) 60 < 92 \ 124 |
29 GS (group separator) 61 = 93 ] 125 }
30 RS (record separator) 62 > 94 ^ 126 ~
31 US (unit separator) 63 ? 95 _ 127 DEL
*/
// (a/b)%mod == (a * moduloInverse(b)) % mod;
// moduloInverse(b) = power(b, mod-2);
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | c8b5a8d541cf9ba0380de1fe8c690f5d | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
public class testing11 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int w = 0; w < t; w++){
int row = in.nextInt();
int col = in.nextInt();
boolean flag = false;
block:{
for(int i = 1; i <= row; i++){
for(int j = 1; j <= col; j++){
boolean a = (j-2 > 0 && (i-1 > 0 || i+1 <= row));
boolean b = (j+2 <= col && (i-1 > 0 || i+1 <= row));
boolean c = (j-1 > 0 && (i-2 > 0 || i+2 <= row));
boolean d = (j+1 <= col && (i-2 > 0 || i+2 <= row));
if(!a && !b && !c && !d) {
System.out.println(i + " " + j);
flag = true;
break block;
}
}
}
}
if(!flag) System.out.println(row + " " + col);
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 14d6719c05c37443b23a3019e6926031 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
public class ImmobileKnight {
public static void main(String[] args) {
var scan=new Scanner(System.in);
int t =scan.nextInt();
for (int i = 0; i < t; i++) {
int n=scan.nextInt();
int m=scan.nextInt();
printSol(n,m);
}
scan.close();
}
private static void printSol(int n, int m) {
System.out.println( (int)Math.ceil(n/2.0)+" "+ (int)Math.ceil(m/2.0));
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 8ce73811a280266f8338c7597ff66217 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
public class ImmobileKnight{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=1;i<=t;i++)
{
int n=sc.nextInt();
int m=sc.nextInt();
if(Math.max(n,m)==3)
{
if(Math.min(m,n)==1)
{
System.out.println("1 1");
}
else
{
System.out.println("2 2");
}
}
else
{
System.out.println("1 1");
}
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 13e2c35feb96032c5003c927da99cc86 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class behenkalora
{
public static void main(String args[])
{
Scanner rdj = new Scanner(System.in);
int t = rdj.nextInt();
while(t-->0)
{
int n =rdj.nextInt(),m =rdj.nextInt();
int k=Math.min(n,2),l=Math.min(m,2);
System.out.println(k+" "+l);
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | fd759344018a2cb0f59b1fc7d6d1e971 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class ECR136A {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int i = 0; i < t; i++) {
int n = in.nextInt();
int m = in.nextInt();
if ((n == 2 && m == 3) || (n == 3 && m == 2) || (n == 3 && m == 3)) {
System.out.println("2 2");
continue;
}
System.out.println("1 1");
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 7bd62cfa3066f3a5b149a2b1a2067350 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
import java.util.HashSet;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.TreeSet;
import java.util.PriorityQueue;
public class Solution{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int test_cases = sc.nextInt();
outer : for(int h=0;h<test_cases;h++){
//scan the input
int row = sc.nextInt();
int column = sc.nextInt();
if(row==3 && column==3){
System.out.println(2+" "+2);
}
else if(row==2 && column == 3){
System.out.println(1+" "+2);
}
else if(row==3 && column == 2){
System.out.println(2+" "+1);
}
else{
System.out.println(1+" "+1);
}
}
sc.close();
}
public static void scan_string_array(String s[] , int n, Scanner sc){
for(int i=0;i<n;i++){
s[i] = sc.next();
}
}
public static void swap_elements(int a[], int s_index, int e_index){
int temp = a[s_index];
a[s_index] = a[e_index];
a[e_index] = temp;
}
public static void scan_array_long(long a[], int n, Scanner sc){
for(int i=0;i<n;i++){
a[i] = sc.nextLong();
}
}
public static void scan_array(int a[], int n, Scanner sc){
for(int i=0;i<n;i++){
a[i] = sc.nextInt();
}
}
public static void print_array(int a[]){
for(int i=0;i<a.length;i++){
if(i==a.length-1){
System.out.println(a[i]);
return;
}
System.out.print(a[i]+" ");
}
}
public static long sum_array(long a[]){
long sum = 0;
for(int i=0;i<a.length;i++){
sum+=a[i];
}
return sum;
}
public static boolean perfect_square(double num){
boolean isSq = false;
double b = Math.sqrt(num);
double c = Math.sqrt(num) - Math.floor(b);
if(c==0){
isSq=true;
}
return isSq;
}
public static boolean ispalindrome(String s){
int i=0, j =s.length()-1;
while(i<=j){
if(s.charAt(i)!=s.charAt(j)){
return false;
}
i++;
j--;
}
return true;
}
public static boolean ispowerOftwo(int n){
if(n>0 && (int)(n & (n-1))==0){
return true;
}
else{
return false;
}
}
public static int calculate_gcd(int x,int y){
int gcd = 1;
if(x%y==0){
return y;
}
else if(y%x==0){
return x;
}
else{
for(int i=2;i<=x && i<=y;i++){
if(x%i==0 && y%i==0){
gcd = i;
}
}
return gcd;
}
}
public static long calculate_factorial(long x){
long ans = 1;
for(int i=1;i<=x;i++){
ans*=i;
}
return ans;
}
public static void swap(int a[], int b[], int index_a, int index_b){
int temp = a[index_a];
a[index_a] = b[index_b];
b[index_b] = temp;
}
public static int find_maximum(int a[]){
int max = Integer.MIN_VALUE;
for(int i=0;i<a.length;i++){
max = Math.max(a[i], max);
}
return max;
}
public static int find_minimum(int a[]){
int min = Integer.MAX_VALUE;
for(int i=0;i<a.length;i++){
min = Math.min(a[i], min);
}
return min;
}
public static void ruffleSort(int[] a) {
int n=a.length;//shuffle, then sort
Random random = new Random();
for (int i=0; i<n; i++) {
int oi=random.nextInt(n);
int temp=a[oi];
a[oi]=a[i];
a[i]=temp;
}
Arrays.sort(a);
}
public static int sum_of_digits(int n){
int s =0;
while(n!=0){
s+=n%10;
n/=10;
}
return s;
}
public static int[] mergeSort(int[] array) {
if (array.length <= 1) {
return array;
}
int midpoint = array.length / 2;
int[] left = new int[midpoint];
int[] right;
if (array.length % 2 == 0) {
right = new int[midpoint];
} else {
right = new int[midpoint + 1];
}
for (int i = 0; i < left.length; i++) {
left[i] = array[i];
}
for (int i = 0; i < right.length; i++) {
right[i] = array[i + midpoint];
}
int[] result = new int[array.length];
left = mergeSort(left);
right = mergeSort(right);
result = merge(left, right);
return result;
}
public static int[] merge(int[] left, int[] right) {
int[] result = new int[left.length + right.length];
int leftPointer = 0, rightPointer = 0, resultPointer = 0;
while (leftPointer < left.length || rightPointer < right.length) {
if (leftPointer < left.length && rightPointer < right.length) {
if (left[leftPointer] < right[rightPointer]) {
result[resultPointer++] = left[leftPointer++];
} else {
result[resultPointer++] = right[rightPointer++];
}
} else if (leftPointer < left.length) {
result[resultPointer++] = left[leftPointer++];
} else {
result[resultPointer++] = right[rightPointer++];
}
}
return result;
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | c36cd6fb459a9a749f374ec46df42096 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int m = sc.nextInt();
if(n <= 3 && m <= 3) System.out.println((n == 3 ? 2 : 1) + " " + (m == 3 ? 2 : 1));
else System.out.println("1 1");
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | da8ddcc894487ae944054efbb0821ae8 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes |
import com.sun.source.tree.Tree;
import java.io.*;
import java.util.*;
public class Main {
// private static int[][] dirs = {{-1,-1}, {1, 1}, {-1, 1}, {1, -1}};
private static int[][] dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
private static long inf = (long) 1e13;
private static long div = 998_244_353L;
// private static long div = ((long)1e9) + 7;
private static void swap(int[] arr, int i, int j) {
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
private static void swap(char[] arr, int i, int j) {
char tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
private static void perms(int offset, List<List<Integer>> perms, int[] arr) {
if (offset == arr.length) {
List<Integer> perm = new ArrayList<>();
for (int j : arr) perm.add(j);
perms.add(perm);
return;
}
for(int i = offset; i < arr.length; ++i) {
swap(arr, offset, i);
perms(offset + 1, perms, arr);
swap(arr, offset, i);
}
}
private static List<List<Integer>> perms(int[] arr) {
List<List<Integer>> perms = new ArrayList<>();
perms(0, perms, arr);
return perms;
}
private static long pow(long num, long pow, long div) {
if (pow == 0) return 1L;
long res = pow(num, pow/2, div);
long ret = 1;
if (pow % 2 != 0) ret = num % div;
ret = (ret * res) % div;
ret = (ret * res) % div;
return ret;
}
public static void main(String[] commands) throws Exception {
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
String[] parts = rd.readLine().split(" ");
int Q = Integer.parseInt(parts[0]);
BufferedOutputStream bfo = new BufferedOutputStream(System.out);
outer: for(int q = 0;q < Q; ++q) {
parts = rd.readLine().split(" ");
int rows = Integer.parseInt(parts[0]);
int cols = Integer.parseInt(parts[1]);
for(int row = 0;row < rows; ++row) {
for(int col = 0;col < cols; ++col) {
boolean isolidated = true;
for(int dr = -2; dr <= 2; dr += 4) {
for(int dc = -1; dc <= 1 ; dc += 2) {
int nr = row + dr;
int nc = col + dc;
if (nr >= 0 && nr < rows && nc >= 0 && nc < cols) {
isolidated = false;
break;
}
}
}
for(int dc = -2; dc <= 2; dc += 4) {
for(int dr = -1; dr <= 1 ; dr += 2) {
int nr = row + dr;
int nc = col + dc;
if (nr >= 0 && nr < rows && nc >= 0 && nc < cols) {
isolidated = false;
break;
}
}
}
if (isolidated) {
bfo.write(((row +1) + " " + (col + 1) + "\n").getBytes());
continue outer;
}
}
}
bfo.write((1 + " " + 1 + "\n").getBytes());
}
bfo.flush();
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | a916807ad8904eb2b26dabb122b74169 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
public class A1739 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n, m;
n = sc.nextInt();
m = sc.nextInt();
boolean isolatedCellFound = false;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <=m; j++) {
if (!isolatedCellFound && isCellIsolated(i, j, n, m)) {
System.out.println(i + " " + j);
isolatedCellFound = true;
}
}
}
if (!isolatedCellFound) {
System.out.println(n + " " + m);
}
}
}
static boolean isCellIsolated(int x, int y, int n, int m) {
int[] dx = {1, 1, 2, 2, -1, -1, -2, -2};
int[] dy = {-2, +2, -1, +1, -2, +2, -1, +1};
for (int i = 0; i < 8; i++) {
if (x + dx[i] >= 1 && x + dx[i] <= n && y + dy[i] >= 1 && y + dy[i] <=m) {
return false;
}
}
return true;
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | bc3c3a4f5d7ef1aa14a89323a7424386 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes |
import java.util.*;
public class Knights{
public static void main(String[] args){
Scanner sc =new Scanner(System.in);
int t =sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int m =sc.nextInt();
n = n/2+1;
m =m/2+1;
System.out.println(n+" "+ m);
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 16915cd7441fa045e2f32298be137f9e | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
import java.io.*;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.math.BigInteger;
public class Main{
static class P {
String g;
int x , y;
P(String g,int x ,int y) {
this.x = x;
this.y = y;
this.g = g;
}
}
static class Node {
long sum, pre;
Node(long a, long b) {
this.sum = a;
this.pre = b;
}
}
static class SegmentTree {
int l , r; // range responsible for
SegmentTree left , right;
int val;
SegmentTree(int l,int r,int a[]) {
this.l = l;
this.r = r;
if(l == r) {
this.val = a[l];
return;
}
int mid = l + (r-l)/2;
this.left = new SegmentTree(l ,mid , a);
this.right = new SegmentTree(mid + 1 , r,a);
this.val = this.left.val + this.right.val;
}
public int query(int left ,int right) {
if(this.l > right || this.r < left) return 0;
if(this.l >= left && this.r <= right) return this.val;
return this.left.query(left , right) + this.right.query(left , right);
}
// public void pointUpdate(int index ,long val) {
// if(this.l > index || this.r < index) return;
// if(this.l == this.r && this.l == index) {
// this.val = val;
// }
// this.left.pointUpdate(index ,val );
// this.right.pointUpdate(index , val);
// this.val = (this.left.val + this.right.val)%this.mod;
// }
public void rangeUpdate(int left , int right) {
if(this.l > right || this.r < left) return;
if(this.l >= left && this.r <= right) {
this.val += this.r-this.l + 1;
System.out.println(" now " + this.val);
return ;
}
this.left.rangeUpdate(left , right );
this.right.rangeUpdate(left , right );
this.val = this.left.val + this.right.val;
}
// public long valueAtK(int k) {
// if(this.l > k || this.r < k) return 0;
// if(this.l == this.r && this.l == k) {
// return this.val;
// }
// return join(this.left.valueAtK(k) , this.right.valueAtK(k));
// }
public int join(int a ,int b) {
return a + b;
}
}
static class Hash {
long hash[] ,mod = (long)1e9 + 7 , powT[] , prime , inverse[];
Hash(char []s) {
prime = 131;
int n = s.length;
powT = new long[n];
hash = new long[n];
inverse = new long[n];
powT[0] = 1;
inverse[n-1] = pow(pow(prime , n-1 ,mod), mod-2 , mod);
for(int i = 1;i < n; i++ ) {
powT[i] = (powT[i-1]*prime)%mod;
}
for(int i = n-2; i>= 0;i-=1) {
inverse[i] = (inverse[i+1]*prime)%mod;
}
hash[0] = (s[0] - 'a' + 1);
for(int i = 1; i < n;i++ ) {
hash[i] = hash[i-1] + ((s[i]-'a' + 1)*powT[i])%mod;
hash[i] %= mod;
}
}
public long hashValue(int l , int r) {
if(l == 0) return hash[r]%mod;
long ans = hash[r] - hash[l-1] +mod;
ans %= mod;
// System.out.println(inverse[l] + " " + pow(powT[l], mod- 2 , mod));
ans *= inverse[l];
ans %= mod;
return ans;
}
}
static class ConvexHull {
Stack<Integer>stack;
Stack<Integer>stack1;
int n;
Point arr[];
ConvexHull(Point arr[]) {
n = arr.length;
this.arr = arr;
Arrays.sort(arr , (a , b)-> {
if(a.x == b.x) return (int)(b.y-a.y);
return (int)(a.x-b.x);
});
Point min = arr[0];
stack = new Stack<>();
stack1 = new Stack<>();
stack.push(0);
stack1.push(0);
Point ob = new Point(2,2);
for(int i =1;i < n;i++) {
if(stack.size() < 2) stack.push(i);
else {
while(stack.size() >= 2) {
int a = stack.pop() , b = stack.pop() ,c = i;
int dir = ob.cross(arr[b] , arr[a] , arr[c]);
if(dir < 0) {
stack.push(b);
stack.push(a);
stack.push(c);
break;
}
stack.push(b);
}
if(stack.size() < 2) {
stack.push(i);
}
}
}
for(int i =1;i < n;i++) {
if(stack1.size() < 2) stack1.push(i);
else {
while(stack1.size() >= 2) {
int a = stack1.pop() , b = stack1.pop() ,c = i;
int dir = ob.cross(arr[b] , arr[a] , arr[c]);
if(dir > 0) {
stack1.push(b);
stack1.push(a);
stack1.push(c);
break;
}
stack1.push(b);
}
if(stack1.size() < 2) {
stack1.push(i);
}
}
}
}
public List<Point> getPoints() {
boolean vis[] = new boolean[n];
List<Point> list = new ArrayList<>();
// for(int x : stack) {
// list.add(arr[x]);
// vis[x] = true;
// }
for(int x : stack1) {
// if(vis[x]) continue;
list.add(arr[x]);
}
return list;
}
}
public static class Suffix implements Comparable<Suffix> {
int index;
int rank;
int next;
public Suffix(int ind, int r, int nr) {
index = ind;
rank = r;
next = nr;
}
public int compareTo(Suffix s) {
if (rank != s.rank) return Integer.compare(rank, s.rank);
return Integer.compare(next, s.next);
}
}
static class Point {
long x , y;
Point(long x , long y) {
this.x = x;
this.y = y;
}
public Point sub(Point a,Point b) {
return new Point(a.x - b.x , a.y-b.y);
}
public int cross(Point a ,Point b , Point c) {
Point g = sub(b,a) , l = sub(c, b);
long ans = g.y*l.x - g.x*l.y;
if(ans == 0) return 0;
if(ans < 0) return -1;
return 1;
}
}
static class Kattio extends PrintWriter {
private BufferedReader r;
private StringTokenizer st;
// standard input
public Kattio() { this(System.in, System.out); }
public Kattio(InputStream i, OutputStream o) {
super(o);
r = new BufferedReader(new InputStreamReader(i));
}
// USACO-style file input
public Kattio(String problemName) throws IOException {
super(new FileWriter(problemName + ".out"));
r = new BufferedReader(new FileReader(problemName + ".in"));
}
// returns null if no more input
public String next() {
try {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(r.readLine());
return st.nextToken();
} catch (Exception e) { }
return null;
}
public int nextInt() { return Integer.parseInt(next()); }
public double nextDouble() { return Double.parseDouble(next()); }
public long nextLong() { return Long.parseLong(next()); }
}
static HashMap<Integer ,List<int[]>> graph;
static Kattio sc = new Kattio();
static long mod = 998244353l;
static String endl = "\n" , gap = " ";
static HashMap<Integer , Long> value;
static int size[];
static int parent[];
static long fac[];
static long inv[];
static boolean vis[];
static int answer;
static HashSet<String> guess;
static long primePow[];
static int N;
static int dis[];
static int height[];
static long p[];
static int endTime[];
static int time;
static Long dp[][];
static HashMap<String , Long> dmap;
static long dirpair[][];
static HashSet<String> not;
static SegmentTree tree;
public static void main(String[] args)throws IOException {
long t = ri();
// int max = (int)1e5 + 10;
// fac = new long[max];
// fac[0] = 1;
// inv = new long[max];
// inv[0]= inverse(fac[0] ,mod);
// long mod = (long)1e9 + 7;
// for(int i = 1;i < max;i++) {
// fac[i] = i*fac[i-1];
// fac[i] %= mod;
// inv[i]= inverse(fac[i] ,mod);
// }
// List<Integer> list = new ArrayList<>();
// int MAX = (int)4e4;
// for(int i =1;i<=MAX;i++) {
// if(isPalindrome(i + "")) list.add(i);
// }
// // System.out.println(list);
// long dp[] = new long[MAX +1];
// dp[0] = 1;
// long mod = (long)(1e9+7);
// for(int x : list) {
// for(int i =1;i<=MAX;i++) {
// if(i >= x) {
// dp[i] += dp[i-x];
// dp[i] %= mod;
// }
// }
// }
// int MAK = (int)1e5 + 1;
// boolean seive[] = new boolean[MAK];
// Arrays.fill(seive , true);
// seive[1] = false;
// seive[0] = false;
// for (int i = 1; i < MAK; i++) {
// if(seive[i]) {
// for (int j = i+i; j < MAK; j+=i) {
// seive[j] = false;
// }
// }
// }
// // TreeSet<Long>primeSet = new TreeSet<>();
// // for(long i = 2;i <= (long)1e6;i++) {
// // if(seive[(int)i])primeSet.add(i);
// // }
// int MAX = (int)1e5 + 1;
// ArrayList<Integer> a[] = new ArrayList[MAX];
// for(int i =0;i < a.length;i++) a[i] = new ArrayList<>();
// boolean notPrime[] = new boolean[MAX];
// for(int i = 2;i<MAX;i++){
// if(notPrime[i]) continue;
// for(int j = i;j<MAX;j+=i){
// notPrime[j] = true;
// a[j].add(i);
// }
// }
int test_case = 1;
while(t-->0) {
// sc.print("Case #"+(test_case++)+": ");
solve();
}
sc.close();
}
public static int get(int x,int tree[]) {
int index = x;
int ans =0;
while(index > 0) {
ans += tree[index];
index -= index&(-index);
}
return ans;
}
public static void solve() throws IOException {
int n = ri() , m = ri();
int colx[] = {1 ,1 ,-1,-1,2,2,-2,-2};
int coly[] = {2 , -2,-2,2,1,-1,1,-1};
for(int i = 0;i < n;i++) {
for(int j = 0;j < m;j++) {
int cnt = 0;
for(int k = 0;k <colx.length;k++) {
int nr = colx[k] + i , nc = coly[k] + j;
if(nr < 0 || nc < 0 || nr >= n || nc >= m) continue;
cnt++;
}
if(cnt == 0) {
System.out.println((i + 1) + " " + (j + 1));
return ;
}
}
}
System.out.println(1 + " " + 1);
}
public static boolean solve(int i , int k,long g,long a[]) {
System.out.println(g);
int n = a.length;
if(i >= n-1) return true;
if(i == -1) return true;
for(int j = i;;j += k) {
if(g < 0) return false;
g += a[j];
if(g < 0) return false;
if(j == 0 && k == -1) break;
if(j == n-1 && k == 1) break;
}
return true;
}
public static boolean can(int m,int a[][],int n) {
List<int[]> l = new ArrayList<>();
// System.out.println("for m " + m);
for(int b[] : a) if(b[2] <= m) l.add(b);
// for(int b[] : l) System.out.print(Arrays.toString(b));
// System.out.println();
Collections.sort(l,(p,q)-> {
if(p[0] == q[0]) return q[1] - p[1];
return p[0] - q[0];
});
int now = 1;
for(int b[] : l) {
if(b[0] > now) return false;
now = Math.max(now , b[1] + 1);
}
return now >= n;
}
public static long solve(int i,int min,int A[][]) {
if(min < 0) return 0;
long mod = (long)1e9 + 7;
if(i == -1) {
return min >= 0?1:0;
}
if(dp[i][min] != null) return dp[i][min];
long ans = solve(i - 1 ,min - A[i][1],A);
ans %= mod;
ans += solve(i -1 , min,A);
ans %= mod;
return dp[i][min] = ans;
}
public static boolean can(HashMap<Integer , Integer> m1 , HashMap<Integer , Integer> m2) {
long g = 0;
for(int x : m2.keySet()) {
if(!m1.containsKey(x)) g += m2.get(x);
else g+= Math.abs(m1.get(x)-m2.get(x));
if(g > 1) return false;
}
for(int x : m1.keySet()) {
if(!m2.containsKey(x))g += m1.get(x);
if(g > 1) return false;
}
return g == 1;
}
public static long lcm(long x , long y) {
return x/gcd(x , y)*y;
}
public static long ncr(int a , int b,long mod) {
if(a == b) return 1l;
return (((fac[a]*inv[b])%mod)*inv[a-b])%mod;
}
static long turnOffK(long n, long k) {
return (n & ~(1l << (k)));
}
public static void swap(int i,int j,int arr[]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static long max(long ...a) {
return maxArray(a);
}
public static void swap(int i,int j,long arr[]) {
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void swap(int i,int j,char arr[]) {
char temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static String slope(Point a , Point b) {
if((a.x-b.x) == 0) return "inf";
long n = a.y- b.y;
if(n == 0) return "0";
long m = a.x-b.x;
boolean neg = (n*m < 0?true:false);
n = Math.abs(n);
m = Math.abs(m);
long g = gcd(Math.abs(n),Math.abs(m));
n /= g;
m /= g;
String ans = n+"/"+m;
if(neg) ans = "-" + ans;
return ans;
}
public static int lis(int A[], int size) {
int[] tailTable = new int[size];
int len;
tailTable[0] = A[0];
len = 1;
for (int i = 1; i < size; i++) {
if (A[i] < tailTable[0]) tailTable[0] = A[i];
else if (A[i] > tailTable[len - 1]) tailTable[len++] = A[i];
else tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i];
}
return len;
}
public static int CeilIndex(int A[], int l, int r, int key) {
while (r - l > 1) {
int m = l + (r - l) / 2;
if (A[m] >= key) r = m;
else l = m;
}
return r;
}
public static int lcs(char a[] , char b[]) {
int n = a.length , m = b.length;
int dp[][] = new int[n + 1][m + 1];
for(int i =1;i <= n;i++) {
for(int j =1;j <= m;j++) {
if(a[i-1] == b[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
else dp[i][j] = Math.max(dp[i-1][j] , dp[i][j-1]);
}
}
return dp[n][m];
}
public static int find(int node) {
if(node == parent[node]) return node;
return parent[node] = find(parent[node]);
}
public static void merge(int a ,int b ) {
a = find(a);
b = find(b);
if(a == b) return;
if(size[a] >= size[b]) {
parent[b] = a;
size[a] += size[b];
// primePow[a] += primePow[b];
// primePow[b] = 0;
}
else {
parent[a] = b;
size[b] += size[a];
// primePow[b] += primePow[a];
// primePow[a] = 0;
}
}
public static void processPowerOfP(long arr[]) {
int n = arr.length;
arr[0] = 1;
long mod = (long)1e9 + 7;
for(int i =1;i<n;i++) {
arr[i] = arr[i-1]*51;
arr[i] %= mod;
}
}
public static long hashValue(char s[]) {
int n = s.length;
long powerOfP[] = new long[n];
processPowerOfP(powerOfP);
long ans =0;
long mod = (long)1e9 + 7;
for(int i =0;i<n;i++) {
ans += (s[i]-'a'+1)*powerOfP[i];
ans %= mod;
}
return ans;
}
public static void dfs(int r,int c,char arr[][]) {
int n = arr.length , m = arr[0].length;
arr[r][c] = '#';
for(int i =0;i<4;i++) {
int nr = r + colx[i] , nc = c + coly[i];
if(nr < 0 || nc < 0 || nc >= m || nr>=n) continue;
if(arr[nr][nc] == '#') continue;
dfs(nr,nc,arr);
}
}
public static double getSlope(int a , int b,int x,int y) {
if(a-x == 0) return Double.MAX_VALUE;
if(b-y == 0) return 0.0;
return ((double)b-(double)y)/((double)a-(double)x);
}
public static boolean collinearr(long a[] , long b[] , long c[]) {
return (b[1]-a[1])*(b[0]-c[0]) == (b[0]-a[0])*(b[1]-c[1]);
}
public static boolean isSquare(long sum) {
long root = (int)Math.sqrt(sum);
return root*root == sum;
}
public static int[] suffixArray(String s) {
int n = s.length();
Suffix[] su = new Suffix[n];
for (int i = 0; i < n; i++) {
su[i] = new Suffix(i, s.charAt(i) - '$', 0);
}
for (int i = 0; i < n; i++)
su[i].next = (i + 1 < n ? su[i + 1].rank : -1);
Arrays.sort(su);
int[] ind = new int[n];
for (int length = 4; length < 2 * n; length <<= 1) {
int rank = 0, prev = su[0].rank;
su[0].rank = rank;
ind[su[0].index] = 0;
for (int i = 1; i < n; i++) {
if (su[i].rank == prev && su[i].next == su[i - 1].next) {
prev = su[i].rank;
su[i].rank = rank;
}
else {
prev = su[i].rank;
su[i].rank = ++rank;
}
ind[su[i].index] = i;
}
for (int i = 0; i < n; i++) {
int nextP = su[i].index + length / 2;
su[i].next = nextP < n ?
su[ind[nextP]].rank : -1;
}
Arrays.sort(su);
}
int[] suf = new int[n];
for (int i = 0; i < n; i++)
suf[i] = su[i].index;
return suf;
}
public static boolean isPalindrome(String s) {
int i =0 , j = s.length() -1;
while(i <= j && s.charAt(i) == s.charAt(j)) {
i++;
j--;
}
return i>j;
}
// digit dp hint;
public static long callfun(String num , int N, int last ,int secondLast ,int bound ,long dp[][][][]) {
if(N == 1) {
if(last == -1 || secondLast == -1) return 0;
long answer = 0;
int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9;
for(int i = 0;i<=max;i++) {
if(last > secondLast && last > i) {
answer++;
}
if(last < secondLast && last < i) {
answer++;
}
}
return answer;
}
if(secondLast == -1 || last == -1 ){
long answer = 0l;
int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9;
for(int i =0;i<=max;i++) {
int nl , nsl , newbound = bound==0?0:i==max?1:0;
if(last == - 1&& secondLast == -1 && i == 0) {
nl = -1 ; nsl = -1;
}
else {
nl = i;nsl = last;
}
long temp = callfun(num , N-1 , nl , nsl ,newbound, dp);
answer += temp;
if(last != -1 && secondLast != -1 &&((last > secondLast && last > i)||(last < secondLast && last < i))) answer++;
}
return answer;
}
if(dp[N][last][secondLast][bound] != -1) return dp[N][last][secondLast][bound];
long answer = 0l;
int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9;
for(int i =0;i<=max;i++) {
int nl , nsl , newbound = bound==0?0:i==max?1:0;
if(last == - 1&& secondLast == -1 && i == 0) {
nl = -1 ; nsl = -1;
}
else {
nl = i;nsl = last;
}
long temp = callfun(num , N-1 , nl , nsl ,newbound,dp);
answer += temp;
if(last != -1 && secondLast != -1 &&((last > secondLast && last > i)||(last < secondLast && last < i))) answer++;
}
return dp[N][last][secondLast][bound] = answer;
}
public static Long callfun(int index ,int pair,int arr[],Long dp[][]) {
long mod = 998244353l;
if(index >= arr.length) return 1l;
if(dp[index][pair] != null) return dp[index][pair];
Long sum = 0l , ans = 0l;
if(arr[index]%2 == pair) {
return dp[index][pair] = callfun(index + 1,pair^1 , arr,dp)%mod + callfun(index + 1 ,pair , arr , dp)%mod;
}
else {
return dp[index][pair] = callfun(index + 1,pair , arr,dp)%mod;
}
// for(int i =index;i<arr.length;i++) {
// sum += arr[i];
// if(sum%2 == pair) {
// ans = ans + callfun(i + 1,pair^1,arr , dp)%mod;
// ans%=mod;
// }
// }
// return dp[index][pair] = ans;
}
public static boolean callfun(int index , int n,int neg , int pos , String s) {
if(neg < 0 || pos < 0) return false;
if(index >= n) return true;
if(s.charAt(0) == 'P') {
if(neg <= 0) return false;
return callfun(index + 1,n , neg-1 , pos , s.charAt(1) + "N");
}
else {
if(pos <= 0) return false;
return callfun(index + 1 , n , neg , pos-1 , s.charAt(1) + "P");
}
}
public static void getPerm(int n , char arr[] , String s ,List<String>list) {
if(n == 0) {
list.add(s);
return;
}
for(char ch : arr) {
getPerm(n-1 , arr , s+ ch,list);
}
}
public static int getLen(int i ,int j , char s[]) {
while(i >= 0 && j < s.length && s[i] == s[j]) {
i--;
j++;
}
i++;
j--;
if(i>j) return 0;
return j-i + 1;
}
public static int getMaxCount(String x) {
char s[] = x.toCharArray();
int max = 0;
int n = s.length;
for(int i =0;i<n;i++) {
max = Math.max(max,Math.max(getLen(i , i,s) , getLen(i ,i+1,s)));
}
return max;
}
public static double getDis(int arr[][] , int x, int y) {
double ans = 0.0;
for(int a[] : arr) {
int x1 = a[0] , y1 = a[1];
ans += Math.sqrt((x-x1)*(x-x1) + (y-y1)*(y-y1));
}
return ans;
}
public static boolean valid(String x ) {
if(x.length() == 0) return true;
if(x.length() == 1) return false;
char s[] = x.toCharArray();
if(x.length() == 2) {
if(s[0] == s[1]) {
return false;
}
return true;
}
int r = 0 , b = 0;
for(char ch : x.toCharArray()) {
if(ch == 'R') r++;
else b++;
}
return (r >0 && b >0);
}
public static void primeDivisor(HashMap<Long , Long >cnt , long num) {
for(long i = 2;i*i<=num;i++) {
while(num%i == 0) {
cnt.put(i ,(cnt.getOrDefault(i,0l) + 1));
num /= i;
}
}
if(num > 2) {
cnt.put(num ,(cnt.getOrDefault(num,0l) + 1));
}
}
public static boolean isSubsequene(char a[], char b[] ) {
int i =0 , j = 0;
while(i < a.length && j <b.length) {
if(a[i] == b[j]) {
j++;
}
i++;
}
return j >= b.length;
}
public static long fib(int n ,long M) {
if (n == 0) {
return 0;
} else if (n == 1) {
return 1;
} else {
long[][] mat = {{1, 1}, {1, 0}};
mat = pow(mat, n-1 , M);
return mat[0][0];
}
}
public static long[][] pow(long[][] mat, int n ,long M) {
if (n == 1) return mat;
else if (n % 2 == 0) return pow(mul(mat, mat , M), n/2 , M);
else return mul(pow(mul(mat, mat,M), n/2,M), mat , M);
}
static long[][] mul(long[][] p, long[][] q,long M) {
long a = (p[0][0]*q[0][0] + p[0][1]*q[1][0])%M;
long b = (p[0][0]*q[0][1] + p[0][1]*q[1][1])%M;
long c = (p[1][0]*q[0][0] + p[1][1]*q[1][0])%M;
long d = (p[1][0]*q[0][1] + p[1][1]*q[1][1])%M;
return new long[][] {{a, b}, {c, d}};
}
public static long[] kdane(long arr[]) {
int n = arr.length;
long dp[] = new long[n];
dp[0] = arr[0];
long ans = dp[0];
for(int i = 1;i<n;i++) {
dp[i] = Math.max(dp[i-1] + arr[i] , arr[i]);
ans = Math.max(ans , dp[i]);
}
return dp;
}
public static void update(int low , int high , int l , int r, int val , int treeIndex ,int tree[]) {
if(low > r || high < l || high < low) return;
if(l <= low && high <= r) {
System.out.println("At " +low + " and " + high + " ans ttreeIndex " + treeIndex);
tree[treeIndex] += val;
return;
}
int mid = low + (high - low)/2;
update(low , mid , l , r , val , treeIndex*2 + 1, tree);
update(mid + 1 , high , l , r , val , treeIndex*2 + 2 , tree);
}
// static int colx[] = {1 ,1, -1,-1 , 2,2,-2,-2};
// static int coly[] = {-2 ,2, 2,-2,1,-1,1,-1};
static int colx[] = {1 ,-1, 0,0 , 1,1,-1,-1};
static int coly[] = {0 ,0, 1,-1,1,-1,1,-1};
public static void reverse(char arr[]) {
int i =0 , j = arr.length-1;
while(i < j) {
swap(i , j , arr);
i++;
j--;
}
}
public static void reverse(long arr[]) {
int i =0 , j = arr.length-1;
while(i < j) {
swap(i , j , arr);
i++;
j--;
}
}
public static void reverse(int arr[]) {
int i =0 , j = arr.length-1;
while(i < j) {
swap(i , j , arr);
i++;
j--;
}
}
public static long inverse(long x , long mod) {
return pow(x , mod -2 , mod);
}
public static int maxArray(int arr[]) {
int ans = arr[0] , n = arr.length;
for(int i =1;i<n;i++) {
ans = Math.max(ans , arr[i]);
}
return ans;
}
public static long maxArray(long arr[]) {
long ans = arr[0];
int n = arr.length;
for(int i =1;i<n;i++) {
ans = Math.max(ans , arr[i]);
}
return ans;
}
public static int minArray(int arr[]) {
int ans = arr[0] , n = arr.length;
for(int i =0;i<n;i++ ) {
ans = Math.min(ans ,arr[i]);
}
return ans;
}
public static long minArray(long arr[]) {
long ans = arr[0];
int n = arr.length;
for(int i =0;i<n;i++ ) {
ans = Math.min(ans ,arr[i]);
}
return ans;
}
public static int sumArray(int arr[]) {
int ans = 0;
for(int x : arr) {
ans += x;
}
return ans;
}
public static long sumArray(long arr[]) {
long ans = 0;
for(long x : arr) {
ans += x;
}
return ans;
}
public static long rl() {
return sc.nextLong();
}
public static char[] rac() {
return sc.next().toCharArray();
}
public static String rs() {
return sc.next();
}
public static char rc() {
return sc.next().charAt(0);
}
public static int [] rai(int n) {
int ans[] = new int[n];
for(int i =0;i<n;i++) {
ans[i] = sc.nextInt();
}
return ans;
}
public static long [] ral(int n) {
long ans[] = new long[n];
for(int i =0;i<n;i++) {
ans[i] = sc.nextLong();
}
return ans;
}
public static int ri() {
return sc.nextInt();
}
public static int getValue(int num ) {
int ans = 0;
while(num > 0) {
ans++;
num = num&(num-1);
}
return ans;
}
public static boolean isValid(int x ,int y , int n,char arr[][],boolean visited[][][][]) {
return x>=0 && x<n && y>=0 && y <n && !(arr[x][y] == '#');
}
// public static Pair join(Pair a , Pair b) {
// Pair res = new Pair(Math.min(a.min , b.min) , Math.max(a.max , b.max) , a.count + b.count);
// return res;
// }
// segment tree query over range
// public static int query(int node,int l , int r,int a,int b ,Pair tree[] ) {
// if(tree[node].max < a || tree[node].min > b) return 0;
// if(l > r) return 0;
// if(tree[node].min >= a && tree[node].max <= b) {
// return tree[node].count;
// }
// int mid = l + (r-l)/2;
// int ans = query(node*2 ,l , mid ,a , b , tree) + query(node*2 +1,mid + 1, r , a , b, tree);
// return ans;
// }
// // segment tree update over range
// public static void update(int node, int i , int j ,int l , int r,long value, long arr[] ) {
// if(l >= i && j >= r) {
// arr[node] += value;
// return;
// }
// if(j < l|| r < i) return;
// int mid = l + (r-l)/2;
// update(node*2 ,i ,j ,l,mid,value, arr);
// update(node*2 +1,i ,j ,mid + 1,r, value , arr);
// }c
public static long pow(long a , long b , long mod) {
if(b == 1) return a;
if(b == 0) return 1;
long ans = pow(a , b/2 , mod)%mod;
if(b%2 == 0) {
return (ans*ans)%mod;
}
else {
return ((ans*ans)%mod*a)%mod;
}
}
public static long pow(long a , long b ) {
if(b == 1) return a;
if(b == 0) return 1;
long ans = pow(a , b/2);
if(b%2 == 0) {
return (ans*ans);
}
else {
return ((ans*ans)*a);
}
}
public static boolean isVowel(char ch) {
if(ch == 'a' || ch == 'e'||ch == 'i' || ch == 'o' || ch == 'u') return true;
if((ch == 'A' || ch == 'E'||ch == 'I' || ch == 'O' || ch == 'U')) return true;
return false;
}
// public static int getFactor(int num) {
// if(num==1) return 1;
// int ans = 2;
// int k = num/2;
// for(int i = 2;i<=k;i++) {
// if(num%i==0) ans++;
// }
// return Math.abs(ans);
// }
public static int[] readarr()throws IOException {
int n = sc.nextInt();
int arr[] = new int[n];
for(int i =0;i<n;i++) {
arr[i] = sc.nextInt();
}
return arr;
}
public static boolean isPowerOfTwo (long x) {
return x!=0 && ((x&(x-1)) == 0);
}
public static boolean isPrime(long num) {
if(num==1) return false;
if(num<=3) return true;
if(num%2==0||num%3==0) return false;
for(long i =5;i*i<=num;i+=6) {
if(num%i==0 || num%(i+2) == 0) return false;
}
return true;
}
public static boolean isPrime(int num) {
// System.out.println("At pr " + num);
if(num==1) return false;
if(num<=3) return true;
if(num%2==0||num%3==0) return false;
for(int i =5;i*i<=num;i+=6) {
if(num%i==0 || num%(i+2) == 0) return false;
}
return true;
}
// public static boolean isPrime(long num) {
// if(num==1) return false;
// if(num<=3) return true;
// if(num%2==0||num%3==0) return false;
// for(int i =5;i*i<=num;i+=6) {
// if(num%i==0) return false;
// }
// return true;
// }
public static void allMultiple() {
// int MAX = 0 , n = nums.length;
// for(int x : nums) MAX = Math.max(MAX ,x);
// int cnt[] = new int[MAX + 1];
// int ans[] = new int[MAX + 1];
// for (int i = 0; i < n; ++i) cnt[nums[i]]++;
// for (int i = 1; i <= MAX; ++i) {
// for (int j = i; j <= MAX; j += i) ans[i] += cnt[j];
// }
}
public static long gcd(long a , long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static int gcd(int a , int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static int get_gcd(int a , int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static long get_gcd(long a , long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
// public static long fac(long num) {
// long ans = 1;
// int mod = (int)1e9+7;
// for(long i = 2;i<=num;i++) {
// ans = (ans*i)%mod;
// }
// return ans;
// }
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 327f362971339d5d89359e81022f0c21 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | // JAI SHREE RAM, HAR HAR MAHADEV, HARE KRISHNA
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.*;
import java.lang.*;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.io.*;
public class CodeForces {
static private final String INPUT = "input.txt";
static private final String OUTPUT = "output.txt";
static BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer ST;
static PrintWriter out = new PrintWriter(System.out);
static DecimalFormat df = new DecimalFormat("0.00");
final static int MAX = Integer.MAX_VALUE, MIN = Integer.MIN_VALUE, mod = (int) (1e9 + 7);
final static long LMAX = Long.MAX_VALUE, LMIN = Long.MIN_VALUE;
final static long INF = (long) 1e18, Neg_INF = (long) -1e18;
static Random rand = new Random();
// ======================= MAIN ==================================
public static void main(String[] args) throws IOException {
long time = System.currentTimeMillis();
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
// ==== start ====
input();
preprocess();
int t = 1;
t = readInt();
while (t-- > 0) {
solve();
}
out.flush();
// ==== end ====
if (!oj)
System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
}
private static void solve() throws IOException {
int n = readInt(), m = readInt();
if (n == 1 || m == 1 || (n == 2 && m == 2))
out.println("1 1");
else
out.println("2 2");
}
private static void preprocess() throws IOException {
}
// cd C:\Users\Eshan Bhatt\Visual Studio Code\Competitive Programming\CodeForces
// javac CodeForces.java && java CodeForces
// change Stack size -> java -Xss16M CodeForces.java
// ==================== CUSTOM CLASSES ================================
static class Pair implements Comparable<Pair> {
int first, second;
Pair(int f, int s) {
first = f;
second = s;
}
public int compareTo(Pair o) {
if (this.first == o.first)
return this.second - o.second;
return this.first - o.first;
}
@Override
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj == null)
return false;
if (this.getClass() != obj.getClass())
return false;
Pair other = (Pair) (obj);
if (this.first != other.first)
return false;
if (this.second != other.second)
return false;
return true;
}
@Override
public int hashCode() {
return this.first ^ this.second;
}
@Override
public String toString() {
return this.first + " " + this.second;
}
}
static class DequeNode {
DequeNode prev, next;
int val;
DequeNode(int val) {
this.val = val;
}
DequeNode(int val, DequeNode prev, DequeNode next) {
this.val = val;
this.prev = prev;
this.next = next;
}
}
// ======================= FOR INPUT ==================================
private static void input() {
FileInputStream instream = null;
PrintStream outstream = null;
try {
instream = new FileInputStream(INPUT);
outstream = new PrintStream(new FileOutputStream(OUTPUT));
System.setIn(instream);
System.setOut(outstream);
} catch (Exception e) {
System.err.println("Error Occurred.");
}
BR = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
static String next() throws IOException {
while (ST == null || !ST.hasMoreTokens())
ST = new StringTokenizer(readLine());
return ST.nextToken();
}
static long readLong() throws IOException {
return Long.parseLong(next());
}
static int readInt() throws IOException {
return Integer.parseInt(next());
}
static double readDouble() throws IOException {
return Double.parseDouble(next());
}
static char readCharacter() throws IOException {
return next().charAt(0);
}
static String readString() throws IOException {
return next();
}
static String readLine() throws IOException {
return BR.readLine().trim();
}
static int[] readIntArray(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = readInt();
return arr;
}
static int[][] read2DIntArray(int n, int m) throws IOException {
int[][] arr = new int[n][m];
for (int i = 0; i < n; i++)
arr[i] = readIntArray(m);
return arr;
}
static List<Integer> readIntList(int n) throws IOException {
List<Integer> list = new ArrayList<>(n);
for (int i = 0; i < n; i++)
list.add(readInt());
return list;
}
static long[] readLongArray(int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++)
arr[i] = readLong();
return arr;
}
static long[][] read2DLongArray(int n, int m) throws IOException {
long[][] arr = new long[n][m];
for (int i = 0; i < n; i++)
arr[i] = readLongArray(m);
return arr;
}
static List<Long> readLongList(int n) throws IOException {
List<Long> list = new ArrayList<>(n);
for (int i = 0; i < n; i++)
list.add(readLong());
return list;
}
static char[] readCharArray() throws IOException {
return readString().toCharArray();
}
static char[][] readMatrix(int n, int m) throws IOException {
char[][] mat = new char[n][m];
for (int i = 0; i < n; i++)
mat[i] = readCharArray();
return mat;
}
// ========================= FOR OUTPUT ==================================
private static void printIList(List<Integer> list) {
for (int i = 0; i < list.size(); i++)
out.print(list.get(i) + " ");
out.println(" ");
}
private static void printLList(List<Long> list) {
for (int i = 0; i < list.size(); i++)
out.print(list.get(i) + " ");
out.println(" ");
}
private static void printIArray(int[] arr) {
for (int i = 0; i < arr.length; i++)
out.print(arr[i] + " ");
out.println(" ");
}
private static void print2DIArray(int[][] arr) {
for (int i = 0; i < arr.length; i++)
printIArray(arr[i]);
}
private static void printLArray(long[] arr) {
for (int i = 0; i < arr.length; i++)
out.print(arr[i] + " ");
out.println(" ");
}
private static void print2DLArray(long[][] arr) {
for (int i = 0; i < arr.length; i++)
printLArray(arr[i]);
}
private static void yes() {
out.println("YES");
}
private static void no() {
out.println("NO");
}
// ====================== TO CHECK IF STRING IS NUMBER ========================
private static boolean isInteger(String s) {
try {
Integer.parseInt(s);
} catch (NumberFormatException e) {
return false;
} catch (NullPointerException e) {
return false;
}
return true;
}
private static boolean isLong(String s) {
try {
Long.parseLong(s);
} catch (NumberFormatException e) {
return false;
} catch (NullPointerException e) {
return false;
}
return true;
}
// ==================== FASTER SORT ================================
private static void sort(int[] arr) {
int n = arr.length;
List<Integer> list = new ArrayList<>(n);
for (int i = 0; i < n; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = 0; i < n; i++)
arr[i] = list.get(i);
}
private static void reverseSort(int[] arr) {
int n = arr.length;
List<Integer> list = new ArrayList<>(n);
for (int i = 0; i < n; i++)
list.add(arr[i]);
Collections.sort(list, Collections.reverseOrder());
for (int i = 0; i < n; i++)
arr[i] = list.get(i);
}
private static void sort(long[] arr) {
int n = arr.length;
List<Long> list = new ArrayList<>(n);
for (int i = 0; i < n; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = 0; i < n; i++)
arr[i] = list.get(i);
}
private static void reverseSort(long[] arr) {
int n = arr.length;
List<Long> list = new ArrayList<>(n);
for (int i = 0; i < n; i++)
list.add(arr[i]);
Collections.sort(list, Collections.reverseOrder());
for (int i = 0; i < n; i++)
arr[i] = list.get(i);
}
// ==================== MATHEMATICAL FUNCTIONS ===========================
private static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private static int lcm(int a, int b) {
return (a / gcd(a, b)) * b;
}
private static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
private static int mod_pow(long a, long b, int mod) {
if (b == 0)
return 1;
int temp = mod_pow(a, b >> 1, mod);
temp %= mod;
temp = (int) ((1L * temp * temp) % mod);
if ((b & 1) == 1)
temp = (int) ((1L * temp * a) % mod);
return temp;
}
private static long multiply(long a, long b) {
return (((a % mod) * (b % mod)) % mod);
}
private static long divide(long a, long b) {
return multiply(a, mod_pow(b, mod - 2, mod));
}
private static boolean isPrime(long n) {
for (long i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
private static long nCr(long n, long r) {
if (n - r > r)
r = n - r;
long ans = 1L;
for (long i = r + 1; i <= n; i++)
ans *= i;
for (long i = 2; i <= n - r; i++)
ans /= i;
return ans;
}
private static List<Integer> factors(int n) {
List<Integer> list = new ArrayList<>();
for (int i = 1; 1L * i * i <= n; i++)
if (n % i == 0) {
list.add(i);
if (i != n / i)
list.add(n / i);
}
return list;
}
private static List<Long> factors(long n) {
List<Long> list = new ArrayList<>();
for (long i = 1; i * i <= n; i++)
if (n % i == 0) {
list.add(i);
if (i != n / i)
list.add(n / i);
}
return list;
}
// ==================== Primes using Seive =====================
private static List<Integer> getPrimes(int n) {
boolean[] prime = new boolean[n + 1];
Arrays.fill(prime, true);
for (int i = 2; 1L * i * i <= n; i++)
if (prime[i])
for (int j = i * i; j <= n; j += i)
prime[j] = false;
// return prime;
List<Integer> list = new ArrayList<>();
for (int i = 2; i <= n; i++)
if (prime[i])
list.add(i);
return list;
}
private static int[] SeivePrime(int n) {
int[] primes = new int[n];
for (int i = 0; i < n; i++)
primes[i] = i;
for (int i = 2; 1L * i * i < n; i++) {
if (primes[i] != i)
continue;
for (int j = i * i; j < n; j += i)
if (primes[j] == j)
primes[j] = i;
}
return primes;
}
// ==================== STRING FUNCTIONS ================================
private static boolean isPalindrome(String str) {
int i = 0, j = str.length() - 1;
while (i < j)
if (str.charAt(i++) != str.charAt(j--))
return false;
return true;
}
// check if a is subsequence of b
private static boolean isSubsequence(String a, String b) {
int idx = 0;
for (int i = 0; i < b.length() && idx < a.length(); i++)
if (a.charAt(idx) == b.charAt(i))
idx++;
return idx == a.length();
}
private static String reverseString(String str) {
StringBuilder sb = new StringBuilder(str);
return sb.reverse().toString();
}
private static String sortString(String str) {
int[] arr = new int[256];
for (char ch : str.toCharArray())
arr[ch]++;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 256; i++)
while (arr[i]-- > 0)
sb.append((char) i);
return sb.toString();
}
// ==================== LIS & LNDS ================================
private static int LIS(int arr[], int n) {
List<Integer> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
int idx = find1(list, arr[i]);
if (idx < list.size())
list.set(idx, arr[i]);
else
list.add(arr[i]);
}
return list.size();
}
private static int find1(List<Integer> list, int val) {
int ret = list.size(), i = 0, j = list.size() - 1;
while (i <= j) {
int mid = (i + j) / 2;
if (list.get(mid) >= val) {
ret = mid;
j = mid - 1;
} else {
i = mid + 1;
}
}
return ret;
}
private static int LNDS(int[] arr, int n) {
List<Integer> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
int idx = find2(list, arr[i]);
if (idx < list.size())
list.set(idx, arr[i]);
else
list.add(arr[i]);
}
return list.size();
}
private static int find2(List<Integer> list, int val) {
int ret = list.size(), i = 0, j = list.size() - 1;
while (i <= j) {
int mid = (i + j) / 2;
if (list.get(mid) <= val) {
i = mid + 1;
} else {
ret = mid;
j = mid - 1;
}
}
return ret;
}
// =============== Lower Bound & Upper Bound ===========
// less than or equal
private static int lower_bound(List<Integer> list, int val) {
int ans = -1, lo = 0, hi = list.size() - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (list.get(mid) <= val) {
ans = mid;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
return ans;
}
private static int lower_bound(List<Long> list, long val) {
int ans = -1, lo = 0, hi = list.size() - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (list.get(mid) <= val) {
ans = mid;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
return ans;
}
private static int lower_bound(int[] arr, int val) {
int ans = -1, lo = 0, hi = arr.length - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (arr[mid] <= val) {
ans = mid;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
return ans;
}
private static int lower_bound(long[] arr, long val) {
int ans = -1, lo = 0, hi = arr.length - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (arr[mid] <= val) {
ans = mid;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
return ans;
}
// greater than or equal
private static int upper_bound(List<Integer> list, int val) {
int ans = list.size(), lo = 0, hi = ans - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (list.get(mid) >= val) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
return ans;
}
private static int upper_bound(List<Long> list, long val) {
int ans = list.size(), lo = 0, hi = ans - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (list.get(mid) >= val) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
return ans;
}
private static int upper_bound(int[] arr, int val) {
int ans = arr.length, lo = 0, hi = ans - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (arr[mid] >= val) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
return ans;
}
private static int upper_bound(long[] arr, long val) {
int ans = arr.length, lo = 0, hi = ans - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (arr[mid] >= val) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
return ans;
}
// ==================== UNION FIND =====================
private static int find(int x, int[] parent) {
if (parent[x] == x)
return x;
return parent[x] = find(parent[x], parent);
}
private static boolean union(int x, int y, int[] parent, int[] rank) {
int lx = find(x, parent), ly = find(y, parent);
if (lx == ly)
return false;
if (rank[lx] > rank[ly])
parent[ly] = lx;
else if (rank[lx] < rank[ly])
parent[lx] = ly;
else {
parent[lx] = ly;
rank[ly]++;
}
return true;
}
// ==================== TRIE ================================
static class Trie {
class Node {
Node[] children;
boolean isEnd;
Node() {
children = new Node[26];
}
}
Node root;
Trie() {
root = new Node();
}
boolean insert(String word) {
Node curr = root;
boolean ans = true;
for (char ch : word.toCharArray()) {
if (curr.children[ch - 'a'] == null)
curr.children[ch - 'a'] = new Node();
curr = curr.children[ch - 'a'];
if (curr.isEnd)
ans = false;
}
curr.isEnd = true;
return ans;
}
boolean find(String word) {
Node curr = root;
for (char ch : word.toCharArray()) {
if (curr.children[ch - 'a'] == null)
return false;
curr = curr.children[ch - 'a'];
}
return curr.isEnd;
}
}
// ================== SEGMENT TREE (RANGE SUM & RANGE UPDATE) ==================
public static class SegmentTree {
int n;
long[] arr, tree, lazy;
SegmentTree(long arr[]) {
this.arr = arr;
this.n = arr.length;
this.tree = new long[(n << 2)];
this.lazy = new long[(n << 2)];
build(1, 0, n - 1);
}
void build(int id, int start, int end) {
if (start == end)
tree[id] = arr[start];
else {
int mid = (start + end) / 2, left = (id << 1), right = left + 1;
build(left, start, mid);
build(right, mid + 1, end);
tree[id] = tree[left] + tree[right];
}
}
void update(int l, int r, long val) {
update(1, 0, n - 1, l, r, val);
}
void update(int id, int start, int end, int l, int r, long val) {
distribute(id, start, end);
if (end < l || r < start)
return;
if (start == end)
tree[id] += val;
else if (l <= start && end <= r) {
lazy[id] += val;
distribute(id, start, end);
} else {
int mid = (start + end) / 2, left = (id << 1), right = left + 1;
update(left, start, mid, l, r, val);
update(right, mid + 1, end, l, r, val);
tree[id] = tree[left] + tree[right];
}
}
long query(int l, int r) {
return query(1, 0, n - 1, l, r);
}
long query(int id, int start, int end, int l, int r) {
if (end < l || r < start)
return 0L;
distribute(id, start, end);
if (start == end)
return tree[id];
else if (l <= start && end <= r)
return tree[id];
else {
int mid = (start + end) / 2, left = (id << 1), right = left + 1;
return query(left, start, mid, l, r) + query(right, mid + 1, end, l, r);
}
}
void distribute(int id, int start, int end) {
if (start == end)
tree[id] += lazy[id];
else {
tree[id] += lazy[id] * (end - start + 1);
lazy[(id << 1)] += lazy[id];
lazy[(id << 1) + 1] += lazy[id];
}
lazy[id] = 0;
}
}
// ==================== FENWICK TREE ================================
static class FT {
int n;
int[] arr;
int[] tree;
FT(int[] arr, int n) {
this.arr = arr;
this.n = n;
this.tree = new int[n + 1];
for (int i = 1; i <= n; i++) {
update(i, arr[i - 1]);
}
}
FT(int n) {
this.n = n;
this.tree = new int[n + 1];
}
// 1 based indexing
void update(int idx, int val) {
while (idx <= n) {
tree[idx] += val;
idx += idx & -idx;
}
}
// 1 based indexing
int query(int l, int r) {
return getSum(r) - getSum(l - 1);
}
int getSum(int idx) {
int ans = 0;
while (idx > 0) {
ans += tree[idx];
idx -= idx & -idx;
}
return ans;
}
}
// ==================== BINARY INDEX TREE ================================
static class BIT {
long[][] tree;
int n, m;
BIT(int[][] mat, int n, int m) {
this.n = n;
this.m = m;
tree = new long[n + 1][m + 1];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
update(i, j, mat[i - 1][j - 1]);
}
}
}
void update(int x, int y, int val) {
while (x <= n) {
int t = y;
while (t <= m) {
tree[x][t] += val;
t += t & -t;
}
x += x & -x;
}
}
long query(int x1, int y1, int x2, int y2) {
return getSum(x2, y2) - getSum(x1 - 1, y2) - getSum(x2, y1 - 1) + getSum(x1 - 1, y1 - 1);
}
long getSum(int x, int y) {
long ans = 0L;
while (x > 0) {
int t = y;
while (t > 0) {
ans += tree[x][t];
t -= t & -t;
}
x -= x & -x;
}
return ans;
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 618e5b9a082faf6d5a575bb378f089e1 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes |
import java.util.*;
public class Knight {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int a=sc.nextInt(),b=sc.nextInt();
if((a==3 && b==3)||(a==3 && b==2 )||(a==2 && b==3))
System.out.println(2+" "+2);
else System.out.println(a+" "+b);
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 3bb1d91efb1ca82a3b0e3ddd9858c50a | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes |
import java.util.*;
public class Knight {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int a=sc.nextInt(),b=sc.nextInt();
if(a==1||b==1||a==2 && b==2)
System.out.println(a+" "+b);
else if(a==3 && b==3)
System.out.println(2+" "+2);
else if((a==3 && b==2 )||(a==2 && b==3))
System.out.println(2+" "+2);
else System.out.println(1+" "+1);
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 225090c254cf9d256c9dadc39e3770a1 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Solution {
public static HashMap<Integer, Integer> valuesort(HashMap<Integer, Integer> hm)
{
List<Map.Entry<Integer, Integer> > list =
new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet());
Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() {
public int compare(Map.Entry<Integer, Integer> o1,
Map.Entry<Integer, Integer> o2)
{
return (o1.getValue()).compareTo(o2.getValue());
}
});
HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> aa : list) {
temp.put(aa.getKey(), aa.getValue());
}
return temp;
}
public static int findLastOccurrence(int[] nums, int target)
{
int left = 0;
int right = nums.length - 1;
int result = -1;
while (left <= right)
{
int mid = (left + right) / 2;
if (target == nums[mid])
{
result = mid;
left = mid + 1;
}
else if (target < nums[mid]) {
right = mid - 1;
}
else {
left = mid + 1;
}
}
return result;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
int m = sc.nextInt();
if(n==3 && m==3) {
sb.append("2 2\n");
}
else if(n==3) {
sb.append("2 1\n");
}
else if(m==3) {
sb.append("1 2\n");
}
else {
sb.append("1 1\n");
}
}
System.out.print(sb.toString());
sc.close();
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | f668c6207fefac733ad2adcba2451c51 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import javax.print.event.PrintEvent;
public class A {
static int row[] = { -2, -1, 1, 2, -2, -1, 1, 2 };
static int col[] = { -1, -2, 2, 1, 1, 2, -2, -1 };
static void solve(int m, int n) {
int board[][] = new int[m][n];
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
// System.out.println(i + " " + j + " :");
for (int d = 0; d < 8; d++) {
if (isValid(i + row[d], j + col[d], m, n)) {
board[i - 1][j - 1] |= 1;
} else {
board[i - 1][j - 1] |= 0;
}
}
if (board[i - 1][j - 1] == 0) {
System.out.println(i + " " + j);
return;
}
}
}
System.out.println("1 1");
// print(board, m, n);
}
static void print(int arr[][], int m, int n) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
static boolean isValid(int x, int y, int m, int n) {
// System.out.println(x + " " + y);
return x <= m && y <= n && x > 0 && y > 0;
}
public static void main(String[] args) throws Exception {
FastScanner fs = new FastScanner();
int t = fs.nextInt();
for (int tt = 0; tt < t; tt++) {
int m = fs.nextInt();
int n = fs.nextInt();
solve(m, n);
}
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 902e2813e58ec739e79bffb740ed048a | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t= sc.nextInt();
while(t-->0){
boolean flag = false;
int n=sc.nextInt();
int m=sc.nextInt();
for(int i=1;i<=n;i++){
for(int j=1;j<m;j++){
if(!Validate(i,j,n,m)){ System.out.println(i+" "+j);flag = true; break;}
}
if(flag) {break;}
}
if(flag) continue;
System.out.println(n+" "+m);
}
}
private static boolean Validate(int i, int j,int n,int m) {
int yl = i-2;
int xl = j-1;
if(((yl>=1&&yl<=n)&&(xl>=1&&xl<=m))) return true;
yl = i - 1;
xl = j - 2;
if(((yl>=1&&yl<=n)&&(xl>=1&&xl<=m))) return true;
yl = i + 1;
xl = j + 2;
if(((yl>=1&&yl<=n)&&(xl>=1&&xl<=m))) return true;
yl = i + 2;
xl = j + 1;
if(((yl>=1&&yl<=n)&&(xl>=1&&xl<=m))) return true;
yl = i + 2;
xl = j - 1;
if(((yl>=1&&yl<=n)&&(xl>=1&&xl<=m))) return true;
yl = i - 2;
xl = j + 1;
if(((yl>=1&&yl<=n)&&(xl>=1&&xl<=m))) return true;
yl = i + 1;
xl = j - 2;
if(((yl>=1&&yl<=n)&&(xl>=1&&xl<=m))) return true;
yl = i - 1;
xl = j + 2;
if(((yl>=1&&yl<=n)&&(xl>=1&&xl<=m))) return true;
return false;
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 4ffc178369c5c207414b7111cbd2c07b | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class codeforces {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++) {
int n=sc.nextInt();
int m=sc.nextInt();
if(1<=n && m<=8) {
System.out.println(((n/2)+1)+" "+((m/2)+1));
}
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 78f83c88200b3f552f788f982cfaec78 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner t = new Scanner(System.in);
int w = t.nextInt();
while(w-->0)
{
int n = t.nextInt();
int m = t.nextInt();
StringBuilder ans = new StringBuilder();
if(n==1 || m==1)
{
ans.append(n).append(" ").append(m);
}
else if(n<=3 && m<=3)
{
ans.append(2).append(" ").append(2);
}
else{
ans.append(n-1).append(" ").append(m-1);
}
System.out.println(ans);
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 5f7abc5678098f52e06fe775952213b9 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
import java.util.Scanner;
import java.io.*;
import java.math.BigInteger;
import java.util.stream.*;
import java.util.ArrayList;
import java.lang.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import java.util.Iterator;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.lang.Math;
public class Main {
static long mod = (long)(1e9) + 7;
static int max_num = (int)1e5 + 5;
public static void main(String[] args) {
FastReader in = new FastReader();
FastWriter out = new FastWriter();
Scanner scn = new Scanner(System.in);
int tt = in.nextInt();
// int tt = 1;
while (tt-- > 0) {
int n = in.nextInt();
int m = in.nextInt();
// int[] arr = new int[n];
// int[] parr = new int[n];
// for (int i = 0 ; i < n ; i++) {
// arr[i] = in.nextInt();
// }
// parr[0] = arr[0];
// for (int i = 0 ; i < arr.length - 1 ; i++) {
// parr[i + 1] = arr[i + 1] + parr[i];
// }
// int check = 0;
// int[] farr = new int[n];
// int cc = arr[0];
// farr[0] = cc;
// for (int i = 1; i < n; i++) {
// int a = farr[i - 1] - arr[i];
// int b = farr[i - 1] + arr[i];
// if (a > 0 && b > 0 ) {
// if (a != b) {
// check = 1;
// break;
// }
// }
// else {
// farr[i] = Math.max(a, b);
// }
// }
// if (check == 1) print(-1);
// else printArray(parr);
if(n == 1 || m == 1){
System.out.println( n + " " + m);
}
else if(n <= 3 && m <= 3){
System.out.println("2 " + "2");
}
else{
System.out.print(n-1 + " ");
print(m-1);
}
}
}
public static void print(int k) {
System.out.println(k);
}
public static void print(long k) {
System.out.println(k);
}
public static int largestDivisor(int n) {
for (int i = n / 2; i >= 2; i--) {
if (n % i == 0) {
return i;
}
}
return 1;
}
public static String sortString(String inputString) {
char tempArray[] = inputString.toCharArray();
Arrays.sort(tempArray);
return new String(tempArray);
}
public static long maxSumofsubarr(long arr[], int n, int k) {
if (n < k) {
System.out.println("Invalid");
return -1;
}
long res = 0;
for (int i = 0; i < k; i++)
res += arr[i];
long curr_sum = res;
for (int i = k; i < n; i++)
{
curr_sum += arr[i] - arr[i - k];
res = Math.max(res, curr_sum);
}
return res;
}
// agar 2d array ke ek coloumn ko sort karna h to -> Arrays.sort(arr, (a, b) -> a[0] - b[0]);
// chote a ka ascii code 97
// 0 ka ascii code 48
// bade A ka ascii code 65
// int ko char array m karne h to-> char[] arr = (n+"").toCharArray();
// String ko integer banane ke lia -> Integer.parseInt("10");
// dp[2][n] tej chalta h dp[n][2] se
public static int countDigit(long n)
{
return (int)Math.floor(Math.log10(n) + 1);
}
public static boolean checkPalin(String str) {
int i = 0;
int j = str.length() - 1;
while (i < j) {
if (str.charAt(i) != str.charAt(j)) {
return false;
}
i++;
j--;
}
return true;
}
public static int maxInArray(int[] arr) {
int max = arr[0];
for (int i = 0 ; i < arr.length ; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}
static long square(long n) {
if (n == 0)
return 0;
if (n < 0)
n = -n;
long x = n >> 1;
if (n % 2 != 0)
return ((square(x) << 2) + (x << 2) + 1);
else
return (square(x) << 2);
}
static int square(int n) {
if (n == 0)
return 0;
if (n < 0)
n = -n;
int x = n >> 1;
if (n % 2 != 0)
return ((square(x) << 2) + (x << 2) + 1);
else
return (square(x) << 2);
}
public static void printString(String str) {
System.out.println(str);
}
public static void printCharArray(char[] arr) {
for (int i = 0 ; i < arr.length ; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
}
public static <K, V> K getKey(Map<K, V> map, V value) {
for (Map.Entry<K, V> entry : map.entrySet()) {
if (value.equals(entry.getValue())) {
return entry.getKey();
}
}
return null;
}
public static void printArray(int[] arr) {
for (int i = 0 ; i < arr.length ; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
}
public static void print2dArray(int[][] arr) {
for (int i = 0 ; i < arr.length ; i++) {
for (int j = 0 ; j < arr[0].length ; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
public 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 highestPowerof2(int n) {
int res = 0;
for (int i = n; i >= 1; i--) {
if ((i & (i - 1)) == 0) {
res = i;
break;
}
}
return res;
}
public static int countElementInArray(int[] arr, int k) {
int cc = 0;
for (int i = 0 ; i < arr.length ; i++ ) {
if (arr[i] == k) {
cc++;
}
}
return cc;
}
public static long integerFromBinary(String str) {
long j = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '1') {
j = j + (long)Math.pow(2, str.length() - 1 - i);
}
}
return (long) j;
}
static int minInArray(int[] arr) {
int min = arr[0];
for (int i = 0 ; i < arr.length ; i++) {
if (arr[i] < min) {
min = arr[i];
}
}
return min;
}
static void printN() {
System.out.println("No");
}
static void printY() {
System.out.println("Yes");
}
public static int[] radixSort2(int[] a) {
int n = a.length;
int[] c0 = new int[0x101];
int[] c1 = new int[0x101];
int[] c2 = new int[0x101];
int[] c3 = new int[0x101];
for (int v : a) {
c0[(v & 0xff) + 1]++;
c1[(v >>> 8 & 0xff) + 1]++;
c2[(v >>> 16 & 0xff) + 1]++;
c3[(v >>> 24 ^ 0x80) + 1]++;
}
for (int i = 0; i < 0xff; i++) {
c0[i + 1] += c0[i];
c1[i + 1] += c1[i];
c2[i + 1] += c2[i];
c3[i + 1] += c3[i];
}
int[] t = new int[n];
for (int v : a)t[c0[v & 0xff]++] = v;
for (int v : t)a[c1[v >>> 8 & 0xff]++] = v;
for (int v : a)t[c2[v >>> 16 & 0xff]++] = v;
for (int v : t)a[c3[v >>> 24 ^ 0x80]++] = v;
return a;
}
static int[] EvenOddArragement(int nums[]) {
int i1 = 0, i2 = nums.length - 1;
while (i1 < i2) {
while (nums[i1] % 2 == 0 && i1 < i2) {
i1++;
}
while (nums[i2] % 2 != 0 && i2 > i1) {
i2--;
}
int temp = nums[i1];
nums[i1] = nums[i2];
nums[i2] = temp;
}
return nums;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object) throws IOException {
bw.append("" + object);
}
public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}
public void close() throws IOException {
bw.close();
}
}
static int gcd(int a, int b) {
while (b != 0) {
int t = a;
a = b;
b = t % b;
}
return a;
}
static int lcm(int a, int b) {
return (a / gcd(a, b)) * b;
}
static int DigitSum(int n) {
int r = 0, sum = 0;
while (n >= 0) {
r = n % 10;
sum = sum + r;
n = n / 10;
}
return sum;
}
static boolean checkPerfectSquare(int number) {
double sqrt = Math.sqrt(number);
return ((sqrt - Math.floor(sqrt)) == 0);
}
static boolean isPowerOfTwo(int n)
{
if (n == 0)
return false;
return (int)(Math.ceil((Math.log(n) / Math.log(2)))) == (int)(Math.floor(((Math.log(n) / Math.log(2)))));
}
static boolean isPrime2(int n) {
if (n <= 1)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (int i = 3; i <= Math.sqrt(n) + 1; i = i + 2) {
if (n % i == 0)
return false;
}
return true;
}
static String minLexRotation(String str) {
int n = str.length();
String arr[] = new String[n];
String concat = str + str;
for (int i = 0; i < n; i++) {
arr[i] = concat.substring(i, i + n);
}
Arrays.sort(arr);
return arr[0];
}
static String maxLexRotation(String str) {
int n = str.length();
String arr[] = new String[n];
String concat = str + str;
for (int i = 0; i < n; i++) {
arr[i] = concat.substring(i, i + n);
}
Arrays.sort(arr);
return arr[arr.length - 1];
}
static class P implements Comparable<P> {
int i, j;
public P(int i, int j) {
this.i = i;
this.j = j;
}
public int compareTo(P o) {
return Integer.compare(i, o.i);
}
}
static class pair {
int i, j;
pair(int x, int y) {
i = x;
j = y;
}
}
static int binary_search(int a[], int value) {
int start = 0;
int end = a.length - 1;
int mid = start + (end - start) / 2;
while (start <= end) {
if (a[mid] == value)
return mid;
if (a[mid] > value)
end = mid - 1;
else
start = mid + 1;
mid = start + (end - start) / 2;
}
return -1;
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | efb0901586592674e7087188e914ce3b | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
public class ImmobileKnight {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i=0;i<t;i++){
int a = sc.nextInt();
int b = sc.nextInt();
if(a>1 && b>1){
if(a>3 || b>3){
System.out.println(a+" "+b);
}
else{
System.out.println(2+" "+2);
}
}
else{
System.out.println(a+" "+b);
}
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | a05a67873351bdf1047eb1e711cf6436 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
public class Codeforce {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int m=sc.nextInt();
if(n==1 || m==1)
{
System.out.println(n+" "+m);
}else if(n==3 && m==3)
{
System.out.println((n-1)+" "+(m-1));
}else if((n==2 && m==3)|| (n==3 && m==2))
{
System.out.println((n-1)+" "+(m-1));
}else{
System.out.println(n+" "+m);
}
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 4590c7cef5bf6bb2ba96d3d0f0f10d91 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
public class code {
public static void main(String[] args) {
Scanner hs = new Scanner(System.in);
int t= hs.nextInt();
int n[]= new int[t];
int m[]= new int[t];
for (int i=0;i<t;i++) {
n[i] = hs.nextInt();
m[i] = hs.nextInt();
}
for(int i=0;i<t;i++) {
if(m[i]>8 || n[i]<1) {
System.out.println("error!");
}
if(m[i]<=3 || n[i]<=3) {
System.out.print((n[i]+1)/2+" ");
System.out.println((m[i]+1)/2);
}else {
System.out.print(1+" ");
System.out.println(1);
}
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 5561d15db5736085824a1e21c5d71392 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.*;
import java.util.*;
public class code
{
public static void main(String args[]) throws Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int m=sc.nextInt();
int dx[]={-2,-2,2,2,1,1,-1,-1};
int dy[]={-1,1,-1,1,-2,2,-2,2};
int x=-1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int c=0;
for(int h=0;h<8;h++)
{
int a=i+dx[h];
int b=j+dy[h];
if(a<=0||a>n||b<=0||b>m)
c++;
}
if(c==8)
{
System.out.println(i+" "+j);
x=1;
break;
}
}
if(x==1)
break;
}
if(x==-1)
System.out.println(n+" "+m);
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 0ecc73ea078625649dfaed5930dd1510 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.*;
import java.sql.PreparedStatement;
import java.util.*;
public class Main {
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;
}
}
public static void count(int[] arr,int start,int ind,HashSet<Integer> set){
for(int i=start;i<=ind;i++){
if(set.contains(arr[i])){
continue;
}
set.add(arr[i]);
}
}
int gcd (int a, int b) {
while (b>0) {
a %= b;
int temp=a;
a=b;
b=temp;
}
return a;
}
static void solve(int n,int m,BufferedWriter output) throws IOException {
if(n==2){
output.write("Yes\n");
output.write(m+"\n");
}else if(m<n||n%2==0 && m%2==1){
output.write("No\n");
}else{
output.write("Yes\n");
for(int i =0;i<n-( 2 - n%2 );++i ){
output.write(1+" ");
m--;
}
if(n%2==0){
output.write(m+" ");
}else{
output.write(m/2+" "+m/2);
}
output.write("\n");
}
output.flush();
}
public static void main(String[] args) throws IOException {
MyScanner s=new MyScanner();
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
String check=s.nextLine();
// if(check==null){
// return;
// }
// int[] arr=new int[26];
// for(char c:str1.toCharArray()){
// arr[c-'a']++;
// }
// for(char c:str2.toCharArray()){
// arr[c-'a']++;
// }
// String ans="";
// int start=0;
// boolean odd;
// char odd1=;
// for(int i=0;i<26;i++){
// if(arr[i]==0){
// continue;
// }else {
// if(arr[i]%2!=0){
// if(!odd){
// odd=true;
// odd1=(char) (arr[i]+'a');
// }
// arr[i]--;
// }
// while(arr[i]!=0){
// ans+=(char) (arr[i]+'a');
// arr[i]-=2;
// }
// }
// }
// string ans2=reverse(ans1);
// if(odd){
// ans+=odd1;
// }
// return ans+ans2;
// int[] diff=new int[n-1];
// sum=0;
// for(int i=0;i<n-1;i++){
// diff[i]=arr[i]-arr[i-1];
// sum+=diff[i];
// }
// for(int i=0;i<n;i++){
// sum-=ar
// }
int t=Integer.parseInt(check);
while(t-->0) {
int r=s.nextInt(),c=s.nextInt();
if(r>3 && c>3){
output.write(r+" "+c+"\n");
}else if(r==c && r==3){
output.write(2+" "+2+"\n");
}else{
output.write((1+r/2)+" "+(1+c/2)+"\n");
}
output.flush();
// int n=s.nextInt();
// int[][] arr=new int[n][2];
// for(int i=0;i<n;i++){
// arr[i][0]=s.nextInt();
// }
// long time=0;
// for(int i=0;i<n;i++){
// arr[i][1]=s.nextInt();
// time+=arr[i][1];
// }
//
// Arrays.sort(arr,(i,j)->i[0]-j[0]);
// long help=
//
// for
// int c=s.nextInt();
// HashMap<Integer,Integer> map=new HashMap();
// while(n-->0){
// int temp=s.nextInt();
// map.put(temp,map.getOrDefault(temp,0)+1);
// }
// int ans=0;
// for(int a:map.keySet()){
// if(map.get(a)<=c){
// ans+=map.get(a);
// }else{
// ans+=c;
// }
// }
// output.write(ans+"\n");
// output.flush();
// String a=s.nextLine();
// int[] arr=new int[a.length()];
// arr[0]=a.charAt(0)-'0';
// for(int i=1;i<arr.length;i++){
// arr[i]=arr[i-1]+(a.charAt(i)-'0');
// arr[i]%=9;
// }
// int size=s.nextInt()-1,q=s.nextInt();
// int temp=0;
// int i=arr.length-size;
// for(;i<arr.length;i++){
// temp+=(a.charAt(i)-'0');
// }
// temp%=9;
// HashMap<Integer,Integer> map=new HashMap<>();
// map.put(temp,arr.length-size-1);
// for(i=arr.length-size-1;i>=0;i--){
// temp+=(a.charAt(i)-'0');
// temp-=(a.charAt(i+size)-'0');
// if(temp<0){
// temp+=9;
// }
// temp%=9;
// map.put(temp,i);
// }
// while(q-->0){
// int l=s.nextInt()-1,r=s.nextInt()-1,k=s.nextInt();
// int mul=arr[r];
// if(l!=0){
// mul-=arr[l-1];
// }
// if(mul<0){
// mul+=9;
// }
// mul%=9;
// int b=-1,a1=-1;
// boolean run=true;
// if(mul==0){
// if(map.containsKey(k)){
// b=map.get(k)+1;
// a1=1;
// }
// }else{
// for(i=0;i<9 && run;i++){
// for(int j=0;j<9;j++){
// if(i==j){
// continue;
// }
// temp=i*mul+j-k;
// temp%=9;
// if(temp==0 && map.containsKey(i) && map.containsKey(j)){
// a1=map.get(i)+1;
// b=map.get(j)+1;
// run=false;
// break;
// }
// }
// }
// }
// output.write(a1+" "+b+"\n");
// output.flush();
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 5904fa985b6ad1bda77d42c76d661bdf | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.System.*;
public class M {
public static void main(String[] args) {
FastScanner x = new FastScanner();
int t = x.nextInt();
while (t-- > 0){
Long max = (long) Integer.MIN_VALUE;
Long min = (long)Integer.MAX_VALUE;
Long res = 0L;
int n = x.nextInt();
boolean boo = true;
int m = x.nextInt();
// Long[] arr = x.readArrayLong(n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (!boo){
break;
}
boolean jur = false;
if (i + 2 <= n && (j - 1 > 0 || j + 1 <= m)){
jur = true;
}
if(i - 2 > 0 && (j - 1 > 0 || j + 1 <= m)){
jur = true;
}
if(j + 2 <= m && (i - 1 > 0 || i + 1 <= n)){
jur = true;
}if(j - 2 > 0 && (i - 1 > 0 || i + 1 <= n)){
jur = true;
}
if(!jur){
boo = false;
out.println(i + " " + j);
break;
}
}
}if (boo){
out.println("1 1");
}
}
}static void scanline(int cnt[],int l,int r){
cnt[r]++;
}
static boolean bin(int[] arr,int target){
int l = 0;
int r = arr.length - 1;
while (l <= r){
int mid = l + (r - l) / 2;
if (arr[mid] == target){
return true;
} else if (arr[mid] > target) {
r = mid - 1;
}else{
l = mid + 1;
}
}return false;
}
static Long getmax(Long[] arr){
Long max = (long) Integer.MIN_VALUE;
for (int i = 0; i < arr.length; i++) {
max = Math.max(max,arr[i]);
}return max;
}
static String getter(String s, int ind,int len){
char a1 = s.charAt(ind);
char a2 = s.charAt(len);
StringBuilder res = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
if (i == ind){
res.append(a2);
} else if (i == len) {
res.append(a1);
}else{
res.append(s.charAt(i));
}
}
return res.toString();
}
static int shift(Integer[] arr,int l,int r,int k){
Integer[] sarr = new Integer[arr.length];
for (int i = 0; i < arr.length; i++) {
sarr[i] = arr[i];
}
for (int i = 0; i < k; i++) {
for (int j = l - 1; j < r - 1; j++) {
arr[j + 1] = arr[j];
}
out.println(Arrays.toString(arr));
}
return arr[arr.length - 1] - arr[0];
}
static int lowerbound(Long[] arr,Long target){ // we can find smallest element in the list that equal or bigger than the target
if(arr == null || arr.length == 0){
return -1;
}
int l = 0;
int r = arr.length - 1;
while (l < r){
int mid = (l + r) / 2;
if (arr[mid] < target){
l = mid + 1;
}else{
r = mid;
}
}
if (arr[l] >= target){
return l;
}
return -1;
}
static int upperbound(Long[] arr,Long target){ // we can find smallest element in the list that bigger than the target
if (arr == null || arr.length == 0){
return -1;
}
int l = 0;
int r = arr.length - 1;
while (l < r){
int mid = (l + r) / 2;
if (arr[mid] <= target){
l = mid + 1;
}else {
r = mid;
}
}
return arr[l] > target ? l : -1;
}
public static void rec(int N,String cur) {
if (cur.length() == N) {
out.println(cur);
return;
}
rec(N, cur + "0");
rec(N, cur + "1");
rec(N,cur + "2");
}
public static int intfromstring(String s){
String[] nums = {"zero","one","two","three","four","five","six","seven","eight","nine","ten"};
for (int i = 0; i < nums.length; i++) {
if (s.equals(nums[i])){
return i;
}
}return -1;
}
public static long NOK(long a,long b){
return lcm(a,b);
}static long gcd(long a,long b){
return b == 0 ? a : gcd(b,a % b);
}static long lcm(long a,long b){
return a / gcd(a,b) * b;
}
public static long sum(long a){
return a * (a - 1) / 2;
}
static boolean odd(int e){
return e % 2 == 1;
}static boolean even(int e){
return e % 2 == 0;
}
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; (long) i * i <= n; i = i + 6){
if (n % i == 0 || n % (i + 2) == 0){
return false;}}
return true;
}static String arrtostring(long res[]){
return Arrays.toString(res).replace(",","").replace("[","").replace("]","");
}
public static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextLine() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextLine());
}
long nextLong() {
return Long.parseLong(nextLine());
}
double nextDouble() {
return Double.parseDouble(nextLine());
}
Integer[] readArray(int n) {
Integer[] a=new Integer[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
Long[] readArrayLong(int n) {
Long[] a=new Long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 3f09f6f627dab68e7d427ae465420e94 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int m = sc.nextInt();
if(n<3 || m<3){
if(n == 2 && m == 3)
System.out.println((n-1)+" "+(m-1));
else if(n == 3 && m== 2)
System.out.println((n-1)+" "+(m-1));
else
System.out.println(n+" "+m);
}
else if(n == 3 && m == 3)
System.out.println("2"+" "+"2");
else
System.out.println((n-1)+" "+(m-1));
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 1461f74f180f2602d44e965af605a93e | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class ArrayFilling {
public static void main (String []args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int m=sc.nextInt();
boolean flag=true;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if( ((i-2)>=0 && (j+1)<m) || ((i-2)>=0 && (j-1)>=0)
|| ((i+2)<n && (j+1)<m) || ((i+2)<n && (j-1)>=0)
|| ((i-1)>=0 && (j-2)>=0) || ((i+1)<n && (j-2)>=0)
|| ((i-1)>=0 && (j+2)<m) || ((i+1)<n && (j+2)<m))
{
continue;
}
else
{
System.out.println((i+1) +" "+ (j+1));
flag=false;
break;
}
}
if(!flag)
break;
}
if(flag)
System.out.println(n+" "+m);
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 59be63f54c0fb32c89697e332b1a28b5 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
//public class codechef
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int m=sc.nextInt();
int p=0;
for(int i=0;i<n;i++)
{//2 3
for(int j=0;j<m;j++)
{
if(((i-2)<0 || (j-1)<0) && ((i-2)<0 || (j+1)>=m) && ((i+2)>=n || (j+1)>=m) && ((i+2)>=n || (j-1)<0) && ((j-2)<0 || (i-1)<0) && ((j-2)<0 || (i+1)>=n) && ((j+2)>=m || (i+1)>=n) && ((j+2)>=m || (i-1)<0))
{
System.out.println((i+1)+" "+(j+1));
p=1;
break;
}
}
if(p==1)
break;
}
if(p==0)
System.out.println(n+" "+m);
}
// your code goes here
}
}
//int p=sc.nextInt();
//int m=sc.nextLong();
//int arr[]=new int[n];
//arr[i]=sc.nextInt();
//String p=sc.next();
//for(int i=0;i<n;i++)
//char ch=s.charAt();
//Collections.sort();
//long arr[]=new long[(int)n]; (int)
// for(long i=0;i<n;i++)
// {
// long p=sc.nextLong();
// if(hm1.containsKey(p))
// {
// hm1.put(p,hm1.get(p)+1);
// }
// else
// {
// hm1.put(p,1);
// }
// }
// for(Map.Entry e:hm1.entrySet)
// {
// if(hm2.containsKey(e.getKey())
// {
// hm2.remove(e.getKey());
// hm1.remove(e.getKey());
// }
// }
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 748ed8d2c942b22b78d6b3076540a496 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i = 0 ; i < t ;i++){
int n = sc.nextInt();
int m = sc.nextInt();
if((n >= 3 && m >=4) || (n >= 4 && m >=3)){
System.out.println(n+" "+m);
continue;
}
if(n ==3 && m == 3){
System.out.println("2 2");
}else{
System.out.println(((n/2)+1)+" "+((m/2)+1));
}
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 2ecfa9f61a463d12a823ae0394120818 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;
public class A {
static FastScanner fs = new FastScanner();
public static void main(String[] args) {
int tc = 1;
// int tc = fs.nextInt();
while (tc-- > 0) {
solve();
}
}
public static void solve() {
int n = fs.nextInt();
int[][] arr = new int[n][2];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
arr[i][j] = fs.nextInt();
}
}
for (int[] a : arr) {
int row = a[0];
int col = a[1];
System.out.println((row + 1) / 2 + " " + (col + 1) / 2);
}
}
// ----------------------------------------------------------------------------------//
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
char nextChar() {
return next().charAt(0);
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
static class Debug {
public static void debug(long a) {
System.out.println("--> " + a);
}
public static void debug(long a, long b) {
System.out.println("--> " + a + " + " + b);
}
public static void debug(char a, char b) {
System.out.println("--> " + a + " + " + b);
}
public static void debug(int[] array) {
System.out.print("Array--> ");
System.out.println(Arrays.toString(array));
}
public static void debug(char[] array) {
System.out.print("Array--> ");
System.out.println(Arrays.toString(array));
}
public static void debug(HashMap<Integer, Integer> map) {
System.out.print("Map--> " + map.toString());
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 8ec474efc0d508205030c1686cfef0f1 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.*;
import java.util.*;
public class A1739 {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
for(int z=1;z<=t;z++){
int n=sc.nextInt();
int m=sc.nextInt();
if(n==1 || m==1){
System.out.println("1 1");
} else if (n<=3 && m<=3){
System.out.println("2 2");
} else {
System.out.println("1 1");
}
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | d6c757cbe1f88a2b307fd5ea535612dd | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | /*
⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿
⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿
⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿
⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿
⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿
⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺
⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘
⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆
⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇
⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇
⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇
⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇
⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇
⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀
⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀
⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸
⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼
⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿
⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿
⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿
⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿
*/
import java.util.*;
public class Ex3 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int oo = 0; oo < t; oo++) {
int n = in.nextInt();
int m = in.nextInt();
if(n == 1 && m == 1){
System.out.println("1 1");
}else if(n == 1 && m == 2){
System.out.println("1 2");
}else if(n == 2 && m == 1){
System.out.println("2 1");
}else if(n == 2 && m ==3 || n == 3 && m ==2|| n==3 && m==3){
System.out.println("2 2");
}else if(n == 3 && m == 4 || n == 4 && m == 3){
System.out.println("1 1");
}else {
System.out.println("1 1");
}
}
}
public class ListNode<E> {
private E value;
private ListNode next;
public ListNode(E newVal, ListNode<E> newNext) {
value = newVal;
next = newNext;
}
public E getValue() {
return value;
}
public ListNode<E> getNext() {
return next;
}
public void setValue(E newValue) {
value = newValue;
}
public void setNext(ListNode<E> newNext) {
next = newNext;
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | d843662d1513d0974c81c0920b65e837 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | // import java.lang.reflect.Array;
// import java.math.BigInteger;
// import java.nio.channels.AcceptPendingException;
// import java.nio.charset.IllegalCharsetNameException;
// import java.util.Collections;
// import java.util.logging.SimpleFormatter;
// import java.util.regex.Matcher;
// import java.util.regex.Pattern;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
/* docstring*/
public class Main {
static Templates.FastScanner sc = new Templates.FastScanner();
static PrintWriter fop = new PrintWriter(System.out);
public static void main(String[] args) {
try {
A();
// B();
// C();
// D();
// E();
} catch (Exception e) {
return;
}
}
/* docstring*/
static void A() throws IOException{
int T = Integer.parseInt(sc.next());
while (T-- > 0) {
int n = Integer.parseInt(sc.next());
int m = Integer.parseInt(sc.next());
if(n == 1 || m == 1){
System.out.println(n+" "+m);
}
else{
System.out.println(((n/2)+1)+" "+((m/2)+1));
}
}
fop.flush();
fop.close();
}
/* docstring*/
static void B() throws IOException{
int T = Integer.parseInt(sc.next());
while (T-- > 0) {
// Write Your Code...
}
fop.flush();
fop.close();
}
/* docstring*/
static void C() throws IOException{
int T = Integer.parseInt(sc.next());
while (T-- > 0) {
// Write Your Code...
}
fop.flush();
fop.close();
}
/* docstring*/
static void D() throws IOException{
int T = Integer.parseInt(sc.next());
while (T-- > 0) {
// Write Your Code...
}
fop.flush();
fop.close();
}
/* docstring*/
static void E() throws IOException{
int T = Integer.parseInt(sc.next());
while (T-- > 0) {
// Write Your Code...
}
fop.flush();
fop.close();
}
}
class Templates {
// int tree[] = new int[4*n+1] ;
// BuiltTree(A , 0 , n-1 , tree , 1);
// int lazy[] = new int[4*n + 1] ;
//
// updateRangeLazy(tree , lazy , 0 , n-1 , 0 , 2 , 10 , 1);
// updateRangeLazy(tree , lazy , 0 , n-1 , 0 , 4 , 10 , 1);
//
// fop.println(querylazy(tree , lazy , 0 , n-1 , 1 ,1 ,1));
//
// updateRangeLazy(tree, lazy , 0 , n-1 , 10 , 4 , 3 ,1);
// fop.println(querylazy(tree , lazy , 0 , n-1 , 3 , 5 , 1 ));
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[] readLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
// segment tree
// BuiltTree(A , 0 , n-1 , tree , 1);
static void BuiltTree(int A[], int s, int e, int tree[], int index) {
if (s == e) {
tree[index] = A[s];
return;
}
int mid = (s + e) / 2;
BuiltTree(A, s, mid, tree, 2 * index);
BuiltTree(A, mid + 1, e, tree, 2 * index + 1);
tree[index] = Math.min(tree[2 * index], tree[2 * index + 1]);
return;
}
static int query(int tree[], int ss, int se, int qs, int qe, int index) {
// complete overlap
if (ss >= qs && se <= qe)
return tree[index];
// no overlap
if (qe < ss || qs > se)
return Integer.MAX_VALUE;
// partial overlap
int mid = (ss + se) / 2;
int left = query(tree, ss, mid, qs, qe, 2 * index);
int right = query(tree, mid + 1, se, qs, qe, 2 * index + 1);
return Math.min(left, right);
}
static void update(int tree[], int ss, int se, int i, int increment, int index) {
// i is the index of which we want to update the value
if (i > se || i < ss)
return;
if (ss == se) {
tree[index] += increment;
return;
}
int mid = (ss + se) / 2;
update(tree, ss, mid, i, increment, 2 * index);
update(tree, mid + 1, se, i, increment, 2 * index + 1);
tree[index] = Math.min(tree[2 * index], tree[2 * index + 1]);
}
static void updateRange(int tree[], int ss, int se, int l, int r, int inc, int index) {
if (l > se || r < ss)
return;
if (ss == se) {
tree[index] += inc;
return;
}
int mid = (ss + se) / 2;
updateRange(tree, ss, mid, l, r, inc, 2 * index);
updateRange(tree, mid + 1, se, l, r, inc, 2 * index + 1);
tree[index] = Math.min(tree[2 * index], tree[2 * index + 1]);
return;
}
// Lazy rnage Update
static void updateRangeLazy(int tree[], int lazy[], int ss, int se, int l, int r, int increment, int index) {
if (lazy[index] != 0) {
tree[index] += lazy[index];
if (ss != se) {
lazy[2 * index] += lazy[index];
lazy[2 * index + 1] += lazy[index];
}
lazy[index] = 0;
}
if (ss > r && se < l)
return;
if (ss >= l && se <= r) {
tree[index] += increment;
if (ss != se) {
lazy[2 * index] += increment;
lazy[2 * index + 1] += increment;
}
return;
}
int mid = (ss + se) / 2;
updateRange(tree, ss, mid, l, r, increment, 2 * index);
updateRange(tree, mid + 1, se, l, r, increment, 2 * index + 1);
tree[index] = Math.min(tree[2 * index], tree[2 * index + 1]);
}
// min lazy query
static int querylazy(int tree[], int lazy[], int ss, int se, int qs, int qe, int index) {
if (lazy[index] != 0) {
tree[index] += lazy[index];
if (ss != se) {
lazy[2 * index] += lazy[index];
lazy[2 * index + 1] += lazy[index];
}
lazy[index] = 0;
}
if (ss > qe || se < qs)
return Integer.MAX_VALUE;
if (ss >= qs && se <= qe)
return tree[index];
int mid = (ss + se) / 2;
int left = querylazy(tree, lazy, ss, mid, qs, qe, 2 * index);
int right = querylazy(tree, lazy, mid + 1, se, qs, qe, 2 * index + 1);
return Math.min(left, right);
}
static void sieve(int n) {
boolean[] flag = new boolean[n];
for (int i = 2; i * i < n; i++) {
if (flag[i])
continue;
else
for (int j = i * i; j <= n; j += i) {
flag[j] = true;
}
}
}
static int gcd(int a, int b) {
if (b > a) {
int tenp = b;
b = a;
a = tenp;
}
int temp = 0;
while (b != 0) {
a %= b;
temp = b;
b = a;
a = temp;
}
return a;
}
static long gcdl(long a, long b) {
if (b > a) {
long tenp = b;
b = a;
a = tenp;
}
long temp = 0;
while (b != 0) {
a %= b;
temp = b;
b = a;
a = temp;
}
return a;
}
static final Random random = new Random();
static void ruffleSort(int[] a) {
int n = a.length;// shuffle, then sort
for (int i = 0; i < n; i++) {
int oi = random.nextInt(n), temp = a[oi];
a[oi] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 72a4b30c58e8acc2847c6b5fc5fb560e | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | // A. Immobile Knight
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.*;
import java.io.*;
public class Main {
static StringBuilder sb;
static dsu dsu;
static long fact[];
static int mod = (int) (1e9 + 7);
static void solve() {
int n = i();
int m = i();
int dx[] = new int[]{-1,-1,1,1,2,2,-2,-2};
int dy[] = new int[]{-2,2,-2,2,-1,1,-1,1};
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
boolean flag = true;
for(int k=0;k<8;k++){
int x = i+dx[k];
int y = j + dy[k];
if(x>0&&x<=n&&y>0&&y<=m) flag = false;
}
if(flag){
sb.append(i+" "+j).append("\n");
return;
}
}
}
sb.append(1+" "+1).append("\n");
}
public static void main(String[] args) {
sb = new StringBuilder();
int test = i();
while (test-- > 0) {
solve();
}
System.out.println(sb);
}
/*
* fact=new long[(int)1e6+10]; fact[0]=fact[1]=1; for(int i=2;i<fact.length;i++)
* { fact[i]=((long)(i%mod)1L(long)(fact[i-1]%mod))%mod; }
*/
//**************NCR%P******************
static long ncr(int n, int r) {
if (r > n)
return (long) 0;
long res = fact[n] % mod;
// System.out.println(res);
res = ((long) (res % mod) * (long) (p(fact[r], mod - 2) % mod)) % mod;
res = ((long) (res % mod) * (long) (p(fact[n - r], mod - 2) % mod)) % mod;
// System.out.println(res);
return res;
}
static long p(long x, long y)// POWER FXN //
{
if (y == 0)
return 1;
long res = 1;
while (y > 0) {
if (y % 2 == 1) {
res = (res * x) % mod;
y--;
}
x = (x * x) % mod;
y = y / 2;
}
return res;
}
//**************END******************
// *************Disjoint set
// union*********//
static class dsu {
int parent[];
dsu(int n) {
parent = new int[n];
for (int i = 0; i < n; i++)
parent[i] = -1;
}
int find(int a) {
if (parent[a] < 0)
return a;
else {
int x = find(parent[a]);
parent[a] = x;
return x;
}
}
void merge(int a, int b) {
a = find(a);
b = find(b);
if (a == b)
return;
parent[b] = a;
}
}
//**************PRIME FACTORIZE **********************************//
static TreeMap<Integer, Integer> prime(long n) {
TreeMap<Integer, Integer> h = new TreeMap<>();
long num = n;
for (int i = 2; i <= Math.sqrt(num); i++) {
if (n % i == 0) {
int nt = 0;
while (n % i == 0) {
n = n / i;
nt++;
}
h.put(i, nt);
}
}
if (n != 1)
h.put((int) n, 1);
return h;
}
//****CLASS PAIR ************************************************
static class Pair implements Comparable<Pair> {
int x;
long y;
Pair(int x, long y) {
this.x = x;
this.y = y;
}
public int compareTo(Pair o) {
return (int) (this.y - o.y);
}
}
//****CLASS PAIR **************************************************
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int Int() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String String() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return String();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
static InputReader in = new InputReader(System.in);
static OutputWriter out = new OutputWriter(System.out);
public static long[] sort(long[] a2) {
int n = a2.length;
ArrayList<Long> l = new ArrayList<>();
for (long i : a2)
l.add(i);
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a2[i] = l.get(i);
return a2;
}
public static char[] sort(char[] a2) {
int n = a2.length;
ArrayList<Character> l = new ArrayList<>();
for (char i : a2)
l.add(i);
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a2[i] = l.get(i);
return a2;
}
public static long pow(long x, long y) {
long res = 1;
while (y > 0) {
if (y % 2 != 0) {
res = (res * x);// % modulus;
y--;
}
x = (x * x);// % modulus;
y = y / 2;
}
return res;
}
//GCD___+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public static long gcd(long x, long y) {
if (x == 0)
return y;
else
return gcd(y % x, x);
}
// ******LOWEST COMMON MULTIPLE
// *********************************************
public static long lcm(long x, long y) {
return (x * (y / gcd(x, y)));
}
//INPUT PATTERN********************************************************
public static int i() {
return in.Int();
}
public static long l() {
String s = in.String();
return Long.parseLong(s);
}
public static String s() {
return in.String();
}
public static int[] readArrayi(int n) {
int A[] = new int[n];
for (int i = 0; i < n; i++) {
A[i] = i();
}
return A;
}
public static long[] readArray(long n) {
long A[] = new long[(int) n];
for (int i = 0; i < n; i++) {
A[i] = l();
}
return A;
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 21c2e9f1f654310d8d17e7d2b36b22f6 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.*;
import java.util.*;
public class acmp2 {
public static void main(String[] args) {
Scanner fastScanner = new Scanner(System.in);
int m= fastScanner.nextInt();
while (m-->0) {
int n = fastScanner.nextInt();
int n2 = fastScanner.nextInt();
if(n < 3 && n2 < 3) System.out.println(1 + " " + 1);
else if((n==3 && n2==2)) System.out.println("2 1");
else if((n==2 && n2==3)) System.out.println("1 2");
else if(n == 3 && n2==3) System.out.println("2 2");
else {
System.out.println(n + " " + n2);
}
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | ce768f5c34588e9b72f620ba1f93de5a | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.*;
import java.util.*;
public class CodeForces {
public static void mergeSort(String[] a, int from, int to) {
if (from == to) {
return;
}
int mid = (from + to) / 2;
// sort the first and the second half
mergeSort(a, from, mid);
mergeSort(a, mid + 1, to);
merge(a, from, mid, to);
}// end mergeSort
public static void merge(String[] a, int from, int mid, int to) {
int n = to - from + 1; // size of the range to be merged
String[] b = new String[n]; // merge both halves into a temporary array b
int i1 = from; // next element to consider in the first range
int i2 = mid + 1; // next element to consider in the second range
int j = 0; // next open position in b
// as long as neither i1 nor i2 past the end, move the smaller into b
while (i1 <= mid && i2 <= to) {
if (a[i1].compareTo(a[i2]) < 0) {
b[j] = a[i1];
i1++;
} else {
b[j] = a[i2];
i2++;
}
j++;
}
// note that only one of the two while loops below is executed
// copy any remaining entries of the first half
while (i1 <= mid) {
b[j] = a[i1];
i1++;
j++;
}
// copy any remaining entries of the second half
while (i2 <= to) {
b[j] = a[i2];
i2++;
j++;
}
// copy back from the temporary array
for (j = 0; j < n; j++) {
a[from + j] = b[j];
}
}//end merge
static int findGCD(int x, int y) {
int r, a, b;
a = Math.max(x, y); // a is greater number
b = Math.min(x, y); // b is smaller number
r = b;
while (a % b != 0) {
r = a % b;
a = b;
b = r;
}
return r;
}
public static void main(String[] args) {
FastReader fastScanner = new FastReader();
int m= fastScanner.nextInt();
while (m-->0) {
int n = fastScanner.nextInt();
int n2 = fastScanner.nextInt();
if(n < 3 && n2 < 3) System.out.println(1 + " " + 1);
else if(n == 3 && n2==3) System.out.println("2 2");
else if((n==3 && n2==2)) System.out.println("2 1");
else if((n==2 && n2==3)) System.out.println("1 2");
else {
System.out.println(n + " " + n2);
}
}
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return st.nextToken();
}
String nextLine() {
String str = "";
try {
if (st.hasMoreTokens()) {
str = st.nextToken("\n");
} else {
str = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 6d973e0d86654d80c5789047682926cf | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class ProblemA {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int m = sc.nextInt();
if(n < 3 || m < 3){
if(n < 3 && m == 3){
System.out.println(1 + " " + 2);
}
else if(m < 3 && n == 3){
System.out.println(2 + " " + 1);
}else{
System.out.println(1 + " " + 1);
}
}else if(n == 3 && m == 3){
System.out.println(2 + " " + 2);
}else{
System.out.println( (n-1) + " " + (m-1) );
}
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 775c964167f300a43ac48c135d30e5a3 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0)
{
int n = sc.nextInt();
int m = sc.nextInt();
if(n==1||m==1)
System.out.println("1 1");
else if(m>=2 && n>=4 || n>=2 && m>=4)
System.out.println("1 1");
else if(m<=2 && n<=2)
System.out.println("1 1");
else
System.out.println("2 2");
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | da08dfb7668dd4dce1a2f8320598926f | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class cc {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int testcase = scan.nextInt();
for(int i = 0 ; i < testcase; i++){
int row = scan.nextInt();
int column = scan.nextInt();
if(row >= 3 && column >= 4 || row >= 4 && column >= 3){
System.out.println(row + " " + column);
}
else{
if(row == column && row == 3){
System.out.println(2 + " " + 2);
}
else{
int r = (row/2) + 1;
int c = (column / 2) + 1;
System.out.println(r + " " + c);
}
}
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | c9bb1b4a1525b95dcc3c5071ee623044 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.*;
import java.util.*;
public class CodeForces {
public static void mergeSort(String[] a, int from, int to) {
if (from == to) {
return;
}
int mid = (from + to) / 2;
// sort the first and the second half
mergeSort(a, from, mid);
mergeSort(a, mid + 1, to);
merge(a, from, mid, to);
}// end mergeSort
public static void merge(String[] a, int from, int mid, int to) {
int n = to - from + 1; // size of the range to be merged
String[] b = new String[n]; // merge both halves into a temporary array b
int i1 = from; // next element to consider in the first range
int i2 = mid + 1; // next element to consider in the second range
int j = 0; // next open position in b
// as long as neither i1 nor i2 past the end, move the smaller into b
while (i1 <= mid && i2 <= to) {
if (a[i1].compareTo(a[i2]) < 0) {
b[j] = a[i1];
i1++;
} else {
b[j] = a[i2];
i2++;
}
j++;
}
// note that only one of the two while loops below is executed
// copy any remaining entries of the first half
while (i1 <= mid) {
b[j] = a[i1];
i1++;
j++;
}
// copy any remaining entries of the second half
while (i2 <= to) {
b[j] = a[i2];
i2++;
j++;
}
// copy back from the temporary array
for (j = 0; j < n; j++) {
a[from + j] = b[j];
}
}//end merge
static int findGCD(int x, int y) {
int r, a, b;
a = Math.max(x, y); // a is greater number
b = Math.min(x, y); // b is smaller number
r = b;
while (a % b != 0) {
r = a % b;
a = b;
b = r;
}
return r;
}
public static void main(String[] args) {
FastReader fastScanner = new FastReader();
int m= fastScanner.nextInt();
while (m-->0) {
int n = fastScanner.nextInt();
int n2 = fastScanner.nextInt();
if(n < 3 && n2 < 3) System.out.println(1 + " " + 1);
else if(n == 3 && n2==3) System.out.println("2 2");
else if((n==3 && n2==2)) System.out.println("2 1");
else if((n==2 && n2==3)) System.out.println("1 2");
else {
System.out.println(n + " " + n2);
}
}
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return st.nextToken();
}
String nextLine() {
String str = "";
try {
if (st.hasMoreTokens()) {
str = st.nextToken("\n");
} else {
str = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 11 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | d17217948e0715a52f52d5bb80957d1d | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main {
public static void swap (int [] arr , int i , int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void main(String[] args) throws IOException {
OutputStreamWriter osr = new OutputStreamWriter(System.out);
PrintWriter o = new PrintWriter(osr);
FastReader fr = new FastReader();
int t = fr.nextInt();
while (t--!=0)
{
int n = fr.nextInt() , m = fr.nextInt();
o.println(((n/2)+1) + " "+ (1+(m/2)));
}
o.close();
}
}
class FastReader {
// Attributes :
BufferedReader br;
StringTokenizer st;
// Constructor :
public FastReader() {
InputStreamReader isr = new InputStreamReader(System.in);
br = new BufferedReader(isr);
}
// Operations :
// #01 :
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
// #02 :
public String nextLine() throws IOException {
return br.readLine();
}
// #03 :
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
// #04 :
public long nextLong() throws IOException {
return Long.parseLong(next());
}
// #05 :
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
// #06 :
public int [] intArray (int size) throws IOException{
int [] arr = new int[size];
for (int i = 0 ; i < size; i++)
arr[i] = nextInt();
return arr;
}
// #07 :
public char [] charArray() throws IOException {
return nextLine().toCharArray();
}
}
class Pair {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
static class Compare implements Comparator<Pair> {
@Override
public int compare(Pair o1, Pair o2) {
return (o1.y - o2.y);
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | c9dddf50a8684d8635c1c86937aaad35 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main {
public static void swap (int [] arr , int i , int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void main(String[] args) throws IOException {
OutputStreamWriter osr = new OutputStreamWriter(System.out);
PrintWriter o = new PrintWriter(osr);
FastReader fr = new FastReader();
int t = fr.nextInt();
while (t--!=0)
{
int n = fr.nextInt() , m = fr.nextInt();
o.println((int)ceil(n/2.0) + " "+ (int)ceil(m/2.0));
}
o.close();
}
}
class FastReader {
// Attributes :
BufferedReader br;
StringTokenizer st;
// Constructor :
public FastReader() {
InputStreamReader isr = new InputStreamReader(System.in);
br = new BufferedReader(isr);
}
// Operations :
// #01 :
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
// #02 :
public String nextLine() throws IOException {
return br.readLine();
}
// #03 :
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
// #04 :
public long nextLong() throws IOException {
return Long.parseLong(next());
}
// #05 :
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
// #06 :
public int [] intArray (int size) throws IOException{
int [] arr = new int[size];
for (int i = 0 ; i < size; i++)
arr[i] = nextInt();
return arr;
}
// #07 :
public char [] charArray() throws IOException {
return nextLine().toCharArray();
}
}
class Pair {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
static class Compare implements Comparator<Pair> {
@Override
public int compare(Pair o1, Pair o2) {
return (o1.y - o2.y);
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 0eb205db8f8553317e13fe3d9b37bce5 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main {
public static void swap (int [] arr , int i , int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void main(String[] args) throws IOException {
OutputStreamWriter osr = new OutputStreamWriter(System.out);
PrintWriter o = new PrintWriter(osr);
FastReader fr = new FastReader();
int t = fr.nextInt();
while (t--!=0)
{
int n = fr.nextInt() , m = fr.nextInt();
int x = 1 , y = 1;
for (int i = 1 ; i < n ; i++)
{
for (int j = 1 ; j < m ; j++)
{
if (!((i + 2) < n && (j + 1) < m) && !((i+2) < n && (j-1) > 0) && !((i-2) > 0 && (j+1) < m) && !((i-2) > 0 && (j-1) > 0) && !((j+2) < m && (i+1) < n) && !((j+2) < m && (i-1) > 0) && !((j-2) > 0 && (i+1) < n) && !((j-2) > 0 && (i-1) > 0))
{
x = i;
y = j;
}
}
}
o.println(x + " " + y);
}
o.close();
}
}
class FastReader {
// Attributes :
BufferedReader br;
StringTokenizer st;
// Constructor :
public FastReader() {
InputStreamReader isr = new InputStreamReader(System.in);
br = new BufferedReader(isr);
}
// Operations :
// #01 :
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
// #02 :
public String nextLine() throws IOException {
return br.readLine();
}
// #03 :
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
// #04 :
public long nextLong() throws IOException {
return Long.parseLong(next());
}
// #05 :
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
// #06 :
public int [] intArray (int size) throws IOException{
int [] arr = new int[size];
for (int i = 0 ; i < size; i++)
arr[i] = nextInt();
return arr;
}
// #07 :
public char [] charArray() throws IOException {
return nextLine().toCharArray();
}
}
class Pair {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
static class Compare implements Comparator<Pair> {
@Override
public int compare(Pair o1, Pair o2) {
return (o1.y - o2.y);
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | d5a54a4e0badc45fd8142b4281cd0208 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main {
public static void swap (int [] arr , int i , int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void main(String[] args) throws IOException {
OutputStreamWriter osr = new OutputStreamWriter(System.out);
PrintWriter o = new PrintWriter(osr);
FastReader fr = new FastReader();
int t = fr.nextInt();
while (t--!=0)
{
int n = fr.nextInt() , m = fr.nextInt();
int x = 1 , y = 1;
for (int i = 1 ; i < n; i++)
{
for (int j = 1 ; j < m ; j++) {
if (((i + 2) < n && (j + 1) < m) || ((i+2) < n && (j-1) > 0) || ((i-2) > 0 && (j+1) < m) || ((i-2) > 0 && (j-1) > 0) || ((j+2) < m && (i+1) < n) || ((j+2) < m && (i-1) > 0) || ((j-2) > 0 && (i+1) < n) || ((j-2) > 0 && (i-1) > 0))
continue;
else
{
x = i;
y = j;
}
}
}
o.println(x+" "+y);
}
o.close();
}
}
class FastReader {
// Attributes :
BufferedReader br;
StringTokenizer st;
// Constructor :
public FastReader() {
InputStreamReader isr = new InputStreamReader(System.in);
br = new BufferedReader(isr);
}
// Operations :
// #01 :
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
// #02 :
public String nextLine() throws IOException {
return br.readLine();
}
// #03 :
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
// #04 :
public long nextLong() throws IOException {
return Long.parseLong(next());
}
// #05 :
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
// #06 :
public int [] intArray (int size) throws IOException{
int [] arr = new int[size];
for (int i = 0 ; i < size; i++)
arr[i] = nextInt();
return arr;
}
// #07 :
public char [] charArray() throws IOException {
return nextLine().toCharArray();
}
}
class Pair {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
static class Compare implements Comparator<Pair> {
@Override
public int compare(Pair o1, Pair o2) {
return (o1.y - o2.y);
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 9c823f2dcf2d5ff4dc64d5284bec1640 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
FastScanner input = new FastScanner();
Algorithm algorithm = new Algorithm();
int t = input.nextInt();
while (t-- > 0) {
int n = input.nextInt();
int m = input.nextInt();
if(n == 1 || m == 1){
System.out.println(1 + " " + 1);
}else if(n < 3 && m < 3){
System.out.println(1 + " " + 1);
}else{
System.out.println((n-1) + " " + (m-1));
}
}
}
}
class Algorithm {
int maxElement(int[] a) {
int max = Integer.MIN_VALUE;
for (int i = 0; i < a.length; ++i) {
max = Math.max(max, a[i]);
}
return max;
}
int lower_bound(long[] a, int x) {
int l = 1, r = a.length, ans = 0;
while ((r - l) >= 0) {
int m = (l + r) >> 1;
if (a[m] >= x) {
ans = m;
r = m - 1;
} else {
l = m + 1;
}
}
return ans;
}
int upper_bound(long[] a, long x) {
int l = 1, r = a.length;
while ((r - l) >= 0) {
int m = l + r >> 1;
if (a[m] > x) {
r = m - 1;
} else {
l = m + 1;
}
}
return l;
}
boolean sqrt(long x){
long l = 0;
long r = 10000000L;
while((r - l) >= 0){
long m = (l + r) >> 1;
long square = (long) m * m;
if(square == x) return true;
if (square > x) r = m - 1;
else l = m + 1;
}
return false;
}
boolean isPrime(long n){
if (n < 2) return false;
if (n == 2 || n == 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
long end = (long) Math.sqrt(n) + 1;
for (long i = 6; i <= end; i += 6) {
if (n % (i - 1) == 0 || n % (i + 1) == 0) return false;
}
return true;
}
long[] prefixSum(int[] arr) {
long[] prefixsum = new long[arr.length];
for (int i = 1; i < arr.length; i++) {
prefixsum[i] = prefixsum[i-1] + arr[i];
}
return prefixsum;
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(){
init();
}
public FastScanner(String name) {
init(name);
}
public FastScanner(boolean isOnlineJudge){
if(!isOnlineJudge || System.getProperty("ONLINE_JUDGE") != null){
init();
}else{
init("input.txt");
}
}
private void init(){
br = new BufferedReader(new InputStreamReader(System.in));
}
private void init(String name){
try {
br = new BufferedReader(new FileReader(name));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public String nextToken(){
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(nextToken());
}
public long nextLong(){
return Long.parseLong(nextToken());
}
public double nextDouble(){
return Double.parseDouble(nextToken());
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 5410022fc92df19334a66c3cfbb96171 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | //package first_project;
import java.util.*;
public class First_project {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int r,c,size;
size = input.nextInt();
for (int i = 0; i < size; i++) {
r = input.nextInt();
c = input.nextInt();
if(r > 2 && c > 3 || r > 3 && c > 2 ){
System.out.println("1"+" "+"1");
}
else{
if(r%2!=0)
{
r/=2;
r++;
}
else{
r/=2;
}
if(c%2!=0)
{
c/=2;
c++;
}
else{
c/=2;
}
System.out.println(r + " " + c);
}
// System.out.println("");
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 04c1547d4455e75e7d89d9bb2890ed09 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes |
import java.util.*;
public class First_project {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int r,c,size;
size = input.nextInt();
for (int i = 0; i < size; i++) {
r = input.nextInt();
c = input.nextInt();
int k = r/2;
int j = c/2;
if(r%2!=0)
k++;
if(c%2!=0)
j++;
if(k-1<1||k-2<1||k+1>r||k+2>r)
{
if(j-1<1||j-2<1||j+1>c||j+2>c)
{
System.out.println(k+" "+j);
}
else{
System.out.println("1"+" "+"1");
}
}
else{
System.out.println("1"+" "+"1");
}
System.out.println("");
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 13fb04e52f81e8b2d7ca02fe4da84717 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.*;
import java.lang.*;
import java.util.*;
public class Main {
static PrintWriter out;
static int MOD = 1000000007;
static FastReader scan;
/*-------- I/O usaing short named function ---------*/
public static String ns() {
return scan.next();
}
public static int ni() {
return scan.nextInt();
}
public static long nl() {
return scan.nextLong();
}
public static double nd() {
return scan.nextDouble();
}
public static String nln() {
return scan.nextLine();
}
public static void p(Object o) {
out.print(o);
}
public static void ps(Object o) {
out.print(o + " ");
}
public static void pn(Object o) {
out.println(o);
}
/*-------- for output of an array ---------------------*/
static void iPA(int arr[]) {
StringBuilder output = new StringBuilder();
for (int i = 0; i < arr.length; i++) output.append(arr[i] + " ");
out.println(output);
}
static void lPA(long arr[]) {
StringBuilder output = new StringBuilder();
for (int i = 0; i < arr.length; i++) output.append(arr[i] + " ");
out.println(output);
}
static void sPA(String arr[]) {
StringBuilder output = new StringBuilder();
for (int i = 0; i < arr.length; i++) output.append(arr[i] + " ");
out.println(output);
}
static void dPA(double arr[]) {
StringBuilder output = new StringBuilder();
for (int i = 0; i < arr.length; i++) output.append(arr[i] + " ");
out.println(output);
}
/*-------------- for input in an array ---------------------*/
static void iIA(int arr[]) {
for (int i = 0; i < arr.length; i++) arr[i] = ni();
}
static void lIA(long arr[]) {
for (int i = 0; i < arr.length; i++) arr[i] = nl();
}
static void sIA(String arr[]) {
for (int i = 0; i < arr.length; i++) arr[i] = ns();
}
static void dIA(double arr[]) {
for (int i = 0; i < arr.length; i++) arr[i] = nd();
}
/*------------ for taking input faster ----------------*/
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;
}
}
// Method to check if x is power of 2
static boolean isPowerOfTwo(int x) {
return x != 0 && ((x & (x - 1)) == 0);
}
//Method to return lcm of two numbers
static int gcd(int a, int b) {
return a == 0 ? b : gcd(b % a, a);
}
//Method to count digit of a number
static int countDigit(long n) {
return (int) Math.floor(Math.log10(n) + 1);
}
//Method for sorting
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a) l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++) a[i] = l.get(i);
}
//Method for checking if a number is prime or not
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;
}
public static void reverse(int a[], int n) {
int i, k, t;
for (i = 0; i < n / 2; i++) {
t = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = t;
}
// printing the reversed array
System.out.println("Reversed array is: \n");
for (k = 0; k < n; k++) {
System.out.println(a[k]);
}
}
public static int binarysearch(int arr[], int left, int right, int num) {
int idx = 0;
while (left <= right) {
int mid = (left + right) / 2;
if (arr[mid] >= num) {
idx = mid;
// if(arr[mid]==num)break;
right = mid - 1;
} else {
left = mid + 1;
}
}
return idx;
}
public static void main(String[] args) throws java.lang.Exception {
OutputStream outputStream = System.out;
out = new PrintWriter(outputStream);
scan = new FastReader();
int t = ni();
while (t-- > 0) {
int n = ni();
int m = ni();
if (n == 1 || m == 1) {
System.out.println(n + " " + m);
}else if (n >= 4 && m > 1) {
System.out.println(n + " " + m);
} else if (m >= 4 && n > 1) {
System.out.println(n + " " + m);
}
else {
System.out.println(((n/2) +1 )+ " " + ((m/2) +1));
}
}
out.flush();
out.close();
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 6f8e5e4c9165d3068abb85b5f33773d3 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.*;
public class immobileKnight{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T>0){
int n = sc.nextInt();
int m = sc.nextInt();
if((n==1)||(m==1)){
System.out.println(1+" "+1);
}
else if(n<=3&&m<=3){
System.out.println(2+" "+2);
}
else{
System.out.println(n+" "+m);
}
// else if(n<3&&m<8){
// System.out.println(n+" "+m);
// }
// else if(n>8&&m>8){
// System.out.println(n+" "+m);
// }
T--;
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | f79f25a1d10197ecce7b4c459da73796 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | //package hello;
import java.util.*;
public class Codeforces {
public static void main(String[] args) {
int[][] dir = {{-2,1},{-1,2},{1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1}};
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int m = sc.nextInt();
if(n<2 || m<2){
System.out.println(n+" "+m);
}
else if(n==3 || m ==3) System.out.println(2+" "+2);
// else if(n>=4 && m>=4){
// System.out.println(1+" "+1);
// }
else System.out.println(n+" "+m);
// else{
// boolean fl = false;
// for(int i=0;i<n;i++){
// for(int j=0;j<m;j++){
// boolean possible = false;
//
// for(int k=0;k<8;k++){
// int x = i+dir[k][0];
// int y = j+dir[k][1];
// if(x>=0 && x<n && y>=0 && y<m){
// possible=true;
// break;
// }
// }
//
// if(possible==false){
// int r = i+1,col =j+1;
// System.out.println(r+" "+col);
// fl=true;
// break;
// }
// }
// if(fl) break;
// }
// }
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 1131d720aa81f789225977c6b4aa9fad | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.*;
import java.util.*;
public class acmp {
public static void main(String[]args) {
Scanner sc = new Scanner(System.in);
int a=sc.nextInt();
for (int i = 0; i < a;i++) {
int m=sc.nextInt();
int n=sc.nextInt();
if(n>1 && m>1){
System.out.println (Math.round(m/2)+1+" "+(Math.round(n/2)+1));
}
else if(m==1){
System.out.println(m+" "+(Math.round(n/2)+1));
}
else{
System.out.println((Math.round(m/2)+1)+" "+n);
}
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 979979d512244e1d6f74fa485299f29c | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes |
import java.util.*;
public class code {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int t= sc.nextInt();
while(t-->0){
solve();
}
}
static void solve() {
int n=sc.nextInt();
int m=sc.nextInt();
if(n==1 || m==1) System.out.println(1+" "+1);
else System.out.println(2+" "+2);
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 7d248a77f1dbc0c1ac148cda9b7e9dd1 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.PrintWriter;
public class MyClass {
public static void main(String[] args) {
InputReader scanner = new InputReader(System.in);
PrintWriter output = new PrintWriter(System.out);
int T = scanner.nextInt();
while (T-- > 0) {
int n = scanner.nextInt();
int m = scanner.nextInt();
int min = Math.min(n, m);
int max = Math.max(n, m);
if (min == 2) {
if (max == 3) {
if (n == 2) {
output.println("1 2");
} else {
output.println("2 1");
}
continue;
}
}
if (n == 3 && m == 3) {
output.println("2 2");
continue;
}
output.println(n + " " + m);
}
output.close();
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 1b59d00d9c0d1301a619fa20761b157f | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.io.*;
import java.util.*;
public class CF {
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int T=Integer.parseInt(br.readLine());
while(T-->0)
{
String[] s=br.readLine().split(" ");
int n=Integer.parseInt(s[0]);
int m=Integer.parseInt(s[1]);
if(n==1 || m==1)
System.out.println(1+" "+1);
else if(n==3 && m==3)
System.out.println(2+" "+2);
else
{
boolean found=false;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(isIsolated(i, j, n, m))
{
found=true;
System.out.println(i+" "+j);
break;
}
}
if(found)
break;
}
if(!found)
System.out.println(1+" "+1);
}
}
}
static boolean isIsolated(int i,int j,int n,int m)
{
int[] di={1,1,-1,-1,2,2,-2,-2};
int[] dj={2,-2,2,-2,1,-1,1,-1};
for(int k=0;k<8;k++)
{
if(i+di[k]<1 || i+di[k]>n || j+dj[k]<1 || j+dj[k]>m)
continue;
return false;
}
return true;
}
}
// Aman and garden
// Medium
// There is a garden and Aman is the gardener and he wants to arrange trees in a row
// of length n such that every Kth plant is non-decreasing in height. For example the plant
// at position 1 should be smaller than or equal to the tree planted at position 1+K and plant
// at position 1+K should be smaller than or equal to 1+2*K and so on, this
// should be true for every position(for eg. 2 <= 2+K <= 2+2*K ...).
// Now Aman can change a plant at any position with a plant of any height in order to create
// the required arrangment. He wants to know minimum number of trees he will have to change to get the required arrangement.
// We"ll be given a plants array which represents the height of plants at every position
// and a number K and we need to output the minimum number of plants we will have to change to get the required arrangement.
// Example:
// plants = [5,3,4,1,6,5];
// K=2;
// here plants at index (0,2,4) and (1,3,5) should be non decreasing.
// plants[0]=5;
// plants[2]=4;
// plants[4]=6;
// We can change the plant at index 2 with a plant of height 5(one change).
// Similarly
// plants[1]=3;
// plants[3]=1;
// plants[5]=5;
// We can change the plant at index 3 with a plant of height 4(one change).
// So minimum 2 changes are required.
// Constraints
// 1<=plants.length<=100000
// 1<=plants[i],K<=plants.length
// Format
// Input
// First line contains an integer N representing length of the plant array.
// Next line contains N space separated integers representing height of trees.
// Last line contains an integer K
// Output
// Output the minimum number of changes required.
// Example
// Sample Input
// 6
// 5
// 3
// 4
// 1
// 6
// 5
// 2
// Sample Output
// 2
// Tokyo Drift
// Easy
// There is a racing competition which will be held in your city next weekend. There are N racers who are going to take part in the competition. Each racer is at a given distance from the finish line, which is given in an integer array.
// Due to some safety reasons, total sum of speeds with which racers can drive is restricted with a given limit. Since, cost of organizing such an event depends on how long the event will last, you need to find out the minimum time in which all racers will cross the finishing line, but sum of speeds of all racers should be less than or equal to the given limit.
// If it is impossible to complete the race for all racers within given limit, we have to return -1.
// Note: Speed is defined as Ceil (distance/time), where ceil represents smaller than or equal to. For example if distance is 20 km and time taken to travel is 3 hrs then speed equals ceil(20/3) i.e. 7 km/hr.
// Example: Let us take 4 Racers with Distances from finishing line as [15 km, 25 km, 5 km, 20 km], and the maximum sum of speeds allowed is 12 km/hr. The minimum time in which all racers will reach the finishing line will be 7 hours.
// Racer 1 will have 15 km / 7 hr = 3 km/hr speed
// Racer 2 will have 25 km / 7 hr = 4 km/hr speed
// Racer 3 will have 05 km / 7 hr = 1 km/hr speed
// Racer 4 will have 20 km / 7 hr = 3 km/hr speed
// Hence, the total sum of speeds will be (3 + 4 + 1 + 3) = 11 km/hr which is less than or equal to 12 km/hr.
// Constraints
// 1 <= N <= 100000
// 1 <= racers[i] <= 10000000
// 1 <= Limit <= 10000000
// Format
// Input
// First line contains an integer N representing length of array.
// Next line contains N space seprated integers representing distance from finishing line.
// Last line contains an integer representing limit of sum of speeds with which racers can drive
// Output
// A single line integer representing minimum time in which all racers will cross the finishing line, If not possible print -1
// Example
// Sample Input
// 4
// 15 25 5 20
// 12
// Sample Output
// 7
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 415c0e8cbc8a826084681cae183ffaad | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | //shynkakakakkakakakak
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
for (int i = 0; i < a; i++) {
int b = sc.nextInt();
int c = sc.nextInt();
if (b == 3 && c == 3) {
System.out.println("2 2");
}
else {
System.out.println(b / 2 + 1+ " " + (c / 2 + 1));
}
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | e3b5a1fd0fd1b7b599c3dba225d32faf | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | //shynkakakakkakakakak
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
for (int i = 0; i < a; i++) {
int b = sc.nextInt();
int c = sc.nextInt();
if (b == 3 && c == 3) {
System.out.println("2 2");
}
else {
System.out.println(b / 2 + 1 + " " + (c / 2 + 1));
}
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output | |
PASSED | 2eaef46a44c6ba4851bb6bdf6cebe913 | train_109.jsonl | 1664462100 | There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board. | 256 megabytes | import java.util.Scanner;
public class Knight {
public static void main(String arg[])
{
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
for(int i=0;i<n;i++)
{
int x=scan.nextInt();
int y=scan.nextInt();
if(x==3||y==3)
{
if(x==1||y==1)
System.out.println(1+" "+1);
else
System.out.println(2+" "+2);
}
else
System.out.println(1+" "+1);
}
}
}
| Java | ["3\n\n1 7\n\n8 8\n\n3 3"] | 2 seconds | ["1 7\n7 2\n2 2"] | NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle. | Java 8 | standard input | [
"implementation"
] | e6753e3f71ff13cebc1aaf04d3d2106b | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board. | 800 | For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.