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 | 1236a49bde8623744849ce94f9c6150d | train_109.jsonl | 1636869900 | You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 < i_2 < \ldots < i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$? | 256 megabytes | //---#ON_MY_WAY---
import static java.lang.Math.*;
import java.io.*;
import java.math.*;
import java.util.*;
public class apples {
static class pair {
int x, y;
public pair(int a, int b) {
x = a;
y = b;
}
}
static FastReader x = new FastReader();
static OutputStream outputStream = System.out;
static PrintWriter out = new PrintWriter(outputStream);
/*---------------------------------------CODE STARTS HERE-------------------------*/
public static void main(String[] args) throws NumberFormatException, IOException {
long startTime = System.nanoTime();
int mod = 1000000007;
int t = x.nextInt();
StringBuilder str = new StringBuilder();
while (t > 0) {
int n = x.nextInt();
int a[] = readarr(n);
int b[] = readarr(n);
sortint(a);
sortint(b);
int f = 0;
for (int i = 0; i < n; i++) {
if(abs(a[i]-b[i])>1||a[i]>b[i]) {
f = 1;
break;
}
}
if(f==0) {
str.append("YES");
}
else {
str.append("NO");
}
str.append("\n");
t--;
}
out.println(str);
out.flush();
long endTime = System.nanoTime();
//System.out.println((endTime-startTime)/1000000000.0);
}
/*--------------------------------------------FAST I/O--------------------------------*/
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
char nextchar() {
char ch = ' ';
try {
ch = (char) br.read();
} catch (IOException e) {
e.printStackTrace();
}
return ch;
}
}
/*--------------------------------------------BOILER PLATE---------------------------*/
static int[] readarr(int n) {
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = x.nextInt();
}
return arr;
}
static int[] sortint(int a[]) {
ArrayList<Integer> al = new ArrayList<>();
for (int i : a) {
al.add(i);
}
Collections.sort(al);
for (int i = 0; i < a.length; i++) {
a[i] = al.get(i);
}
return a;
}
static long[] sortlong(long a[]) {
ArrayList<Long> al = new ArrayList<>();
for (long i : a) {
al.add(i);
}
Collections.sort(al);
for (int i = 0; i < al.size(); i++) {
a[i] = al.get(i);
}
return a;
}
static long pow(long x, long y) {
long result = 1;
while (y > 0) {
if (y % 2 == 0) {
x = x * x;
y = y / 2;
} else {
result = result * x;
y = y - 1;
}
}
return result;
}
static long pow(long x, long y, long mod) {
long result = 1;
x %= mod;
while (y > 0) {
if (y % 2 == 0) {
x = (x%mod * x%mod) % mod;
y /= 2;
} else {
result = (result%mod * x%mod) % mod;
y--;
}
}
return result;
}
static int[] revsort(int a[]) {
ArrayList<Integer> al = new ArrayList<>();
for (int i : a) {
al.add(i);
}
Collections.sort(al, Comparator.reverseOrder());
for (int i = 0; i < a.length; i++) {
a[i] = al.get(i);
}
return a;
}
static int[] gcd(int a, int b, int ar[]) {
if (b == 0) {
ar[0] = a;
ar[1] = 1;
ar[2] = 0;
return ar;
}
ar = gcd(b, a % b, ar);
int t = ar[1];
ar[1] = ar[2];
ar[2] = t - (a / b) * ar[2];
return ar;
}
static boolean[] esieve(int n) {
boolean p[] = new boolean[n + 1];
Arrays.fill(p, true);
for (int i = 2; i * i <= n; i++) {
if (p[i] == true) {
for (int j = i * i; j <= n; j += i) {
p[j] = false;
}
}
}
return p;
}
static ArrayList<Integer> primes(int n) {
boolean p[] = new boolean[n + 1];
ArrayList<Integer> al = new ArrayList<>();
Arrays.fill(p, true);
int i = 0;
for (i = 2; i * i <= n; i++) {
if (p[i] == true) {
al.add(i);
for (int j = i * i; j <= n; j += i) {
p[j] = false;
}
}
}
for (i = i; i <= n; i++) {
if (p[i] == true) {
al.add(i);
}
}
return al;
}
static int etf(int n) {
int res = n;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
res /= i;
res *= (i - 1);
while (n % i == 0) {
n /= i;
}
}
}
if (n > 1) {
res /= n;
res *= (n - 1);
}
return res;
}
static int gcd(int a, int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
static long gcd(long a, long b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
} | Java | ["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"] | 1 second | ["YES\nNO\nYES"] | NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements. | Java 8 | standard input | [
"greedy",
"math",
"sortings"
] | 6ca98e655007bfb86f1039c9f096557e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$). | 900 | For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower). | standard output | |
PASSED | 56bfd26516a775ee0bdbc1e9e72607ed | train_109.jsonl | 1636869900 | You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 < i_2 < \ldots < i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$? | 256 megabytes | 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 codeforcesA{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static int gcd(int a,int b){if(b==0){return a;}return gcd(b,a%b);}
public static void main(String args[]){
FastReader sc=new FastReader();
int t=sc.nextInt();
StringBuilder sb=new StringBuilder();
while(t-->0){
//aa,aba,aca,abca,acba,abbacca,accabba
int n=sc.nextInt();
int ar[]=new int[n];
int br[]=new int[n];
Map<Integer,Integer> map=new HashMap<>();
for(int i=0;i<n;i++){ar[i]=sc.nextInt();map.put(ar[i],map.getOrDefault(ar[i],0)+1);}
for(int i=0;i<n;i++){br[i]=sc.nextInt();}
Arrays.sort(br);boolean flag=true;
for(int i=n-1;i>=0;i--){
if(map.get(br[i])!=null && map.get(br[i])>0){
map.put(br[i],map.get(br[i])-1);
}
else{
if(map.get(br[i]-1)!=null && map.get(br[i]-1)>0){
map.put(br[i]-1,map.get(br[i]-1)-1);
}
else{flag=false;break;}
}
}
System.out.println(flag?"YES":"NO");
}
}
} | Java | ["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"] | 1 second | ["YES\nNO\nYES"] | NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements. | Java 8 | standard input | [
"greedy",
"math",
"sortings"
] | 6ca98e655007bfb86f1039c9f096557e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$). | 900 | For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower). | standard output | |
PASSED | dbe2e5678e8de835c8ac552801e7fa8e | train_109.jsonl | 1636869900 | You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 < i_2 < \ldots < i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$? | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int test = 0; test < t; test++) {
int n = in.nextInt();
int[] a = new int[n];
int[] b = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
for (int i = 0; i < n; i++) {
b[i] = in.nextInt();
}
Arrays.sort(a);
Arrays.sort(b);
boolean flag = false;
for (int i = 0; i < n; i++) {
if (!(a[i] == b[i] || a[i] + 1 == b[i])) {
flag = true;
break;
}
}
System.out.println(flag ? "NO" : "YES");
}
}
} | Java | ["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"] | 1 second | ["YES\nNO\nYES"] | NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements. | Java 8 | standard input | [
"greedy",
"math",
"sortings"
] | 6ca98e655007bfb86f1039c9f096557e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$). | 900 | For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower). | standard output | |
PASSED | b31073f749a7d5b5522e9de90e79a550 | train_109.jsonl | 1636869900 | You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 < i_2 < \ldots < i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$? | 256 megabytes | import java.util.*;
import java.io.*;
public class C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
for (; t > 0; t--) {
int n = sc.nextInt();
int[] a = new int[n];
int[] b = new int[n];
for (int i = 0; i < n; i++) a[i] = sc.nextInt();
for (int i = 0; i < n; i++) b[i] = sc.nextInt();
Arrays.sort(a);
Arrays.sort(b);
boolean possible = true;
for (int i = 0; i < n; i++)
if (b[i] - a[i] != 0 && b[i] - a[i] != 1) {
possible = false;
break;
}
out.println(possible ? "YES" : "NO");
}
out.close();
sc.close();
}
}
| Java | ["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"] | 1 second | ["YES\nNO\nYES"] | NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements. | Java 8 | standard input | [
"greedy",
"math",
"sortings"
] | 6ca98e655007bfb86f1039c9f096557e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$). | 900 | For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower). | standard output | |
PASSED | bf70fd418dd799e800d2414d5f356669 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.DataInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
public class Main {
private static void run() throws IOException {
int n, m;
n = in.nextInt();
m = in.nextInt();
int size = n * m;
int ans = size / 3;
if (size % 3 != 0) ans++;
out.println(ans);
}
public static void main(String[] args) throws IOException {
in = new Reader();
out = new PrintWriter(new OutputStreamWriter(System.out));
int t = in.nextInt();
for (int i = 0; i < t; i++) {
run();
}
out.flush();
in.close();
out.close();
}
private static int gcd(int a, int b) {
if (a == 0 || b == 0)
return 0;
while (b != 0) {
int tmp;
tmp = a % b;
a = b;
b = tmp;
}
return a;
}
static final long mod = 1000000007;
static long pow_mod(long a, long b) {
long result = 1;
while (b != 0) {
if ((b & 1) != 0) result = (result * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return result;
}
private static long multiplied_mod(long... longs) {
long ans = 1;
for (long now : longs) {
ans = (ans * now) % mod;
}
return ans;
}
@SuppressWarnings("FieldCanBeLocal")
private static Reader in;
private static PrintWriter out;
private static int[] read_int_array(int len) throws IOException {
int[] a = new int[len];
for (int i = 0; i < len; i++) {
a[i] = in.nextInt();
}
return a;
}
private static long[] read_long_array(int len) throws IOException {
long[] a = new long[len];
for (int i = 0; i < len; i++) {
a[i] = in.nextLong();
}
return a;
}
private static void print_array(int[] array) {
for (int now : array) {
out.print(now);
out.print(' ');
}
out.println();
}
private static void print_array(long[] array) {
for (long now : array) {
out.print(now);
out.print(' ');
}
out.println();
}
static class Reader {
private static final int BUFFER_SIZE = 1 << 16;
private final DataInputStream din;
private final byte[] buffer;
private int bufferPointer, bytesRead;
Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
final byte[] buf = new byte[1024]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
break;
}
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextSign() throws IOException {
byte c = read();
while ('+' != c && '-' != c) {
c = read();
}
return '+' == c ? 0 : 1;
}
private static boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
public int skip() throws IOException {
int b;
// noinspection ALL
while ((b = read()) != -1 && isSpaceChar(b)) {
;
}
return b;
}
public char nc() throws IOException {
return (char) skip();
}
public String next() throws IOException {
int b = skip();
final StringBuilder sb = new StringBuilder();
while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = read();
}
return sb.toString();
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
final boolean neg = c == '-';
if (neg) {
c = read();
}
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg) {
return -ret;
}
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
final boolean neg = c == '-';
if (neg) {
c = read();
}
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg) {
return -ret;
}
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ') {
c = read();
}
final boolean neg = c == '-';
if (neg) {
c = read();
}
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg) {
return -ret;
}
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) {
buffer[0] = -1;
}
}
private byte read() throws IOException {
if (bufferPointer == bytesRead) {
fillBuffer();
}
return buffer[bufferPointer++];
}
public void close() throws IOException {
din.close();
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 17 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 239f0d4e77330e0bbd23f4baeac9fce4 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.Random;
public class ColoringRectangles {
public static void main(String[] args) {
ContestScanner scanner = new ContestScanner();
int tests = scanner.nextInt();
for (int i = 0; i < tests; i++) {
int n = scanner.nextInt();
int m = scanner.nextInt();
System.out.println(solve(n, m));
}
}
private static int solve(int n, int m) {
if (n % 3 == 0) {
return n / 3 * m;
}
if (m % 3 == 0) {
return m / 3 * n;
}
int sum = n + m;
n = Math.min(n, m);
m = sum - n;
if (n == 1) {
return lineColors(m);
} else {
int numOfThree = m / 3 * n;
if (m % 3 == 1) {
return numOfThree + lineColors(n);
} else {
if (n % 3 == 1) {
return numOfThree + (n / 3) * 2 + 1;
} else {
return numOfThree + 2 * (n / 3 + 1);
}
}
}
}
private static int lineColors(int m) {
if (m == 2) {
return 1;
}
if (m % 3 == 1) {
return Math.max(0, m / 3 - 1) + 2;
} else {
return m / 3 + 1;
}
}
private static void shuffleArray(long[] arr) {
int n = arr.length;
Random rnd = new Random();
for (int i = 0; i < n; ++i) {
long tmp = arr[i];
int randomPos = i + rnd.nextInt(n - i);
arr[i] = arr[randomPos];
arr[randomPos] = tmp;
}
}
private static class ContestScanner {
private final java.io.InputStream in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int bufferLength = 0;
private static final long LONG_MAX_TENTHS = 922337203685477580L;
private static final int LONG_MAX_LAST_DIGIT = 7;
private static final int LONG_MIN_LAST_DIGIT = 8;
public ContestScanner(java.io.InputStream in) {
this.in = in;
}
public ContestScanner(java.io.File file) throws java.io.FileNotFoundException {
this(new java.io.BufferedInputStream(new java.io.FileInputStream(file)));
}
public ContestScanner() {
this(System.in);
}
private boolean hasNextByte() {
if (ptr < bufferLength) {
return true;
} else {
ptr = 0;
try {
bufferLength = in.read(buffer);
} catch (java.io.IOException e) {
e.printStackTrace();
}
if (bufferLength <= 0) {
return false;
}
}
return true;
}
private int readByte() {
if (hasNextByte()) return buffer[ptr++];
else return -1;
}
private static boolean isPrintableChar(int c) {
return 33 <= c && c <= 126;
}
public boolean hasNext() {
while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
return hasNextByte();
}
public String next() {
if (!hasNext()) throw new java.util.NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (!hasNext()) throw new java.util.NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while (true) {
if ('0' <= b && b <= '9') {
int digit = b - '0';
if (n >= LONG_MAX_TENTHS) {
if (n == LONG_MAX_TENTHS) {
if (minus) {
if (digit <= LONG_MIN_LAST_DIGIT) {
n = -n * 10 - digit;
b = readByte();
if (!isPrintableChar(b)) {
return n;
} else if (b < '0' || '9' < b) {
throw new NumberFormatException(
String.format("%d%s... is not number", n, Character.toString(b))
);
}
}
} else {
if (digit <= LONG_MAX_LAST_DIGIT) {
n = n * 10 + digit;
b = readByte();
if (!isPrintableChar(b)) {
return n;
} else if (b < '0' || '9' < b) {
throw new NumberFormatException(
String.format("%d%s... is not number", n, Character.toString(b))
);
}
}
}
}
throw new ArithmeticException(
String.format("%s%d%d... overflows long.", minus ? "-" : "", n, digit)
);
}
n = n * 10 + digit;
} else if (b == -1 || !isPrintableChar(b)) {
return minus ? -n : n;
} else {
throw new NumberFormatException();
}
b = readByte();
}
}
public int nextInt() {
long nl = nextLong();
if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
return (int) nl;
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long[] nextLongArray(int length) {
long[] array = new long[length];
for (int i = 0; i < length; i++) array[i] = this.nextLong();
return array;
}
public long[] nextLongArray(int length, java.util.function.LongUnaryOperator map) {
long[] array = new long[length];
for (int i = 0; i < length; i++) array[i] = map.applyAsLong(this.nextLong());
return array;
}
public int[] nextIntArray(int length) {
int[] array = new int[length];
for (int i = 0; i < length; i++) array[i] = this.nextInt();
return array;
}
public int[] nextIntArray(int length, java.util.function.IntUnaryOperator map) {
int[] array = new int[length];
for (int i = 0; i < length; i++) array[i] = map.applyAsInt(this.nextInt());
return array;
}
public double[] nextDoubleArray(int length) {
double[] array = new double[length];
for (int i = 0; i < length; i++) array[i] = this.nextDouble();
return array;
}
public double[] nextDoubleArray(int length, java.util.function.DoubleUnaryOperator map) {
double[] array = new double[length];
for (int i = 0; i < length; i++) array[i] = map.applyAsDouble(this.nextDouble());
return array;
}
public long[][] nextLongMatrix(int height, int width) {
long[][] mat = new long[height][width];
for (int h = 0; h < height; h++)
for (int w = 0; w < width; w++) {
mat[h][w] = this.nextLong();
}
return mat;
}
public int[][] nextIntMatrix(int height, int width) {
int[][] mat = new int[height][width];
for (int h = 0; h < height; h++)
for (int w = 0; w < width; w++) {
mat[h][w] = this.nextInt();
}
return mat;
}
public double[][] nextDoubleMatrix(int height, int width) {
double[][] mat = new double[height][width];
for (int h = 0; h < height; h++)
for (int w = 0; w < width; w++) {
mat[h][w] = this.nextDouble();
}
return mat;
}
public char[][] nextCharMatrix(int height, int width) {
char[][] mat = new char[height][width];
for (int h = 0; h < height; h++) {
String s = this.next();
for (int w = 0; w < width; w++) {
mat[h][w] = s.charAt(w);
}
}
return mat;
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | efcf0250bca7b8fec88945347fe62bad | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.Scanner;
/**
*
* @author eslam
*/
public class JavaApplication1025 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
while(t-->0){
int n = input.nextInt();
int m = input.nextInt();
int ans = n/3*m+((n%3)*(m/3));
if(n%3==1&&m%3==1){
ans++;
}else if(n%3==2&&m%3==2){
ans+=2;
}else if((n%3==1&&m%3==2)||(n%3==2&&m%3==1)){
ans++;
}
System.out.println(ans);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 9da79791713b628572d166f2f80fee7a | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
public class ColouringRectangle1584B {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int test=1;test<=t;test++)
{
int n=sc.nextInt();
int m=sc.nextInt();
int mf=0,nf=0;
if(m%3==0)
{
mf=(m/3)*n;
}
else
{
mf=(m/3)*n;
if(m%3==1)
{
mf=mf+(n/3)+1;
}
else
{
mf=mf+(n/3)*2;
if(n%3==2)mf=mf+2;
else
mf=mf+1;
}
}
if(n%3==0)
{
nf=(n/3)*m;
}
else
{
nf=((n/3))*m;
if(n%3==1)
{
nf=nf+(m/3)+1;
}
else
{
nf=nf+(m/3)*2;
if(m%3==2)nf=nf+2;
else
nf=nf+1;
}
}
if(mf<=0)
{
System.out.println(nf);
}
else if(nf<=0)
{
System.out.println(mf);
}
else
{
System.out.println(Math.min(mf, nf));
}
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 9b685d18809e6c0959046a4153d15152 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.util.*;
public class B_Coloring_Rectangles {
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0)
{
int n=sc.nextInt();
int m=sc.nextInt();
if(n%3==0){
System.out.println((n/3)*m);
}
else if(m%3==0){
System.out.println(n*(m/3));
}
// else if(n==m)
// {
// System.out.println(n);
// }
else{
int a=(int)Math.ceil((double)(n*m)/3);
System.out.println(a);
}
}
sc.close();
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 3ed8bd41a458b1df1986da6dfc95a828 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | // ceil using integer division: ceil(x/y) = (x+y-1)/y
import java.util.*;
import java.lang.*;
import java.io.*;
public class practice {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
BufferedWriter output = new BufferedWriter(
new OutputStreamWriter(System.out));
int t = Reader.nextInt();
while (t-- > 0) {
long n = Reader.nextLong();
long m = Reader.nextLong();
if(n==1 && m==1) {
System.out.println(0);
continue;
}
System.out.println(helper(n,m));
}
}
public static long helper(long n, long m){
if(n==1 && m==1) {
return 0;
}
else if(n==1){
if(m%3==0){
return m/3;
}
else{
return m/3 + 1;
}
}
else if(m==1){
if(n%3==0){
return n/3;
}
else{
return n/3 + 1;
}
}
long ans = Long.MAX_VALUE;
if(m%3==0){
ans = Math.min(ans,(m/3)*n);
}
else{
if(m%3==1){
ans = Math.min(ans,(m/3)*n+helper(1,n));
}
else{
ans = Math.min(ans,(m/3)*n+2*helper(1,n));
}
}
if(n%3==0){
ans = Math.min(ans,(n/3)*m);
}
else{
if(n%3==1){
ans = Math.min(ans,(n/3)*m+helper(1,m));
}
else{
ans = Math.min(ans,(n/3)*m+2*helper(1,m));
}
}
return ans;
}
}
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static String nextLine() throws IOException {
return reader.readLine();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static long nextLong() throws IOException{
return Long.parseLong(next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | d5093db1546cfbf2b726c5eca2034bb0 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.Scanner;
public class ColoringRectangles {
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 * m) % 3 == 0) {
System.out.println((m*n) / 3);
} else {
System.out.println(((m*n) / 3) + 1);
}
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | dcab5e37aaba6265a142f5c6c187dbb6 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import static java.lang.System.out;
import java.io.*;
import java.util.*;
public class B_Coloring_Rectangles
{
public static void main(String[] args)
{
FastScanner fs=new FastScanner();
// HashMap<Integer,Integer> mp=new HashMap<Integer,Integer>();
// for(int i=2;i<=3e4;i*=2) mp.put(i, 1);
int testCase=1;
testCase=fs.nextInt();
// int k=1;
for(int TT=0;TT<testCase;TT++)
{
int n,m;
n=fs.nextInt();
m=fs.nextInt();
int ans=n*m;
int res;
if(ans%3==0) res=ans/3;
else res=ans/3+1;
out.println(res);
// out.println("Case #" + k + ": ");
// k++;
}
}
static void sort(int[] a)
{
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
private char NC = (char) 0;
private char c = NC;
private double cnt = 1;
String next()
{
while (!st.hasMoreTokens())
try
{
st=new StringTokenizer(br.readLine());
} catch (IOException e)
{
e.printStackTrace();
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
int[] readArray(int n)
{
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong()
{
return Long.parseLong(next());
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public double[] nextDoubles(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
}
public static void print(int[] arr)
{
//for debugging only
for(int x: arr)
out.print(x+" ");
out.println();
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | c525e656acdcbf2f25474afcbe2436f4 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
import java.io.*;
public class Hello {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int t = in.nextInt();
for (int tt = 0; tt < t; tt++) {
int a = in.nextInt(), b = in.nextInt();
int area= a*b;
if(area % 3 == 0){
pw.println(area/3);
}
else{
int ans = area/3;
pw.println(ans+1);
}
}
pw.close();
}
static void debug(Object... obj) {
System.err.println(Arrays.deepToString(obj));
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | d3891f9cf9effcdb9c642e06f3b42525 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 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 B_Coloring_Rectangles {
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*m+2)/3);
// int ans = (m/3)*n;
// if(m%3 == 1) {
// ans += n/3;
// if(n%3 != 0) {
// ans++;
// }
// } else if(m%3 == 2) {
// ans += (n/3)*2;
// if(n%3 == 1) {
// ans++;
// } else if(n%3 == 2) {
// ans += 2;
// }
// }
// out.println(ans);
}
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);
}
}
public static void allDivisors(int n) {
for(int i = 1; i*i <= n; i++) {
if(n%i == 0) {
System.out.println(i + " ");
if(i != n/i) {
System.out.println(n/i + " ");
}
}
}
}
public static boolean isPrime(int n) {
if(n < 1) return false;
if(n == 2 || n == 3) return true;
if(n % 2 == 0 || n % 3 == 0) return false;
for(int i = 5; i*i <= n; i += 6) {
if(n % i == 0 || n % (i+2) == 0) {
return false;
}
}
return true;
}
public static int gcd(int a, int b) {
int dividend = a > b ? a : b;
int divisor = a < b ? a : b;
while(divisor > 0) {
int reminder = dividend % divisor;
dividend = divisor;
divisor = reminder;
}
return dividend;
}
public static int lcm(int a, int b) {
int lcm = gcd(a, b);
int hcf = (a * b) / lcm;
return hcf;
}
public static String sortString(String inputString) {
char tempArray[] = inputString.toCharArray();
Arrays.sort(tempArray);
return new String(tempArray);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
float nextFloat() {
return Float.parseFloat(next());
}
boolean nextBoolean() {
return Boolean.parseBoolean(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
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
*/
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 718b436bad5d92a02093f41628f2ed63 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 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 B_Coloring_Rectangles {
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();
int ans = (m/3)*n;
if(m%3 == 1) {
ans += n/3;
if(n%3 != 0) {
ans++;
}
} else if(m%3 == 2) {
ans += (n/3)*2;
if(n%3 == 1) {
ans++;
} else if(n%3 == 2) {
ans += 2;
}
}
out.println(ans);
}
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);
}
}
public static void allDivisors(int n) {
for(int i = 1; i*i <= n; i++) {
if(n%i == 0) {
System.out.println(i + " ");
if(i != n/i) {
System.out.println(n/i + " ");
}
}
}
}
public static boolean isPrime(int n) {
if(n < 1) return false;
if(n == 2 || n == 3) return true;
if(n % 2 == 0 || n % 3 == 0) return false;
for(int i = 5; i*i <= n; i += 6) {
if(n % i == 0 || n % (i+2) == 0) {
return false;
}
}
return true;
}
public static int gcd(int a, int b) {
int dividend = a > b ? a : b;
int divisor = a < b ? a : b;
while(divisor > 0) {
int reminder = dividend % divisor;
dividend = divisor;
divisor = reminder;
}
return dividend;
}
public static int lcm(int a, int b) {
int lcm = gcd(a, b);
int hcf = (a * b) / lcm;
return hcf;
}
public static String sortString(String inputString) {
char tempArray[] = inputString.toCharArray();
Arrays.sort(tempArray);
return new String(tempArray);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
float nextFloat() {
return Float.parseFloat(next());
}
boolean nextBoolean() {
return Boolean.parseBoolean(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
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
*/
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | e8954f370fe6543005701e3028eb6b1b | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | /*LoudSilence*/
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Solution {
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
static FastScanner s = new FastScanner();
static FastWriter out = new FastWriter();
final static int mod = (int)1e9 + 7;
final static int INT_MAX = Integer.MAX_VALUE;
final static int INT_MIN = Integer.MIN_VALUE;
final static long LONG_MAX = Long.MAX_VALUE;
final static long LONG_MIN = Long.MIN_VALUE;
final static double DOUBLE_MAX = Double.MAX_VALUE;
final static double DOUBLE_MIN = Double.MIN_VALUE;
final static float FLOAT_MAX = Float.MAX_VALUE;
final static float FLOAT_MIN = Float.MIN_VALUE;
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
static class FastScanner{BufferedReader br;StringTokenizer st;
public FastScanner() {br = new BufferedReader(new InputStreamReader(System.in));}
String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException e){e.printStackTrace();}}return st.nextToken();}
int nextInt(){return Integer.parseInt(next());}
long nextLong(){return Long.parseLong(next());}
double nextDouble(){return Double.parseDouble(next());}
List<Integer> readIntList(int n){List<Integer> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextInt()); return arr;}
List<Long> readLongList(int n){List<Long> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextLong()); return arr;}
int[] readIntArr(int n){int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = s.nextInt(); return arr;}
long[] readLongArr(int n){long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = s.nextLong(); return arr;}
String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}}
static class FastWriter{private 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 debug(int object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");}
public void debug(long object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");}
public void close() throws IOException{bw.close();}}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
public static ArrayList<Integer> seive(int n){ArrayList<Integer> list = new ArrayList<>();int arr[] = new int[n+1];for(int i = 2; i <= n; i++) {if(arr[i] == 1) {continue;}else {list.add(i);for(int j = i*i; j <= n; j = j + i) {arr[j] = 1;}}}return list;}
public static long gcd(long a, long b){if(a > b) {a = (a+b)-(b=a);}if(a == 0L){return b;}return gcd(b%a, a);}
public static void swap(int[] arr, int i, int j) {arr[i] = arr[i] ^ arr[j]; arr[j] = arr[j] ^ arr[i]; arr[i] = arr[i] ^ arr[j];}
public static boolean isPrime(long n){if(n < 2){return false;}if(n == 2 || n == 3){return true;}if(n%2 == 0 || n%3 == 0){return false;}long sqrtN = (long)Math.sqrt(n)+1;for(long i = 6L; i <= sqrtN; i += 6) {if(n%(i-1) == 0 || n%(i+1) == 0) return false;}return true;}
public static long mod_add(long a, long b){ return (a%mod + b%mod)%mod;}
public static long mod_sub(long a, long b){ return (a%mod - b%mod + mod)%mod;}
public static long mod_mul(long a, long b){ return (a%mod * b%mod)%mod;}
public static long modInv(long a, long b){ return expo(a, b-2)%b;}
public static long mod_div(long a, long b){return mod_mul(a, modInv(b, mod));}
public static long expo (long a, long n){if(n == 0){return 1;}long recAns = expo(mod_mul(a,a), n/2);if(n % 2 == 0){return recAns;}else{return mod_mul(a, recAns);}}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
// Pair class
public static class Pair<X extends Comparable<X>,Y extends Comparable<Y>> implements Comparable<Pair<X, Y>>{
X first;
Y second;
public Pair(X first, Y second){
this.first = first;
this.second = second;
}
public String toString(){
return "( " + first+" , "+second+" )";
}
@Override
public int compareTo(Pair<X, Y> o) {
int t = first.compareTo(o.first);
if(t == 0) return second.compareTo(o.second);
return t;
}
}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
// Code begins
public static void solve(int test) throws IOException {
int n = s.nextInt();
int m = s.nextInt();
if(m >= 3){
if(m == 3){
System.out.println(n);
}else{
int ans = m/3 * n;
m = m - ((m/3) * 3);
if(n >= 3){
if(n == 3){
System.out.println(m + ans);
}else{
ans += n/3 * m;
n = n - ((n/3) * 3);
if(n*m == 4){
ans += 2;
}else if(n*m == 1 || n*m == 2){
ans++;
}
System.out.println(ans);
}
}else{
if(n*m == 4){
ans+=2;
}else if(n*m == 1 || n*m == 2){
ans+=1;
}
System.out.println(ans);
}
}
}else{
int ans = 0;
if(n >= 3){
if(n == 3){
System.out.println(m + ans);
}else{
ans += n/3 * m;
n = n - ((n/3) * 3);
if(n*m == 4){
ans += 2;
}else if(n*m == 1 || n*m == 2){
ans++;
}
System.out.println(ans);
}
}else{
if(n*m == 4){
System.out.println(2);
}else{
System.out.println(1);
}
}
}
}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
public static void main(String[] args) throws IOException {
int test = s.nextInt();
for(int tt = 1; tt <= test; tt++) {
solve(tt);
}
out.close();
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 6ae5fd653b31e7b34e8a2cd174c0b350 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.max;
import static java.lang.System.exit;
import static java.util.Arrays.fill;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class cf {
static long mod = (long) (1e9 + 7);
static void solve() throws Exception {
int tests = scanInt();
// int tests = 1;
for (int test = 0; test < tests; test++) {
// int n = scanInt(), k = scanInt();
// String l = scanString();
// out.println();
// continue test;
int n = scanInt();
int m = scanInt();
int val = n * m;
if(val % 3 != 0){
val = val/3 + 1;
out.println(val);
}
else{
out.println(val/3);
}
}
}
static class pair {
long x, y;
pair(long ar, long ar2) {
x = ar;
y = ar2;
}
}
static class pairChar {
Character key;
int val;
pairChar(Character key, int val) {
this.key = key;
this.val = val;
}
}
static int[] arrI(int N) throws Exception {
int A[] = new int[N];
for (int i = 0; i < N; i++) {
A[i] = scanInt();
}
return A;
}
static long[] arrL(int N) throws Exception {
long A[] = new long[N];
for (int i = 0; i < A.length; i++)
A[i] = scanLong();
return A;
}
static void sort(long[] a) // check for long
{
ArrayList<Long> l = new ArrayList<>();
for (long i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static void sortReverse(long[] a) // check for long
{
ArrayList<Long> l = new ArrayList<>();
for (long i : a)
l.add(i);
Collections.sort(l);
int n = a.length;
for (int i = 0; i < n; i++)
a[n - i - 1] = l.get(i);
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static void sortReverse(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a)
l.add(i);
Collections.sort(l);
int n = a.length;
for (int i = 0; i < n; i++)
a[n - i - 1] = l.get(i);
}
public static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
static class DescendingComparator implements Comparator<Integer> {
public int compare(Integer a, Integer b) {
return b - a;
}
}
static class AscendingComparator implements Comparator<Integer> {
public int compare(Integer a, Integer b) {
return a - b;
}
}
static boolean isPalindrome(char X[]) {
int l = 0, r = X.length - 1;
while (l <= r) {
if (X[l] != X[r])
return false;
l++;
r--;
}
return true;
}
static long fact(long N) {
long num = 1L;
while (N >= 1) {
num = ((num % mod) * (N % mod)) % mod;
N--;
}
return num;
}
static long pow(long a, long b) {
long mod = 1000000007;
long pow = 1;
long x = a;
while (b != 0) {
if ((b & 1) != 0)
pow = (pow * x) % mod;
x = (x * x) % mod;
b /= 2;
}
return pow;
}
static long toggleBits(long x)// one's complement || Toggle bits
{
int n = (int) (Math.floor(Math.log(x) / Math.log(2))) + 1;
return ((1 << n) - 1) ^ x;
}
static int countBits(long a) {
return (int) (Math.log(a) / Math.log(2) + 1);
}
static boolean isPrime(long N) {
if (N <= 1)
return false;
if (N <= 3)
return true;
if (N % 2 == 0 || N % 3 == 0)
return false;
for (int i = 5; i * i <= N; i = i + 6)
if (N % i == 0 || N % (i + 2) == 0)
return false;
return true;
}
static long GCD(long a, long b) {
if (b == 0) {
return a;
} else
return GCD(b, a % b);
}
static HashMap<Integer, Integer> getHashMap(int A[]) {
HashMap<Integer, Integer> mp = new HashMap<>();
for (int a : A) {
int f = mp.getOrDefault(a, 0) + 1;
mp.put(a, f);
}
return mp;
}
public static Map<Character, Integer> mapSortByValue(Map<Character, Integer> hm) {
// Create a list from elements of HashMap
List<Map.Entry<Character, Integer>> list = new LinkedList<Map.Entry<Character, Integer>>(hm.entrySet());
// Sort the list
Collections.sort(list, new Comparator<Map.Entry<Character, Integer>>() {
public int compare(Map.Entry<Character, Integer> o1, Map.Entry<Character, Integer> o2) {
return o1.getValue() - o2.getValue();
}
});
// put data from sorted list to hashmap
Map<Character, Integer> temp = new LinkedHashMap<Character, Integer>();
for (Map.Entry<Character, Integer> aa : list) {
temp.put(aa.getKey(), aa.getValue());
}
return temp;
}
public static Map<Integer, Integer> mapSortByValueInt(Map<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() - o2.getValue();
}
});
// put data from sorted list to hashmap
Map<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> aa : list) {
temp.put(aa.getKey(), aa.getValue());
}
return temp;
}
public static Map<Integer, Integer> mapSortByValueRev(Map<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 o2.getValue() - o1.getValue();
}
});
// put data from sorted list to hashmap
Map<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> aa : list) {
temp.put(aa.getKey(), aa.getValue());
}
return temp;
}
public static Map<Character, Integer> mapSortByKey(Map<Character, Integer> hm) {
// Create a list from elements of HashMap
List<Map.Entry<Character, Integer>> list = new LinkedList<Map.Entry<Character, Integer>>(hm.entrySet());
// Sort the list
Collections.sort(list, new Comparator<Map.Entry<Character, Integer>>() {
public int compare(Map.Entry<Character, Integer> o1, Map.Entry<Character, Integer> o2) {
return o1.getKey() - o2.getKey();
}
});
// put data from sorted list to hashmap
Map<Character, Integer> temp = new LinkedHashMap<Character, Integer>();
for (Map.Entry<Character, Integer> aa : list) {
temp.put(aa.getKey(), aa.getValue());
}
return temp;
}
static int scanInt() throws IOException {
return parseInt(scanString());
}
static long scanLong() throws IOException {
return parseLong(scanString());
}
static String scanString() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
static BufferedReader in;
static PrintWriter out;
static StringTokenizer tok;
public static void main(String[] args) {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
in.close();
out.close();
} catch (Throwable e) {
e.printStackTrace();
exit(1);
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | f900c362c065aae092e12c5b8a62bcee | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution{
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
static StringTokenizer st;
static final long mod=1000000007;
public static void Solve() throws IOException{
st=new StringTokenizer(br.readLine());
int n=Integer.parseInt(st.nextToken()),m=Integer.parseInt(st.nextToken());
int ans=(n*m)/3;
if((n*m)%3!=0) ans++;
if(n*m==2) ans=1;
bw.write(ans+"\n");
}
/** Main Method**/
public static void main(String[] YDSV) throws IOException{
//int t=1;
int t=Integer.parseInt(br.readLine());
while(t-->0) Solve();
bw.flush();
}
/** Helpers**/
private static char[] getStr()throws IOException{
return br.readLine().toCharArray();
}
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[] getArrIn(int n) throws IOException{
st=new StringTokenizer(br.readLine());
int[] ar=new int[n];
for(int i=0;i<n;i++) ar[i]=Integer.parseInt(st.nextToken());
return ar;
}
private static long[] getArrLo(int n) throws IOException{
st=new StringTokenizer(br.readLine());
long[] ar=new long[n];
for(int i=0;i<n;i++) ar[i]=Long.parseLong(st.nextToken());
return ar;
}
private static List<Integer> getListIn(int n) throws IOException{
st=new StringTokenizer(br.readLine());
List<Integer> al=new ArrayList<>();
for(int i=0;i<n;i++) al.add(Integer.parseInt(st.nextToken()));
return al;
}
private static List<Long> getListLo(int n) throws IOException{
st=new StringTokenizer(br.readLine());
List<Long> al=new ArrayList<>();
for(int i=0;i<n;i++) al.add(Long.parseLong(st.nextToken()));
return al;
}
private static long pow_mod(long a,long b) {
long result=1;
while(b!=0){
if((b&1)!=0) result=(result*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return result;
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 6f49d2624adb5c2f90763c3ff9adeffa | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static Kattio io;
static long mod = 998244353, inv2 = 499122177;
static {
io = new Kattio();
}
public static void main(String[] args) throws IOException {
int t = io.nextInt();
for (int i = 0; i < t; i++) {
solve();
}
io.close();
}
private static void solve() {
int r = io.nextInt(), c = io.nextInt(), min = Integer.MAX_VALUE;
if(r>1) {
min = (r / 2) * c;
}
if(c>1) {
min = Math.min(min, (c / 2) * r);
}
io.println((int)Math.ceil(((double) r*c)/ (double)3));
}
static class pair implements Comparable<pair> {
private final int x;
private final int y;
int ind=0;
public pair(final int x, final int y) {
this.x = x;
this.y = y;
}
public pair(final int x, final int y, int w) {
this.x = x;
this.y = y;
ind = w;
}
@Override
public String toString() {
return "pair{" +
"x=" + x +
", y=" + y +
'}';
}
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof pair)) {
return false;
}
final pair pair = (pair) o;
if (x != pair.x) {
return false;
}
return y == pair.y;
}
@Override
public int hashCode() {
int result = x;
result = (int) (31 * result + y);
return result;
}
@Override
public int compareTo(pair pair) {
if(this.y==pair.y){
return Integer.compare(this.x, pair.x);
}
return Integer.compare(this.y, pair.y);
}
}
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());
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 1cfab349d51d57fa7ac87d6d2c2b1453 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 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();
for (int tc = 0; tc < t; ++tc) {
int n = sc.nextInt();
int m = sc.nextInt();
System.out.println(solve(n, m));
}
sc.close();
}
static int solve(int n, int m) {
return (n * m + 2) / 3;
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | e25eeecb77c565be3fcd0761fd780fe7 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.Scanner;
public class B1584 {
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
long testCases;
testCases = sc.nextLong();
for (int i = 0; i < testCases; i++) {
long n = sc.nextLong();
long m = sc.nextLong();
if ((m * n) % 3 == 0) System.out.println((m * n) / 3);
else System.out.println((m * n) / 3 + 1);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 5e50c2cfa33a6f73ad86220cdad5f524 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 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
{
static class Pair
{
int i;
int j;
Pair(int i,int j)
{
this.i=i;
this.j=j;
}
}
public static void reverse(int arr[],int i,int j)
{
while(i<j)
{
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
i++;
j--;
}
}
public static int rowwise(int n,int k)
{
int mod=n%3;
n/=3;
int ans=k*n;
int q=mod*((int)Math.ceil(k/3.0));
ans+=q;
return ans;
}
public static int colwise(int n,int k)
{
int mod=k%3;
k/=3;
int ans=n*k;
int q=mod*((int)Math.ceil(n/3.0));
ans+=q;
return ans;
}
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 k=sc.nextInt();
int ans1=rowwise(n,k);
int ans2=colwise(n,k);
System.out.println(Math.min(ans1,ans2));}}} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 93b983d1f0836efe69cd226506fce1e3 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Solution {
public static void main(String... args) throws Exception {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while (t-- > 0) {
solve(scan);
}
}
public static void solve(Scanner scan) {
int a = scan.nextInt();
int b = scan.nextInt();
long ans= (1l*a*b+2)/3;
System.out.println(ans);
}
// static void shuffleArray(int[] arr) {
// int n = arr.length;
// Random rnd = new Random();
// for (int i = 0; i < n; ++i) {
// int tmp = arr[i];
// int randomPos = i + rnd.nextInt(n - i);
// arr[i] = arr[randomPos];
// arr[randomPos] = tmp;
// }
// }
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | c689bdbc4e5faa1d5ec92f0f47faecf6 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.util.*;
public class Checking {
static FastScanner fs;
static FastWriter fw;
static boolean checkOnlineJudge = System.getProperty("ONLINE_JUDGE") == null;
private static final int[][] kdir = new int[][]{{-1, 2}, {-2, 1}, {-2, -1}, {-1, -2}, {1, -2}, {2, -1}, {2, 1}, {1, 2}};
private static final int[][] dir = new int[][]{{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
private static final int iMax = (int) (1e9 + 100), iMin = (int) (-1e9 - 100);
private static final long lMax = (long) (1e18 + 100), lMin = (long) (-1e18 - 100);
private static final int mod1 = (int) (1e9 + 7);
private static final int mod2 = 998244353;
public static void main(String[] args) throws IOException {
fs = new FastScanner();
fw = new FastWriter();
int t = 1;
t = fs.nextInt();
while (t-- > 0) {
solve();
}
fw.out.close();
}
private static void solve() {
int n = fs.nextInt();
int m = fs.nextInt();
if((n*m) % 3 == 0){
fw.out.println((n*m) /3);
}else{
fw.out.println((n*m)/3 + 1);
}
}
private static class UnionFind {
private final int[] parent;
private final int[] rank;
UnionFind(int n) {
parent = new int[n + 5];
rank = new int[n + 5];
for (int i = 0; i <= n; i++) {
parent[i] = i;
rank[i] = 0;
}
}
private int find(int i) {
if (parent[i] == i)
return i;
return parent[i] = find(parent[i]);
}
private void union(int a, int b) {
a = find(a);
b = find(b);
if (a != b) {
if (rank[a] < rank[b]) {
int temp = a;
a = b;
b = temp;
}
parent[b] = a;
if (rank[a] == rank[b])
rank[a]++;
}
}
}
// private static class Calc_nCr {
// private final long[] fact;
// private final long[] invfact;
// private final int p;
//
// Calc_nCr(int n, int prime) {
// fact = new long[n + 5];
// invfact = new long[n + 5];
// p = prime;
//
// fact[0] = 1;
// for (int i = 1; i <= n; i++) {
// fact[i] = (i * fact[i - 1]) ;
// }
//
// invfact[n] = pow(fact[n], p - 2);
// for (int i = n - 1; i >= 0; i--) {
// invfact[i] = (invfact[i + 1] * (i + 1)) ;
// }
// }
//
// private long nCr(int n, int r) {
// if (r > n || n < 0 || r < 0) return 0;
// return (((fact[n] * invfact[r]) % p) * invfact[n - r]) % p;
// }
// }
private static long gcd(long a, long b) {
return (b == 0 ? a : gcd(b, a % b));
}
private static long lcm(long a, long b) {
return ((a * b) / gcd(a, b));
}
private static long pow(long a, long b) {
long result = 1;
while (b > 0) {
if ((b & 1L) == 1) {
result = (result * a) ;
}
a = (a * a) ;
b >>= 1;
}
return result;
}
private static long ceilDiv(long a, long b) {
return ((a + b - 1) / b);
}
private static long getMin(long... args) {
long min = lMax;
for (long arg : args)
min = Math.min(min, arg);
return min;
}
private static long getMax(long... args) {
long max = lMin;
for (long arg : args)
max = Math.max(max, arg);
return max;
}
private static boolean isPalindrome(String s, int l, int r) {
int i = l, j = r;
while (j - i >= 1) {
if (s.charAt(i) != s.charAt(j))
return false;
i++;
j--;
}
return true;
}
private static List<Integer> primes(int n) {
boolean[] primeArr = new boolean[n + 5];
Arrays.fill(primeArr, true);
for (int i = 2; (i * i) <= n; i++) {
if (primeArr[i]) {
for (int j = i * i; j <= n; j += i) {
primeArr[j] = false;
}
}
}
List<Integer> primeList = new ArrayList<>();
for (int i = 2; i <= n; i++) {
if (primeArr[i])
primeList.add(i);
}
return primeList;
}
private static int noOfSetBits(long x) {
int cnt = 0;
while (x != 0) {
x = x & (x - 1);
cnt++;
}
return cnt;
}
private static boolean isPerfectSquare(long num) {
long sqrt = (long) Math.sqrt(num);
return ((sqrt * sqrt) == num);
}
private static class Pair<U, V> {
private final U first;
private final V second;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair<?, ?> pair = (Pair<?, ?>) o;
return first.equals(pair.first) && second.equals(pair.second);
}
@Override
public int hashCode() {
return Objects.hash(first, second);
}
@Override
public String toString() {
return "(" + first + ", " + second + ")";
}
private Pair(U ff, V ss) {
this.first = ff;
this.second = ss;
}
}
private static void randomizeIntArr(int[] arr, int n) {
Random r = new Random();
for (int i = (n - 1); i > 0; i--) {
int j = r.nextInt(i + 1);
swapInIntArr(arr, i, j);
}
}
private static void randomizeLongArr(long[] arr, int n) {
Random r = new Random();
for (int i = (n - 1); i > 0; i--) {
int j = r.nextInt(i + 1);
swapInLongArr(arr, i, j);
}
}
private static void swapInIntArr(int[] arr, int a, int b) {
int temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
private static void swapInLongArr(long[] arr, int a, int b) {
long temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
private static int[] readIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = fs.nextInt();
return arr;
}
private static long[] readLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++)
arr[i] = fs.nextLong();
return arr;
}
private static List<Integer> readIntList(int n) {
List<Integer> list = new ArrayList<>();
for (int i = 0; i < n; i++)
list.add(fs.nextInt());
return list;
}
private static List<Long> readLongList(int n) {
List<Long> list = new ArrayList<>();
for (int i = 0; i < n; i++)
list.add(fs.nextLong());
return list;
}
private static class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner() throws IOException {
if (checkOnlineJudge)
this.br = new BufferedReader(new FileReader("src/input.txt"));
else
this.br = new BufferedReader(new InputStreamReader(System.in));
this.st = new StringTokenizer("");
}
public String next() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException err) {
err.printStackTrace();
}
}
return st.nextToken();
}
public String nextLine() {
if (st.hasMoreTokens()) {
return st.nextToken("").trim();
}
try {
return br.readLine().trim();
} catch (IOException err) {
err.printStackTrace();
}
return "";
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
private static class FastWriter {
PrintWriter out;
FastWriter() throws IOException {
if (checkOnlineJudge)
out = new PrintWriter(new FileWriter("src/output.txt"));
else
out = new PrintWriter(System.out);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 55c05caba9428f1309a434f8134f6271 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class coloringRectangles {
public static void main(String[] args) throws IOException {
Reader r = new Reader();
int t = r.nextInt();
int[] answers = new int[t];
int min1, min2;
int n, m;
for (int i = 0; i < t; i++) {
n = r.nextInt();
m = r.nextInt();
answers[i] = (int)Math.ceil((n * m) / 3.0);
}
for (int i : answers) {
System.out.println(i);
}
}
static class Reader {
String filename;
BufferedReader br;
StringTokenizer st;
PrintWriter out;
boolean fileOut = false;
public Reader() {
this.br = new BufferedReader(new InputStreamReader(System.in));
}
public Reader(String name) throws IOException {
this.filename = name;
this.br = new BufferedReader(new FileReader(this.filename + ".in"));
this.out = new PrintWriter(new BufferedWriter(new FileWriter(this.filename + ".out")));
this.fileOut = true;
}
public String next() throws IOException {
while(this.st == null || !this.st.hasMoreTokens()) {
try {
this.st = new StringTokenizer(this.br.readLine());
} catch (Exception var2) {
}
}
return this.st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(this.next());
}
public void println(Object text) {
if (this.fileOut) {
this.out.println(text);
} else {
System.out.println(text);
}
}
public void close() {
if (this.fileOut) {
this.out.close();
}
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 46b209048f5c9a026128d61270d2f6e7 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
import java.io.*;
public class practice {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new PrintWriter(System.out)));
StringBuilder sb = new StringBuilder();
int t = Integer.parseInt(br.readLine());
while (t --> 0) {
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
sb.append((int) Math.ceil(n * m / 3.0) + "\n");
}
pw.println(sb.toString().trim());
pw.close();
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | f858151e722fab8ac5d790cefcdb7317 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
FastReader sc = new FastReader();
PrintWriter writer = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
int m = n*sc.nextInt();
int ans = m/3;
if(m%3==1 || m%3 == 2)ans++;
writer.println(ans);
}
writer.flush();
writer.close();
}
private static long power (long a, long n, long p) {
long res = 1;
while(n!=0) {
if(n%2==1) {
res=(res*a)%p;
n--;
}else {
a= (a*a)%p;
n/=2;
}
}
return res;
}
private static boolean isPrime(int c) {
for (int i = 2; i*i <= c; i++) {
if(c%i==0)return false;
}
return true;
}
private static int find(int a , int arr[]) {
if(arr[a] != a) return arr[a] = find(arr[a], arr);
return arr[a];
}
private static void union(int a, int b, int arr[]) {
int aa = find(a,arr);
int bb = find(b, arr);
arr[aa] = bb;
}
private static int gcd(int a, int b) {
if(a==0)return b;
return gcd(b%a, a);
}
public static int[] readIntArray(int size, FastReader s) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = s.nextInt();
}
return array;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
class Pair implements Comparable<Pair>{
int a;
int b;
Pair(int a, int b){
this.a = a;
this.b = b;
}
@Override
public boolean equals(Object obj) {
if(this == obj) return true;
if(obj == null || obj.getClass()!= this.getClass()) return false;
Pair pair = (Pair) obj;
return (pair.a == this.a && pair.b == this.b);
}
@Override
public int hashCode()
{
return Objects.hash(a,b);
}
@Override
public int compareTo(Pair o) {
if(this.a == o.a) {
return Integer.compare(this.b, o.b);
}else {
return Integer.compare(this.a, o.a);
}
}
@Override
public String toString() {
return this.a + " " + this.b;
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 49193188df1a53a01739f028ccda373e | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.lang.Math;
import java.lang.reflect.Array;
import java.util.*;
import javax.swing.text.DefaultStyledDocument.ElementSpec;
public final class Solution {
static BufferedReader br = new BufferedReader(
new InputStreamReader(System.in)
);
static BufferedWriter bw = new BufferedWriter(
new OutputStreamWriter(System.out)
);
static StringTokenizer st;
/*write your constructor and global variables here*/
static class sortCond implements Comparator<Pair<Integer, Integer>> {
@Override
public int compare(Pair<Integer, Integer> p1, Pair<Integer, Integer> p2) {
if (p1.a <= p2.a) {
return -1;
} else {
return 1;
}
}
}
static class Rec {
int a;
int b;
long c;
Rec(int a, int b, long c) {
this.a = a;
this.b = b;
this.c = c;
}
}
static class Pair<f, s> {
f a;
s b;
Pair(f a, s b) {
this.a = a;
this.b = b;
}
}
interface modOperations {
int mod(int a, int b, int mod);
}
static int findBinaryExponentian(int a, int pow, int mod) {
if (pow == 1) {
return a;
} else if (pow == 0) {
return 1;
} else {
int retVal = findBinaryExponentian(a, (int) pow / 2, mod);
int val = (pow % 2 == 0) ? 1 : a;
return modMul.mod(modMul.mod(retVal, retVal, mod), val, mod);
}
}
static int findPow(int a, int b, int mod) {
if (b == 1) {
return a % mod;
} else if (b == 0) {
return 1;
} else {
int res = findPow(a, (int) b / 2, mod);
return modMul.mod(res, modMul.mod(res, (b % 2 == 1 ? a : 1), mod), mod);
}
}
static int bleft(long ele, ArrayList<Long> sortedArr) {
int l = 0;
int h = sortedArr.size() - 1;
int ans = -1;
while (l <= h) {
int mid = l + (int) (h - l) / 2;
if (sortedArr.get(mid) < ele) {
l = mid + 1;
} else if (sortedArr.get(mid) >= ele) {
ans = mid;
h = mid - 1;
}
}
return ans;
}
static long gcd(long a, long b) {
long div = b;
long rem = a % b;
while (rem != 0) {
long temp = rem;
rem = div % rem;
div = temp;
}
return div;
}
static long[] log(long no, long n) {
long i = 1l;
long cnt = 0l;
while (i < no) {
i *= 2l;
cnt++;
}
long arr[] = new long[2];
arr[0] = cnt;
arr[1] = i;
return arr;
}
static int log1(int no) {
int i = 0;
while ((1 << i) < no) {
i++;
}
return (1 << i) == no ? (1 << i) : (1 << (i - 1));
}
static modOperations modAdd = (int a, int b, int mod) -> {
return (a % mod + b % mod) % mod;
};
static modOperations modSub = (int a, int b, int mod) -> {
return (int) ((1l * a % mod - 1l * b % mod + 1l * mod) % mod);
};
static modOperations modMul = (int a, int b, int mod) -> {
return (int) ((1l * (a % mod) * 1l * (b % mod)) % (1l * mod));
};
static modOperations modDiv = (int a, int b, int mod) -> {
return modMul.mod(a, findBinaryExponentian(b, mod - 1, mod), mod);
};
static HashSet<Integer> primeList(int MAXI) {
int[] prime = new int[MAXI + 1];
HashSet<Integer> obj = new HashSet<>();
for (int i = 2; i <= (int) Math.sqrt(MAXI) + 1; i++) {
if (prime[i] == 0) {
obj.add(i);
for (int j = i * i; j <= MAXI; j += i) {
prime[j] = 1;
}
}
}
for (int i = (int) Math.sqrt(MAXI) + 1; i <= MAXI; i++) {
if (prime[i] == 0) {
obj.add(i);
}
}
return obj;
}
static int[] factorialList(int MAXI, int mod) {
int[] factorial = new int[MAXI + 1];
factorial[2] = 1;
for (int i = 3; i < MAXI + 1; i++) {
factorial[i] = modMul.mod(factorial[i - 1], i, mod);
}
return factorial;
}
static void put(HashMap<Integer, Integer> cnt, int key) {
if (cnt.containsKey(key)) {
cnt.replace(key, cnt.get(key) + 1);
} else {
cnt.put(key, 1);
}
}
static long arrSum(ArrayList<Long> arr) {
long tot = 0;
for (int i = 0; i < arr.size(); i++) {
tot += arr.get(i);
}
return tot;
}
static int ord(char b) {
return (int) b - (int) 'a';
}
static int optimSearch(int[] cnt, int lower_bound, int pow, int n) {
int l = lower_bound + 1;
int h = n;
int ans = 0;
while (l <= h) {
int mid = l + (h - l) / 2;
if (cnt[mid] - cnt[lower_bound] == pow) {
return mid;
} else if (cnt[mid] - cnt[lower_bound] < pow) {
ans = mid;
l = mid + 1;
} else {
h = mid - 1;
}
}
return ans;
}
static Pair<Long, Integer> ret_ans(ArrayList<Integer> ans) {
int size = ans.size();
int mini = 1000000000 + 1;
long tit = 0l;
for (int i = 0; i < size; i++) {
tit += 1l * ans.get(i);
mini = Math.min(mini, ans.get(i));
}
return new Pair<>(tit - mini, mini);
}
static int factorList(
HashMap<Integer, Integer> maps,
int no,
int maxK,
int req
) {
int i = 1;
while (i * i <= no) {
if (no % i == 0) {
if (i != no / i) {
put(maps, no / i);
}
put(maps, i);
if (maps.get(i) == req) {
maxK = Math.max(maxK, i);
}
if (maps.get(no / i) == req) {
maxK = Math.max(maxK, no / i);
}
}
i++;
}
return maxK;
}
static ArrayList<Integer> getKeys(HashMap<Integer, Integer> maps) {
ArrayList<Integer> vals = new ArrayList<>();
for (Map.Entry<Integer, Integer> map : maps.entrySet()) {
vals.add(map.getKey());
}
return vals;
}
static ArrayList<Integer> getValues(HashMap<Integer, Integer> maps) {
ArrayList<Integer> vals = new ArrayList<>();
for (Map.Entry<Integer, Integer> map : maps.entrySet()) {
vals.add(map.getValue());
}
return vals;
}
/*write your methods here*/
static int getMax(ArrayList<Integer> arr) {
int max = arr.get(0);
for (int i = 1; i < arr.size(); i++) {
if (arr.get(i) > max) {
max = arr.get(i);
}
}
return max;
}
static int getMin(ArrayList<Integer> arr) {
int max = arr.get(0);
for (int i = 1; i < arr.size(); i++) {
if (arr.get(i) < max) {
max = arr.get(i);
}
}
return max;
}
public static void main(String[] args) throws IOException {
int cases = Integer.parseInt(br.readLine()), n, m, i, j;
while (cases-- != 0) {
st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
int val = ((int) n / 3) * 3;
int val1 = ((int) m / 3) * 3;
int tot1 = (val1 / 3) * n;
if (m % 3 == 2) {
tot1 += Math.min(2 * ((int) (n / 3) + (n % 3 == 0 ? 0 : 1)), n);
} else if (m % 3 == 1) {
tot1 += Math.min(((int) (n / 3) + (n % 3 == 0 ? 0 : 1)), n);
}
int tot2 = (val / 3) * m;
if (n % 3 == 2) {
tot2 += Math.min(2 * ((int) (m / 3) + (m % 3 == 0 ? 0 : 1)), m);
} else if (n % 3 == 1) {
tot2 += Math.min(((int) (m / 3) + (m % 3 == 0 ? 0 : 1)), m);
}
bw.write(Integer.toString(Math.min(tot1, tot2)) + "\n");
}
bw.flush();
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 68ee96f63c0502f693cef89ed38462c0 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.util.*;
public class Q1584B {
static int mod = (int) (1e9 + 7);
static void solve() {
long n = l();
long m = l();
if((n*m)%3==0){
System.out.println((n*m)/3);
}else{
System.out.println(((n*m)/3)+1);
}
}
public static void main(String[] args) {
int test = i();
while (test-- > 0) {
solve();
}
}
// -----> POWER ---> long power(long x, long y) <---- power
// -----> LCM ---> long lcm(long x, long y) <---- lcm
// -----> GCD ---> long gcd(long x, long y) <---- gcd
// -----> NCR ---> long ncr(int n, int r) <---- ncr
// -----> (SORTING OF LONG, CHAR,INT) -->long[] sortLong(long[] a2)<--
// -----> (INPUT OF INT,LONG ,STRING) -> int i() long l() String s()<-
// tempstart
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 InputReader in = new InputReader(System.in);
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();
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 01d0c95a5dff87fe99efda8da8e8ab2e | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes |
import java.util.Scanner;
public class _1584B {
public static void main(String[] args) {
// TODO Auto-generated method stub
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();
int prod = m*n;
if(prod<8) {
if(prod%2==0 && prod%6!=0) {
System.out.println((int)prod/2);
}else if(prod%3==0) {
System.out.println((int)prod/3);
}else {
int max_3 = (int)Math.floor(prod/3)-1;
int max_2 = (prod-max_3*3)/2;
System.out.println(max_3+max_2);
}
}else {
int max_3 = (int)Math.floor(prod/3)-1;
int max_2 = (prod-max_3*3)/2;
System.out.println(max_3+max_2);
}
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 52a5db41fb45a318a16aa803285ec505 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
while(t-->0){
int n = scn.nextInt();
int m = scn.nextInt();
int ans = (int)Math.ceil((double) n*m/3);
System.out.println(ans);
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | e4cc91098eb4c7b9c0b4e1f64f588671 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
import java.io.*;
public class c5{
static class Pair{
int first;
int last;
public Pair(int first , int last){
this.first = first;
this.last = last;
}
public int getFirst(){
return first;
}
public int getLast(){
return last;
}
}
static final int M = 1000000007;
// Fast input
static class Hrittik_FastReader{
StringTokenizer st;
BufferedReader br;
public int n;
public Hrittik_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();
}
String nextLine(){
String str="";
try {
str=br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
double nextDouble(){
return Double.parseDouble(next());
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
}
// Fast output
static class Hrittik_FastWriter {
private final BufferedWriter bw;
public Hrittik_FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}
public void print(Object object) throws IOException {
bw.append("" + object);
}
public void close() throws IOException {
bw.close();
}
}
// GCD of two integers
private static int gcd(int a , int b){
if(b == 0) return a;
return gcd(b, a%b);
}
// GCD of two long integers
private static long gcd(long a , long b){
if(b == 0) return a;
return gcd(b, a%b);
}
// LCM of two integers
private static int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
// LCM of two long integers
private static long lcm(long a, long b) {
return a / gcd(a, b) * b;
}
// swap two elements of an array
private static void swap(int[] arr, int i, int j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
// calculating x ^ y
private static long power(long x, long y){
long res = 1;
x = x % M;
while(y > 0){
if ((y & 1) == 1){
res = (res * x) % M;
}
y = y >> 1;
x = (x * x) % M;
}
return res;
}
static void sortPairByFirst(Pair arr[]){
Arrays.sort(arr , new Comparator<Pair>(){
@Override public int compare(Pair p1 , Pair p2){
return p1.first - p2.first;
}
});
}
static void sortPairByLast(Pair arr[]){
Arrays.sort(arr , new Comparator<Pair>(){
@Override public int compare(Pair p1 , Pair p2){
return p1.last - p2.last;
}
});
}
public static void main(String[] args) {
try {
Hrittik_FastReader Sc =new Hrittik_FastReader();
Hrittik_FastWriter out = new Hrittik_FastWriter();
int t = Sc.nextInt();
outer : while(t-- > 0){
// write your code here
int n = Sc.nextInt();
int m = Sc.nextInt();
int p = n * m;
int ans = p / 3;
int rem = p % 3;
if(rem > 0) ans++;
System.out.println(ans);
}
out.close();
}
catch (Exception e) {
return;
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | ac2020ce6cc640ef4235a542c1db483c | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | //import java.lang.reflect.Array;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import javax.print.DocFlavor.STRING;
import javax.swing.Popup;
import javax.swing.plaf.synth.SynthStyleFactory;
public class Simple{
public static Deque<Integer> possible(int a[],int n){
boolean bool = true;
Deque<Integer> deq = new LinkedList<>();
int i=0;
int j=n-1;
int max = n;
int min = 1;
while(i<=j){
if(a[i]== min){
deq.addFirst(a[i]);
i++;min++;
continue;
}
if(a[j]== min){
deq.addLast(a[j]);
j--;
min++;
continue;
}
if(a[i]==max){
deq.addFirst(a[i]);
i++;
max--;
continue;
}
if(a[j]==max){
deq.addLast(a[j]);
j--;
max--;
continue;
}
Deque<Integer> d = new LinkedList<>();
d.add(-1);
return d;
}
return deq;
}
public static class Pair implements Comparable<Pair>{
int val;
int freq = 0;
Pair prev ;
Pair next;
boolean bool = false;
public Pair(int val,int freq){
this.val = val;
this.freq= freq;
}
public int compareTo(Pair p){
// if(p.freq == this.freq){
// return this.val - p.freq;
// };
// if(this.freq > p.freq)return -1;
// return 1;
return (p.freq-p.val) - (this.freq - this.val);
}
}
public static long factorial(long n)
{
// single line to find factorial
return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
static long m = 998244353;
// Function to return the GCD of given numbers
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
// Recursive function to return (x ^ n) % m
static long modexp(long x, long n)
{
if (n == 0) {
return 1;
}
else if (n % 2 == 0) {
return modexp((x * x) % m, n / 2);
}
else {
return (x * modexp((x * x) % m, (n - 1) / 2) % m);
}
}
// Function to return the fraction modulo mod
static long getFractionModulo(long a, long b)
{
long c = gcd(a, b);
a = a / c;
b = b / c;
// (b ^ m-2) % m
long d = modexp(b, m - 2);
// Final answer
long ans = ((a % m) * (d % m)) % m;
return ans;
}
// public static long bs(long lo,long hi,long fact,long num){
// long help = num/fact;
// long ans = hi;
// while(lo<=hi){
// long mid = (lo+hi)/2;
// if(mid/)
// }
// }
public static boolean isPrime(int n)
{
// Check if number is less than
// equal to 1
if (n <= 1)
return false;
// Check if number is 2
else if (n == 2)
return true;
// Check if n is a multiple of 2
else if (n % 2 == 0)
return false;
// If not, then just check the odds
for (int i = 3; i <= Math.sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
public static int countDigit(long n)
{
int count = 0;
while (n != 0) {
n = n / 10;
++count;
}
return count;
}
static ArrayList<Long> al ;
static boolean checkperfectsquare(long n)
{
// If ceil and floor are equal
// the number is a perfect
// square
if (Math.ceil((double)Math.sqrt(n)) ==
Math.floor((double)Math.sqrt(n)))
{
return true;
}
else
{
return false;
}
}
public static void decToBinary(int n,int arr[],int j)
{
// Size of an integer is assumed to be 32 bits
for (int i = 31; i >= 0; i--) {
int k = n >> i;
if ((k & 1) > 0){
arr[j]++;
}
j++;
}
}
public static long[] helper(long n){
long arr[] = new long[33];
//ong temp = 2;
for (long i = 1; i <= 32; i++) {
long k = (long)Math.pow(2,i);
if (k<=n){
arr[(int)i-1]+= n/k ;
arr[(int)i-1]+= (n) % k;
}
}
return arr;
}
public static int countAp(int i,int j,int arr[],int n,int k){
if(k==n)return 0;
if(arr[k]-arr[j]==arr[j]-arr[i]){
return countAp(i,j,arr,n,k+1)+1;
}
return countAp(i,j,arr,n,k+1);
}
// public static String reverse(String str){
// String ans ="";
// for(int i=0;i<str.length();i++){
// ans+=str.charAt(n-i-1);
// }
// return ans;
// }
// public static int search(ArrayList<Integer> al,int i,int j,int find){
// int mid = (i+j)/2;
// if(al.get(mid)==find)
// }
static int MAX = 100000;
static int factor[];
// function to generate all prime
// factors of numbers from 1 to 10^6
static void generatePrimeFactors()
{
factor = new int[MAX+1];
factor[1] = 1;
// Initializes all the positions with
// their value.
for (int i = 2; i < MAX; i++)
factor[i] = i;
// Initializes all multiples of 2 with 2
for (int i = 4; i < MAX; i += 2)
factor[i] = 2;
// A modified version of Sieve of
// Eratosthenes to store the
// smallest prime factor that
// divides every number.
for (int i = 3; i * i < MAX; i++) {
// check if it has no prime factor.
if (factor[i] == i) {
// Initializes of j starting from i*i
for (int j = i * i; j < MAX; j += i) {
// if it has no prime factor
// before, then stores the
// smallest prime divisor
if (factor[j] == j)
factor[j] = i;
}
}
}
}
// function to calculate number of factors
static int calculateNoOFactors(int n)
{
if (n == 1)
return 1;
int ans = 1;
// stores the smallest prime number
// that divides n
int dup = factor[n];
// stores the count of number of times
// a prime number divides n.
int c = 1;
// reduces to the next number after prime
// factorization of n
int j = n / factor[n];
// false when prime factorization is done
while (j != 1) {
// if the same prime number is dividing n,
// then we increase the count
if (factor[j] == dup)
c += 1;
/* if its a new prime factor that is
factorizing n, then we again set c=1
and change dup to the new prime factor,
and apply the formula explained
above. */
else {
dup = factor[j];
ans = ans * (c + 1);
c = 1;
}
// prime factorizes a number
j = j / factor[j];
}
// for the last prime factor
ans = ans * (c + 1);
return ans;
}
public static int maxPrimefactorNum(int N)
{
if (N < 2)
return 0;
// Based on Sieve of Eratosthenes
// https://www.geeksforgeeks.org/sieve-of-eratosthenes/
boolean[] arr = new boolean[N + 1];
int prod = 1, res = 0;
for (int p = 2; p * p <= N; p++)
{
// If p is prime
if (arr[p] == false)
{
for (int i = p * 2;
i <= N; i += p)
arr[i] = true;
// We simply multiply first set
// of prime numbers while the
// product is smaller than N.
prod *= p;
if (prod > N)
return res;
res++;
}
}
return res;
}
public static class Tuple{
int l,r,u,d;
public Tuple(int l,int r,int u,int d){
this.l=l;
this.r=r;
this.u=u;
this.d=d;
}
}
// public static boolean dfs(ArrayList<ArrayList<Node>> adj,boolean vis[],int node,int k,int count,int n){
// vis[node]=true;
// count++;
// if(count==n)return true;
// for(Node temp : adj.get(node)){
// if(!vis[node] && !isKthBitSet(temp.w, k)&& isEdgeValid){
// return dfs(adj, vis, temp, k,count,n);
// }
// }
// return false;
// }
public static class Node{
//int u;
long v;
long w;
public Node(long v,long w){
//this.u = u;
this.v=v;
this.w=w;
}
}
public static boolean isKthBitSet(int n,int k){
if ((n & (1 << (k - 1))) > 0)
return true;
return false;
}
public static class Edge{
int v1 =-1;
int v2 = -1;
int e1=-1;
int e2=-1;
}
// public static long helper(String a,String b,int i,int j,int lasti,int lastj,long dp[][]){
// if(i==0 && j==0){
// return 0;
// }
// if(dp[i][j]!=-1){
// return dp[i][j];
// }
// long ans1 = Long.MAX_VALUE;
// long ans2 =Long.MAX_VALUE;
// if(i>0){
// if(a.charAt(i-1)=='1'){
// ans1 = helper(a, b, i-1, j, i, lastj, dp)+dp[lasti][lastj]+lasti-i+1;
// }
// else{
// ans1 = helper(a, b, i-1, j, lasti, lastj, dp);
// }
// }
// if(j>0){
// if(b.charAt(j-1)=='1'){
// ans2 = helper(a, b, i, j-1, lasti, j, dp)+dp[lasti][lastj] + lastj-j+1;
// }
// else{
// ans2 = helper(a, b, i, j-1, lasti, lastj, dp);
// }
// }
// dp[i][j] = Math.min(ans1,ans2);
// return dp[i][j];
// }
public static boolean[] sieve(int n){
boolean isPrime[] = new boolean[n+1];
Arrays.fill(isPrime, true);
isPrime[0] = false;
isPrime[1] = false;
for(int i=2;i*i<=n;i++){
if(!isPrime[i])continue;
for(int j= i*2;j<=n;j=j+i){
isPrime[j] = false;
}
}
return isPrime;
}
public static void swap(int a[][],int i1,int i2,int j1,int j2){
int temp = a[i1][i2];
a[i1][i2] = a[j1][j2];
a[j1][j2] = temp;
}
public static long helper1(long n){
if(n==0 || n==1||n<0){
return 0;
}
long pow = (long)(Math.log(n)/Math.log(2));//2
long num = (long)(Math.pow(2, pow));//4
long greater = n - num + 1;
long add = num*2 - 1;
if(greater>n/2){
long ans = (n-1)*add;
return ans;
}
long ans = greater*2*add;
return ans + helper1(n-greater*2);
}
static int power(int x, int y, int p)
{
int res = 1; // Initialize result
x = x % p; // Update x if it is more
// than or equal to p
while (y > 0)
{
// If y is odd, multiply
// x with result
if ((y & 1) > 0)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
// Function to find modular
// inverse of a under modulo p
// using Fermat's method.
// Assumption: p is prime
static int modInverse(int a, int p)
{
return power(a, p - 2, p);
}
// Returns n! % p using
// Wilson's Theorem
static int modFact(int n,
int p)
{
if (n >= p)
return 0;
int result = 1;
for (int i = 1; i <= n; i++)
result = (result * i) % p;
return result;
}
public static void bfs(ArrayList<ArrayList<Integer>> adj,boolean vis[],int dis[]){
vis[0] = true;
Queue<Integer> q = new LinkedList<>();
q.add(0);
int count = 0;
while(!q.isEmpty()){
int size = q.size();
for(int j = 0;j<size;j++){
int poll = q.poll();
dis[poll] = count;
vis[poll] = true;
for(Integer x : adj.get(poll)){
if(!vis[x]){
q.add(x);
}
}
}
count++;
}
}
public static int maxRect(int n,int m){
if(m==0 || n==0)return 0;
if(m==1){
return maxRect(m, n);
}
if(n==1){
int count = m/3;
if(m%3!=0)count++;
return count;
}
int count1 = (m/3)*n;
if(m==2){
count1 = n;
}
else{
count1+=maxRect(n, m%3);
}
int count2 = (n/3)*m;
if(n==2){
count2 = m;
}
else{
count2+= maxRect(n%3, m);
}
return Math.min(count1,count2);
}
//
public static void main(String args[]){
//System.out.println("Hello Java");
Scanner s = new Scanner(System.in);
int t = s.nextInt();
for(int t1 = 1;t1<=t;t1++){
int n = s.nextInt();
int m = s.nextInt();
int ans = maxRect(n, m);
System.out.println(ans);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | f23a0d5d49449bc738c307bb55decb10 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Arrays;
public class Main {
static void merge(int[] a, int l, int mid, int r) {
int p1 = l, p2 = mid + 1, size = r-l+1;
int temp[] = new int[size];
for(int i = 0;i < size;i++) {
if(p1 <= mid && p2 <= r) {
temp[i] = a[p1] <= a[p2] ? a[p1++] : a[p2++];
} else {
temp[i] = p1 <= mid ? a[p1++] : a[p2++];
}
}
for(int i = 0;i < size;i++) {
a[l++] = temp[i];
}
}
static void mergeSort(int[] a, int l, int r) {
if(l < r) {
int mid = l + (r-l) / 2;
mergeSort(a, l, mid);
mergeSort(a, mid + 1, r);
merge(a, l, mid, r);
}
}
static void mergeSort(int[] a) {
mergeSort(a, 0, a.length-1);
}
public static void main(String[] args) throws IOException {
FastScanner input = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int tests = input.nextInt();
for(int testNum = 0;testNum < tests;testNum++) {
int n = input.nextInt();
int m = input.nextInt();
int a = n*m;
a = a%3 == 0 ? a/3 : a/3+1;
out.println(a);
}
out.flush();
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | b9aa8b48a5866ea1e02b8e98fb929391 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | /******************************************************************************
Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
while(t-->0){
int n = scn.nextInt();
int m = scn.nextInt();
int val = (m*n%3);
int ans = m*n / 3;
if(val>0){
ans++;
}
System.out.println(ans);
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 23228d34fb4c058d33688744b50ba531 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 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
{
// your code goes here
Scanner scn = new Scanner(System.in);
int T = scn.nextInt();
while(T-- > 0){
int n = scn.nextInt();
int m = scn.nextInt();
int area = n * m ;
int ans = area / 3;
if(area % 3 != 0){
ans += 1;
}
System.out.println(ans);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 47ac86feb6a47156e1889b99ef36a302 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
public class B {
public static void main(String[] args) throws java.lang.Exception {
try {
FastReader sc = new FastReader();
int t = sc.nextInt();
u: while (t-- > 0) {
int n = sc.nextInt();
int m=sc.nextInt();
if(n*m<=3)
{
System.out.println(1);
continue u;
}
else
{
int p=n*m;
if(p%3==0)
System.out.println(p/3);
else
System.out.println((p/3)+1);
}
}
} catch (Exception e) {
} finally {
return;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 8a6eb5d6794ccfb0b06d63bc60c5874c | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
public class Solution{
static Scanner sc = new Scanner(System.in);
public static void main(String[] a) {
int testCases = sc.nextInt();
long t1 = System.currentTimeMillis();
for(int i=1; i<=testCases; i++){
solve();
}
if (System.getProperty("ONLINE_JUDGE") == null){
long t2 = System.currentTimeMillis();
System.err.println("Time = " + (t2 - t1));
}
}
public static void solve(){
int m=sc.nextInt();
int n=sc.nextInt();
System.out.println((m*n+2)/3);
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | ef6100ccf1f6385c83b172f5cd7a41bf | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Codeforces {
static long mod = 1_000_000__007;
public static void main(String[] args) {
FastReader fastReader = new FastReader();
int t = fastReader.nextInt();
while (t-- > 0) {
int n = fastReader.nextInt();
int m = fastReader.nextInt();
if (n%3 == 0){
int ans = n/3;
System.out.println(ans*m);
}else if (m%3 == 0){
int ans = m/3;
System.out.println(ans*n);
}else if (n > m){
int ans = n/3;
int add = 0;
if (n%3 != 0){
int rem = (n%3)*m;
add = rem/3;
if (rem%3 != 0){
add++;
}
}
System.out.println((ans*m)+add);
}else{
int ans = m/3;
int add = 0;
if (m%3 != 0){
int rem = (m%3)*n;
add = rem/3;
if (rem%3 != 0){
add++;
}
}
System.out.println((ans*n)+add);
}
}
}
public static boolean isEqual(String s1, String s2) {
boolean isValid = true;
if (s1.length() != s2.length()) {
return false;
}
for (int i = 0; i < s1.length(); i++) {
if (s1.charAt(i) != s2.charAt(i)) {
isValid = false;
break;
}
}
return isValid;
}
static long power(long a, long b) {
if (a == 1 || b == 0) {
return 1L;
}
long res = 1;
while (b != 0) {
if (b % 2 == 1) {
res = (res * a) % mod;
}
b /= 2;
a = (a * a) % mod;
}
return res % mod;
}
static class Pair {
int x;
int y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | aa4c18f6cad740eff5bd62f4d3112c87 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
public class class355 {
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int m=sc.nextInt();
int val=(int)Math.ceil((double)(n*m)/3);
System.out.println(val);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 23175bfe3504a27270ef2142dff31b63 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class test{
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int t = Integer.parseInt(br.readLine());
while(t-- > 0){
StringTokenizer tokenizer = new StringTokenizer(br.readLine());
int n = Integer.parseInt(tokenizer.nextToken());
int m = Integer.parseInt(tokenizer.nextToken());
pw.println((int)Math.ceil((double)(n*m)/(double)3));
}
pw.flush();
pw.close();
br.close();
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 4b7aaf17ea1e93351e88a58e6e66be92 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
public class Main
{
static Scanner sc = new Scanner (System.in);
public static void main(String[] args) {
int test = sc.nextInt();
for ( int i=0; i<test; i++){
long a = sc.nextInt();
long b = sc.nextInt();
long c = a*b;
if( c%3==0)
System.out.println(c/3);
else
System.out.println(c/3+1);
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 935231d5e3592369a7183bfe7dcbd3b9 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner in = new Scanner(System.in);
int test = in.nextInt();
for(int i = 0; i < test; i++){
int n = in.nextInt();
int m = in.nextInt();
int rel = n*m;
int min = 0;
if(rel%3 == 0){
min = rel/3;
}
else{
min = rel/3 + 1;
}
System.out.println(min);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 48fada63259b837611b4aff6b643df20 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | /*LoudSilence*/
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Solution {
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
static FastScanner s = new FastScanner();
static FastWriter out = new FastWriter();
final static int mod = (int)1e9 + 7;
final static int INT_MAX = Integer.MAX_VALUE;
final static int INT_MIN = Integer.MIN_VALUE;
final static long LONG_MAX = Long.MAX_VALUE;
final static long LONG_MIN = Long.MIN_VALUE;
final static double DOUBLE_MAX = Double.MAX_VALUE;
final static double DOUBLE_MIN = Double.MIN_VALUE;
final static float FLOAT_MAX = Float.MAX_VALUE;
final static float FLOAT_MIN = Float.MIN_VALUE;
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
static class FastScanner{BufferedReader br;StringTokenizer st;
public FastScanner() {br = new BufferedReader(new InputStreamReader(System.in));}
String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException e){e.printStackTrace();}}return st.nextToken();}
int nextInt(){return Integer.parseInt(next());}
long nextLong(){return Long.parseLong(next());}
double nextDouble(){return Double.parseDouble(next());}
List<Integer> readIntList(int n){List<Integer> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextInt()); return arr;}
List<Long> readLongList(int n){List<Long> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextLong()); return arr;}
int[] readIntArr(int n){int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = s.nextInt(); return arr;}
long[] readLongArr(int n){long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = s.nextLong(); return arr;}
String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}}
static class FastWriter{private 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 debug(int object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");}
public void debug(long object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");}
public void close() throws IOException{bw.close();}}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
public static ArrayList<Integer> seive(int n){ArrayList<Integer> list = new ArrayList<>();int arr[] = new int[n+1];for(int i = 2; i <= n; i++) {if(arr[i] == 1) {continue;}else {list.add(i);for(int j = i*i; j <= n; j = j + i) {arr[j] = 1;}}}return list;}
public static long gcd(long a, long b){if(a > b) {a = (a+b)-(b=a);}if(a == 0L){return b;}return gcd(b%a, a);}
public static void swap(int[] arr, int i, int j) {arr[i] = arr[i] ^ arr[j]; arr[j] = arr[j] ^ arr[i]; arr[i] = arr[i] ^ arr[j];}
public static boolean isPrime(long n){if(n < 2){return false;}if(n == 2 || n == 3){return true;}if(n%2 == 0 || n%3 == 0){return false;}long sqrtN = (long)Math.sqrt(n)+1;for(long i = 6L; i <= sqrtN; i += 6) {if(n%(i-1) == 0 || n%(i+1) == 0) return false;}return true;}
public static long mod_add(long a, long b){ return (a%mod + b%mod)%mod;}
public static long mod_sub(long a, long b){ return (a%mod - b%mod + mod)%mod;}
public static long mod_mul(long a, long b){ return (a%mod * b%mod)%mod;}
public static long modInv(long a, long b){ return expo(a, b-2)%b;}
public static long mod_div(long a, long b){return mod_mul(a, modInv(b, mod));}
public static long expo (long a, long n){if(n == 0){return 1;}long recAns = expo(mod_mul(a,a), n/2);if(n % 2 == 0){return recAns;}else{return mod_mul(a, recAns);}}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
// Pair class
public static class Pair<X extends Comparable<X>,Y extends Comparable<Y>> implements Comparable<Pair<X, Y>>{
X first;
Y second;
public Pair(X first, Y second){
this.first = first;
this.second = second;
}
public String toString(){
return "( " + first+" , "+second+" )";
}
@Override
public int compareTo(Pair<X, Y> o) {
int t = first.compareTo(o.first);
if(t == 0) return second.compareTo(o.second);
return t;
}
}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
// Code begins
public static void solve(int test) throws IOException {
int n = s.nextInt();
int m = s.nextInt();
if(m >= 3){
if(m == 3){
System.out.println(n);
}else{
int ans = m/3 * n;
m = m - ((m/3) * 3);
if(n >= 3){
if(n == 3){
System.out.println(m + ans);
}else{
ans += n/3 * m;
n = n - ((n/3) * 3);
if(n*m == 4){
ans += 2;
}else if(n*m == 1 || n*m == 2){
ans++;
}
System.out.println(ans);
}
}else{
if(n*m == 4){
ans+=2;
}else if(n*m == 1 || n*m == 2){
ans+=1;
}
System.out.println(ans);
}
}
}else{
int ans = 0;
if(n >= 3){
if(n == 3){
System.out.println(m + ans);
}else{
ans += n/3 * m;
n = n - ((n/3) * 3);
if(n*m == 4){
ans += 2;
}else if(n*m == 1 || n*m == 2){
ans++;
}
System.out.println(ans);
}
}else{
if(n*m == 4){
System.out.println(2);
}else{
System.out.println(1);
}
}
}
}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
public static void main(String[] args) throws IOException {
int test = s.nextInt();
for(int tt = 1; tt <= test; tt++) {
solve(tt);
}
out.close();
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | ca4a0aa270b65ab8730758686114f4be | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | // 🔥🔥🔥🔥 Author: Aman Bhatt (Codeforces Handle: bhattaman0001) 🔥🔥🔥🔥 //
import java.io.*;
import java.util.*;
public class Practice extends PrintWriter {
Practice() {
super(System.out);
}
static Scanner sc = new Scanner(System.in);
public static boolean isSquare(int n) {
int sqrt = (int) Math.sqrt(n);
if (sqrt * sqrt == n) return true; else return false;
}
public static String reverseAString(String s) {
char[] ch = s.toCharArray();
String reverse = "";
for (int i = s.length() - 1; i >= 0; i--) {
reverse += ch[i];
}
return reverse;
}
public static void main(String[] $) {
try (Practice o = new Practice()) {
o.main();
o.flush();
}
}
static HashSet<Integer> set = new HashSet<>();
public static int LCM(int a, int b, int c) {
for (int i = 2; i < a; i++) {
if (a % i == 0) {
set.add(i);
}
}
for (int i = 2; i < b; i++) {
if (b % i == 0) {
set.add(i);
}
}
for (int i = 2; i < c; i++) {
if (c % i == 0) {
set.add(i);
}
}
int ans = 1;
for (int i : set) {
ans *= i;
}
return Math.max(a * b * c, ans);
}
static int gcd(int a, int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
static int lcm(int a, int b) {
return (a / gcd(a, b)) * b;
}
public static boolean div(int n, int d) {
int k = (int) Math.min(d, Math.sqrt(n));
for (int i = 1; i < k; i++) {
if (n % (i + 1) == 0) return false;
}
return true;
}
void main() {
int k = sc.nextInt();
while (k-- > 0) {
int n = sc.nextInt();
int m = sc.nextInt();
int val = n * m;
if (val % 3 == 0) {
println(val / 3);
} else {
val = val + 3 - (val) % 3;
println(val / 3);
}
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 3e94e3bbac122b6c93046771f4c8a728 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
public class class355 {
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int m=sc.nextInt();
int val=(int)Math.ceil((double)(n*m)/3);
System.out.println(val);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | eefdaecac34584a5888ff142d03cbb62 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
import java.math.BigInteger;
public class CodeforcesRound753 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc= new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int m=sc.nextInt();
System.out.println((n*m+2)/3);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 3d4e621b1d1cb324c51cfa43ce9f22a1 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | /*package whatever //do not write package name here */
import java.util.*;
import java.io.*;
public class main
{
public static void main (String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int i=0;
while(i<n)
{
double a = in.nextInt();
double b = in.nextInt();
int c = (int)Math.ceil(a*b/3);
System.out.println(c);
i=i+1;
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 147637a0e58a0c53d72a1b72dfe84ae4 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 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 x = sc.nextInt();
int y = sc.nextInt();
int ans = (int)Math.ceil((x*y)/3.0);
System.out.println(ans);
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | c7789acd144370ee10246862f612bb82 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 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 S=new Scanner(System.in);
int t=S.nextInt();
while(t>0)
{
t--;
int n=S.nextInt();
int m=S.nextInt();
long sum=n*m;
System.out.println(sum%3==0 ? sum/3:sum/3 +1);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | de76b0977e5d8586520ba97f313f7faa | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | /*
AUTHOR-> HARSHIT AGGARWAL
CODEFORCES HANDLE-> @harshit_agg
FROM-> MAHARAJA AGRASEN INSTITUE OF TECHNOLOGY
>> YOU CAN DO THIS <<
*/
import java.util.*;
import java.io.*;
public class colouringrectangles {
public static void main(String[] args) throws Exception {
int t = scn.nextInt();
while (t-- > 0) {
solver();
}
}
public static void solver() {
int n = scn.nextInt();
int m = scn.nextInt();
System.out.println((int)Math.ceil((double)n*m/3));
}
//-------------------------------- HO JA BHAI ----------------------------------------------------
/* code ends here*/
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx U T I L I T I E S xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
public static class Debug { public static final boolean LOCAL = System.getProperty("LOCAL")==null; private static <T> String ts(T t) { if(t==null) { return "null"; } try { return ts((Iterable) t); }catch(ClassCastException e) { if(t instanceof int[]) { String s = Arrays.toString((int[]) t); return "{"+s.substring(1, s.length()-1)+"}"; }else if(t instanceof long[]) { String s = Arrays.toString((long[]) t); return "{"+s.substring(1, s.length()-1)+"}"; }else if(t instanceof char[]) { String s = Arrays.toString((char[]) t); return "{"+s.substring(1, s.length()-1)+"}"; }else if(t instanceof double[]) { String s = Arrays.toString((double[]) t); return "{"+s.substring(1, s.length()-1)+"}"; }else if(t instanceof boolean[]) { String s = Arrays.toString((boolean[]) t); return "{"+s.substring(1, s.length()-1)+"}"; } try { return ts((Object[]) t); }catch(ClassCastException e1) { return t.toString(); } } } private static <T> String ts(T[] arr) { StringBuilder ret = new StringBuilder(); ret.append("{"); boolean first = true; for(T t: arr) { if(!first) { ret.append(", "); } first = false; ret.append(ts(t)); } ret.append("}"); return ret.toString(); } private static <T> String ts(Iterable<T> iter) { StringBuilder ret = new StringBuilder(); ret.append("{"); boolean first = true; for(T t: iter) { if(!first) { ret.append(", "); } first = false; ret.append(ts(t)); } ret.append("}"); return ret.toString(); } public static void dbg(Object... o) { if(LOCAL) { System.err.print("Line #"+Thread.currentThread().getStackTrace()[2].getLineNumber()+": ["); for(int i = 0; i<o.length; i++) { if(i!=0) { System.err.print(", "); } System.err.print(ts(o[i])); } System.err.println("]"); } } }
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()); } float nextFloat() { return Float.parseFloat(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
static int INF = (int) 1e9 + 7; // static int INF = 998244353;
static int MAX = Integer.MAX_VALUE; // static int MAX = 2147483647
static int MIN = Integer.MIN_VALUE; // static int MIN = -2147483647
static class Pair implements Comparable<Pair> { int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair o) { return this.first- o.first; } }
static class LongPair { long first; long second; LongPair(long a, long b) { this.first = a; this.second = b; } }
public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); }
public static int LowerBound(long a[], long x) { /* x is the key or target value */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; }
public static int LowerBound(int a[], int x) { /* x is the key or target value */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 LowerBoundList(ArrayList<Integer> a, int x) { /* x is the key or target value */int l = -1, r = a.size(); while (l + 1 < r) { int m = (l + r) >>> 1; if (a.get(m) >= x) r = m; else l = m; } return r; }
static boolean[] prime; public static void sieveOfEratosthenes(int n) { prime = new boolean[n + 1]; for (int i = 0; i < n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } }
public static int UpperBound(long a[], long x) {/* x is the key or target value */int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] <= x) l = m; else r = m; } return l + 1; }
public static int UpperBound(int a[], int x) {/* x is the key or target value */int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] <= x) l = m; else r = m; } return l + 1; }
public static long lcm(long a, long b) { return (a * b) / gcd(a, b); }
public static void swap(int[] arr, int i, int j) { if (i != j) { arr[i] ^= arr[j]; arr[j] ^= arr[i]; arr[i] ^= arr[j]; } }
public static long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = scn.nextLong(); return a; }
public static int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = scn.nextInt(); } return a; }
public int[][] nextIntMatrix(int n, int m) { int[][] grid = new int[n][m]; for (int i = 0; i < n; i++) { grid[i] = nextIntArray(m); } return grid; }
public static int smallest_divisor(int n) { int i; for (i = 2; i <= Math.sqrt(n); ++i) { if (n % i == 0) { return i; } } return n; }
public static FastReader scn = new FastReader();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | e861936a1a4dab772a0d3f15e107cc97 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
for(int k=0;k<t;k++){
int n = scn.nextInt();
int m = scn.nextInt();
if(n%3==0){
System.out.println((n/3)*m);
}else if(m%3==0){
System.out.println(n*(m/3));
}else{
System.out.println(Math.min((n/3)*m+(int)Math.ceil(m/3.0)*(n%3),(m/3)*n+(int)Math.ceil(n/3.0)*(m%3)));
}
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | d377be849b5544ac61337dc9bd3685de | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.Scanner;
public class B_Coloring_Rectangles{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while(t-->0){
int rowSize = scan.nextInt();
int columnSize = scan.nextInt();
int result = (((columnSize*rowSize)+2)/3);
System.out.println(result);
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | ccbd13709835bf717f778370a8441561 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class coloringRectangle {
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[] input = br.readLine().split(" ");
int m = Integer.parseInt(input[0]);
int n = Integer.parseInt(input[1]);
int b = 0;
if(m < n)
m = (m + n) - (n = m);
while(m > 0 && n > 0) {
if(m * n == 1) {
b += 1;
m -= 1; n -= 1;
}
else if(m * n == 2) {
b += 1;
m -= 2; n -= 1;
}
else if(m * n == 4) {
b += 2;
m -= 2; n -= 2;
}
else {
if(m % 3 == 0 && m == n) {
b = b + (n * (m / 3));
m = 0; n = 0;
}
else {
b = b + (n * (m / 3));
m = m % 3;
}
}
if(m < n)
m = (m + n) - (n = m);
}
System.out.println(b);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 6cda989a690a9c7d98e1cd06c393eb43 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | //1584B
import java.util.*;
public class Coloring_Rectangle
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=1;i<=t;i++)
{
String s[]=(sc.next()+sc.nextLine()).split(" ");
int n=Integer.parseInt(s[0]),n1=n,m=Integer.parseInt(s[1]),m1=m;
int c1=(n/3)*m,c2=(m/3)*n;
n1=n-3*(n/3);m1=m-3*(m/3);
c1+=(n1*(m/3));c2+=(m1*(n/3));
if(m1==2&&n1==2)
{
c1+=2;c2+=2;
}
else if(m1*n1==1||m1*n1==2)
{
c1++;c2++;
}
System.out.println(Math.min(c1,c2));
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 2ef514fd394d286fa56647c87c07e7be | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static long mod = 1000000007;
static long max ;
static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
public static void main(String[] args) throws IOException {
FastReader sc = new FastReader();
int t = sc.nextInt();
while( t-- > 0) {
int n = sc.nextInt();
int m = sc.nextInt();
long x = 1L*n*m;
if( x %3 == 0) {
out.println(x/3);
}
else {
out.println(x/3 + 1);
}
}
out.flush();
}
/*
* FIRST AND VERY IMP -> READ AND UNDERSTAND THE QUESTION VERY CAREFULLY.
* WARNING -> DONT CODE BULLSHIT , ALWAYS CHECK THE LOGIC ON MULTIPLE TESTCASES AND EDGECASES BEFORE.
* SECOND -> TRY TO FIND RELEVENT PATTERN SMARTLY.
* WARNING -> IF YOU THINK YOUR SOLUION IS JUST DUMB DONT SUBMIT IT BEFORE RECHECKING ON YOUR END.
*/
public static boolean ifpowof2(long n ) {
return ((n&(n-1)) == 0);
}
static boolean isprime(long x ) {
if( x== 2) {
return true;
}
if( x%2 == 0) {
return false;
}
for( long i = 3 ;i*i <= x ;i+=2) {
if( x%i == 0) {
return false;
}
}
return true;
}
static boolean[] sieveOfEratosthenes(long n) {
boolean prime[] = new boolean[(int)n + 1];
for (int i = 0; i <= n; i++) {
prime[i] = true;
}
for (long p = 2; p * p <= n; p++) {
if (prime[(int)p] == true) {
for (long i = p * p; i <= n; i += p)
prime[(int)i] = false;
}
}
return prime;
}
public static int[] nextLargerElement(int[] arr, int n) {
Stack<Integer> stack = new Stack<>();
int rtrn[] = new int[n];
rtrn[n-1] = -1;
stack.push( n-1);
for( int i = n-2 ;i >= 0 ; i--){
int temp = arr[i];
int lol = -1;
while( !stack.isEmpty() && arr[stack.peek()] <= temp){
if(arr[stack.peek()] == temp ) {
lol = stack.peek();
}
stack.pop();
}
if( stack.isEmpty()){
if( lol != -1) {
rtrn[i] = lol;
}
else {
rtrn[i] = -1;
}
}
else{
rtrn[i] = stack.peek();
}
stack.push( i);
}
return rtrn;
}
static void mysort(int[] arr) {
for(int i=0;i<arr.length;i++) {
int rand = (int) (Math.random() * arr.length);
int loc = arr[rand];
arr[rand] = arr[i];
arr[i] = loc;
}
Arrays.sort(arr);
}
static void mySort(long[] arr) {
for(int i=0;i<arr.length;i++) {
int rand = (int) (Math.random() * arr.length);
long loc = arr[rand];
arr[rand] = arr[i];
arr[i] = loc;
}
Arrays.sort(arr);
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static long lcm(long a, long b)
{
return (a / gcd(a, b)) * b;
}
static long rightmostsetbit(long n) {
return n&-n;
}
static long leftmostsetbit(long n)
{
long k = (long)(Math.log(n) / Math.log(2));
return 1 << k;
}
static HashMap<Long,Long> primefactor( long n){
HashMap<Long ,Long> hm = new HashMap<>();
long temp = 0;
while( n%2 == 0) {
temp++;
n/=2;
}
if( temp!= 0) {
hm.put( 2L, temp);
}
long c = (long)Math.sqrt(n);
for( long i = 3 ; i <= c ; i+=2) {
temp = 0;
while( n% i == 0) {
temp++;
n/=i;
}
if( temp!= 0) {
hm.put( i, temp);
}
}
if( n!= 1) {
hm.put( n , 1L);
}
return hm;
}
static ArrayList<Integer> allfactors(int abs) {
HashMap<Integer,Integer> hm = new HashMap<>();
ArrayList<Integer> rtrn = new ArrayList<>();
for( int i = 2 ;i*i <= abs; i++) {
if( abs% i == 0) {
hm.put( i , 0);
hm.put(abs/i, 0);
}
}
for( int x : hm.keySet()) {
rtrn.add(x);
}
if( abs != 0) {
rtrn.add(abs);
}
return rtrn;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | ae2803fa1a3a02e241a8c9d0df0b305e | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
public class Test {
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();
long area = (m * n);
int ans = (int) (area / 3);
if(area % 3 != 0) ans++;
System.out.println(ans);
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | b759a48eaf0d33641338bdf68aff74da | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
import javax.swing.plaf.synth.SynthSplitPaneUI;
import java.lang.*;
public class B_Coloring_Rectangles{
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();
long temp=(n*m);
if(temp%3==0){
int ans=(int)temp/3;
System.out.println(ans);
}else{
int ans=(int)temp/3;
System.out.println(ans+1);
}
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 61cc599f5ecc75ac65154035000ab25a | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
public class Solution{
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*m%3==0){
System.out.println(n*m/3);
}
else{
System.out.println(1+(n*m/3));
}
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 699916d2256f4fd6b73eac073bbff800 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Manav
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
BColoringRectangles solver = new BColoringRectangles();
solver.solve(1, in, out);
out.close();
}
static class BColoringRectangles {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int t = in.nextInt();
for (int it = 0; it < t; it++) {
int n = in.nextInt(), m = in.nextInt();
long prod = n * m;
if (prod % 3l == 0) {
out.println(prod / 3);
} else out.println(prod / 3 + 1);
}
}
}
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 close() {
writer.close();
}
public void println(long i) {
writer.println(i);
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 7f712b467f9278c325cc12776dc6a733 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes |
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
static BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
static StringTokenizer tok;
static StringBuilder output = new StringBuilder("");
static int[][] darr, doper;
static boolean[][] dused, dcheck;
static int[] arr, oper;
static boolean[] used, check;
static int h, w, n, m;
public static void main(String[] args) throws Exception {
solution();
}
public static void solution() throws Exception {
int TT = Integer.parseInt(rd.readLine());
for(int TS=0;TS<TT;TS++) {
tok = new StringTokenizer(rd.readLine());
int a = Integer.parseInt(tok.nextToken());
int b = Integer.parseInt(tok.nextToken());
int x = 0, y = 0;
if(a%3 > b%3) {
x = a;
y = b;
} else if(a%3 < b%3) {
x = b;
y = a;
} else {
x = a > b ? a : b;
y = a > b ? b : a;
}
int dx = x % 3;
int dy = y % 3;
int res = ( x / 3 ) * y;
res += (( y / 3) * dx);
res += dx == 2 && dy == 2 ? 2 :
dx == 0 || dy == 0 ? 0 : 1;
wr.write(res+"");
wr.newLine();
}
wr.flush();
}
public static void solution2() throws Exception {
int TT = Integer.parseInt(rd.readLine());
for(int TS=0;TS<TT;TS++) {
tok = new StringTokenizer(rd.readLine());
long x = Integer.parseInt(tok.nextToken());
long y = Integer.parseInt(tok.nextToken());
wr.write((-(x*x))+" "+(y*y));
wr.newLine();
}
wr.flush();
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 599a13db391ed07651df67aa3a54c3d8 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | //package currentContest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class P1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
FastReader sc = new FastReader();
int t;
t = sc.nextInt();
StringBuilder st = new StringBuilder();
// int tc=1;
while (t-- != 0) {
int n=sc.nextInt();
int m=sc.nextInt();
int ans=(n*m)/3;
if((n*m)%3!=0) {
ans++;
}
st.append(ans+"\n");
}
System.out.println(st);
}
static FastReader sc = new FastReader();
public static void solvegraph() {
int n = sc.nextInt();
int edge[][] = new int[n - 1][2];
for (int i = 0; i < n - 1; i++) {
edge[i][0] = sc.nextInt() - 1;
edge[i][1] = sc.nextInt() - 1;
}
ArrayList<ArrayList<Integer>> ad = new ArrayList<>();
for (int i = 0; i < n; i++) {
ad.add(new ArrayList<Integer>());
}
for (int i = 0; i < n - 1; i++) {
ad.get(edge[i][0]).add(edge[i][1]);
ad.get(edge[i][1]).add(edge[i][0]);
}
int parent[] = new int[n];
Arrays.fill(parent, -1);
parent[0] = n;
ArrayDeque<Integer> queue = new ArrayDeque<>();
queue.add(0);
int child[] = new int[n];
Arrays.fill(child, 0);
ArrayList<Integer> lv = new ArrayList<Integer>();
while (!queue.isEmpty()) {
int toget = queue.getFirst();
queue.removeFirst();
child[toget] = ad.get(toget).size() - 1;
for (int i = 0; i < ad.get(toget).size(); i++) {
if (parent[ad.get(toget).get(i)] == -1) {
parent[ad.get(toget).get(i)] = toget;
queue.addLast(ad.get(toget).get(i));
}
}
lv.add(toget);
}
child[0]++;
}
static void sort(int[] A) {
int n = A.length;
Random rnd = new Random();
for (int i = 0; i < n; ++i) {
int tmp = A[i];
int randomPos = i + rnd.nextInt(n - i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
static void sort(long[] A) {
int n = A.length;
Random rnd = new Random();
for (int i = 0; i < n; ++i) {
long tmp = A[i];
int randomPos = i + rnd.nextInt(n - i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
static String sort(String s) {
Character ch[] = new Character[s.length()];
for (int i = 0; i < s.length(); i++) {
ch[i] = s.charAt(i);
}
Arrays.sort(ch);
StringBuffer st = new StringBuffer("");
for (int i = 0; i < s.length(); i++) {
st.append(ch[i]);
}
return st.toString();
}
public static long gcd(long a, long b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 3d2018054b5bd988e4d1546523f014db | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
import java.io.*;
public class Practice {
static boolean multipleTC = true;
FastReader in;
PrintWriter out;
static int mod = 1000000007;
public static void main(String[] args) throws Exception {
new Practice().run();
}
void run() throws Exception {
in = new FastReader();
out = new PrintWriter(System.out);
int T = (multipleTC) ? ni() : 1;
pre();
for (int t = 1; t <= T; t++)
solve(t);
out.flush();
out.close();
}
void pre() throws Exception {
}
void solve(int TC) throws Exception {
int n = ni();
int m = ni();
int area = n * m;
int ans = (area / 3) + ((area % 3) != 0 ? 1 : 0);
pn(ans);
}
boolean isSorted(int arr[]) {
for (int i = 1; i < arr.length; i++) {
if (arr[i] < arr[i - 1]) {
return false;
}
}
return true;
}
static int bitCount(int x) {
return x == 0 ? 0 : (1 + bitCount(x & (x - 1)));
}
void sort(int arr[]) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < arr.length; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = 0; i < arr.length; i++)
arr[i] = list.get(i);
}
static void dbg(Object... o) {
System.err.println(Arrays.deepToString(o));
}
public static boolean isPrime(long n) {
if (n < 2)
return false;
if (n == 2 || n == 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
long sqrtN = (long) Math.sqrt(n) + 1;
for (long i = 6L; i <= sqrtN; i += 6) {
if (n % (i - 1) == 0 || n % (i + 1) == 0)
return false;
}
return true;
}
public static long gcd(long a, long b) {
if (a > b)
a = (a + b) - (b = a);
if (a == 0L)
return b;
return gcd(b % a, a);
}
public long pow(long base, long exp, long MOD) {
base %= MOD;
long res = 1;
while (exp > 0) {
if ((exp & 1) == 1)
res = res * base % MOD;
base = base * base % MOD;
exp >>= 1;
}
return res;
}
public static long totient(long n) {
long result = n;
for (int p = 2; p * p <= n; ++p)
if (n % p == 0) {
while (n % p == 0)
n /= p;
result -= result / p;
}
if (n > 1)
result -= result / n;
return result;
}
int bit(long n) {
return (n == 0) ? 0 : (1 + bit(n & (n - 1)));
}
public long max(long... arr) {
long max = arr[0];
for (long itr : arr)
max = Math.max(max, itr);
return max;
}
public int max(int... arr) {
int max = arr[0];
for (int itr : arr)
max = Math.max(max, itr);
return max;
}
public long min(long... arr) {
long min = arr[0];
for (long itr : arr)
min = Math.min(min, itr);
return min;
}
public int min(int... arr) {
int min = arr[0];
for (int itr : arr)
min = Math.min(min, itr);
return min;
}
public long sum(long... arr) {
long sum = 0;
for (long itr : arr)
sum += itr;
return sum;
}
public long sum(int... arr) {
long sum = 0;
for (int itr : arr)
sum += itr;
return sum;
}
void p(Object o) {
out.print(o);
}
void pn(Object o) {
out.println(o);
}
void pni(Object o) {
out.println(o);
out.flush();
}
String n() throws Exception {
return in.next();
}
String nln() throws Exception {
return in.nextLine();
}
int ni() throws Exception {
return Integer.parseInt(in.next());
}
long nl() throws Exception {
return Long.parseLong(in.next());
}
double nd() throws Exception {
return Double.parseDouble(in.next());
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws Exception {
br = new BufferedReader(new FileReader(s));
}
String next() throws Exception {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new Exception(e.toString());
}
}
return st.nextToken();
}
String nextLine() throws Exception {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
throw new Exception(e.toString());
}
return str;
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 6f8c849d9d5a9063fb7fe0f74d4032ee | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
public class MyClass {
public static void main(String args[])throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t-->0){
String s[]=br.readLine().split(" ");
int n=Integer.parseInt(s[0]);
int m=Integer.parseInt(s[1]);
int sum=n*(m/3);
m=m%3;
sum+=m*(n/3);
n=n%3;
sum+=(m*n)/2;
if(m==n&&n==1) sum+=1;
System.out.println(sum);
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | d58305612e3f13b964ae5a5c08762681 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 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 x = sc.nextInt();
int y = sc.nextInt();
int ans = (int)Math.ceil((x*y)/3.0);
System.out.println(ans);
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 1f0cbadb2f93268a4e5a0674a3aa8fbe | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 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 x = sc.nextInt();
int y = sc.nextInt();
int ans = (int)Math.ceil((x*y)/3.0);
System.out.println(ans);
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | aa43c149ac48ab559ad9fc94daa8039e | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Solution {
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*m)%3==0)
System.out.println((n*m)/3);
else
System.out.println(((n*m)/3)+1);
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | fca5f1b991801b3c4e217e7b84c1c6ba | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
public class Main {
static class Pair {
int l,r;
public Pair(int l,int r) {
this.l=l;
this.r=r;
}
}
static int mod=1000000007;
public static void main(String[] args) throws IOException
{
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
static class TaskC
{
public static void solve(int testNumber, InputReader in, OutputWriter out)
{
int t=in.readInt();
while(t-->0)
{
int n=in.readInt();
int m=in.readInt();
if((n*m)%3!=0)
{
out.printLine(((n*m)/3)+1);
}
else
{
out.printLine((n*m)/3);
}
}
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int arraySize) {
int[] array = new int[arraySize];
for (int i = 0; i < arraySize; i++) {
array[i] = readInt();
}
return array;
}
public String readString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c)) {
res.appendCodePoint(c);
}
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isNewLine(int c) {
return c == '\n';
}
public String nextLine() {
int c = read();
StringBuilder result = new StringBuilder();
do {
result.appendCodePoint(c);
c = read();
} while (!isNewLine(c));
return result.toString();
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sign = 1;
if (c == '-') {
sign = -1;
c = read();
}
long result = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
result *= 10;
result += c & 15;
c = read();
} while (!isSpaceChar(c));
return result * sign;
}
public long[] nextLongArray(int arraySize) {
long array[] = new long[arraySize];
for (int i = 0; i < arraySize; i++) {
array[i] = nextLong();
}
return array;
}
public double nextDouble() {
double ret = 0, div = 1;
byte c = (byte) read();
while (c <= ' ') {
c = (byte) read();
}
boolean neg = (c == '-');
if (neg) {
c = (byte) read();
}
do {
ret = ret * 10 + c - '0';
} while ((c = (byte) read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = (byte) read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg) {
return -ret;
}
return ret;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class CP {
static boolean isPrime(long 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; (long) i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0)
return false;
}
return true;
}
static String addChar(String s, int n, String ch) {
String res =s+String.join("", Collections.nCopies(n, ch));
return res;
}
static int ifnotPrime(int[] prime, int x) {
return (prime[x / 64] & (1 << ((x >> 1) & 31)));
}
static void makeComposite(int[] prime, int x) {
prime[x / 64] |= (1 << ((x >> 1) & 31));
}
static ArrayList<Integer> bitWiseSieve(int n) {
ArrayList<Integer> al = new ArrayList<>();
int prime[] = new int[n / 64 + 1];
for (int i = 3; i * i <= n; i += 2) {
if (ifnotPrime(prime, i) == 0)
for (int j = i * i, k = i << 1;
j < n; j += k)
makeComposite(prime, j);
}
al.add(2);
for (int i = 3; i <= n; i += 2)
if (ifnotPrime(prime, i) == 0)
al.add(i);
return al;
}
public static long[] sort(long arr[]){
List<Long> list = new ArrayList<>();
for(long n : arr){list.add(n);}
Collections.sort(list);
for(int i=0;i<arr.length;i++){
arr[i] = list.get(i);
}
return arr;
}
static ArrayList<Integer> sieve(long size) {
ArrayList<Integer> pr = new ArrayList<Integer>();
boolean prime[] = new boolean[(int) size];
for (int i = 2; i < prime.length; i++) prime[i] = true;
for (int i = 2; i * i < prime.length; i++) {
if (prime[i]) {
for (int j = i * i; j < prime.length; j += i) {
prime[j] = false;
}
}
}
for (int i = 2; i < prime.length; i++) if (prime[i]) pr.add(i);
return pr;
}
static ArrayList<Integer> segmented_sieve(int l, int r, ArrayList<Integer> primes) {
ArrayList<Integer> al=new ArrayList<>();
if (l == 1) ++l;
int max = r - l + 1;
int arr[] = new int[max];
for (int p : primes) {
if (p * p <= r) {
int i = (l / p) * p;
if (i < l) i += p;
for (; i <= r; i += p) {
if (i != p) {
arr[i - l] = 1;
}
}
}
}
for (int i = 0; i < max; ++i) {
if (arr[i] == 0) {
al.add(l+i);
}
}
return al;
}
static boolean isfPrime(long n, int iteration) {
if (n == 0 || n == 1)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
Random rand = new Random();
for (int i = 0; i < iteration; i++) {
long r = Math.abs(rand.nextLong());
long a = r % (n - 1) + 1;
if (modPow(a, n - 1, n) != 1)
return false;
}
return true;
}
static long modPow(long a, long b, long c) {
long res = 1;
for (int i = 0; i < b; i++) {
res *= a;
res %= c;
}
return res % c;
}
private static long binPower(long a, long l, long mod) {
long res = 0;
while (l > 0) {
if ((l & 1) == 1) {
res = mulmod(res, a, mod);
;
l >>= 1;
}
a = mulmod(a, a, mod);
}
return res;
}
private static long mulmod(long a, long b, long c) {
long x = 0, y = a % c;
while (b > 0) {
if (b % 2 == 1) {
x = (x + y) % c;
}
y = (y * 2L) % c;
b /= 2;
}
return x % c;
}
static long binary_Expo(long a, long b) {
long res = 1;
while (b != 0) {
if ((b & 1) == 1) {
res *= a;
--b;
}
a *= a;
b /= 2;
}
return res;
}
static long Modular_Expo(long a, long b) {
long res = 1;
while (b != 0) {
if ((b & 1) == 1) {
res = (res * a) % 1000000007;
--b;
}
a = (a * a) % 1000000007;
b /= 2;
}
return res;
}
static int i_gcd(int a, int b) {
while (true) {
if (b == 0)
return a;
int c = a;
a = b;
b = c % b;
}
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static long ceil_div(long a, long b) {
return (a + b - 1) / b;
}
static int getIthBitFromInt(int bits, int i) {
return (bits >> (i - 1)) & 1;
}
private static TreeMap<Long, Long> primeFactorize(long n) {
TreeMap<Long, Long> pf = new TreeMap<>(Collections.reverseOrder());
long cnt = 0;
long total = 1;
for (long i = 2; (long) i * i <= n; ++i) {
if (n % i == 0) {
cnt = 0;
while (n % i == 0) {
++cnt;
n /= i;
}
pf.put(cnt, i);
//total*=(cnt+1);
}
}
if (n > 1) {
pf.put(1L, n);
//total*=2;
}
return pf;
}
static long upper_Bound(long a[], long x) {
long l = -1, r = a.length;
while (l + 1 < r) {
long m = (l + r) >>> 1;
if (a[(int) m] <= x)
l = m;
else
r = m;
}
return l + 1;
}
static int upper_Bound(List<Integer> a, int x) {
int l = -1, r = a.size();
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (a.get(m) < x)
l = m;
else
r = m;
}
return l + 1;
}
static int lower_Bound(int a[],int x) {
int l = -1, r = a.length;
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (a[(int) m] >= x)
r = m;
else
l = m;
}
return r;
}
static int upperBound(int a[], int x) {// x is the key or target value
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]<=x) l=m;
else r=m;
}
return l+1;
}
static int bsh(int a[],int t) {
int ans =-1;
int i = 0, j = a.length - 1;
while (i <= j) {
int mid = i + (j - i) / 2;
if (a[mid] > t) {
ans = mid;
System.out.print("uppr "+a[ans]);
j=mid-1;
}
else{
System.out.print("less "+a[mid]);
i=mid+1;
}
}
return ans;
}
static int bsl(long a[],long t) {
int ans =-1;
int i = 1, j = a.length-1;
while (i <= j) {
int mid = i + (j - i) / 2;
if (a[mid] == t) {
ans = mid;
break;
} else if (a[mid] > t) {
j = mid - 1;
} else {
ans=mid;
i = mid + 1;
}
}
return ans;
}
static int lower_Bound(ArrayList<Long> a, long x) //closest to the right
{
int l = -1, r = a.size();
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (a.get(m) >= x)
r = m;
else
l = m;
}
return r;
}
static boolean isSquarefactor(int x, int factor, int target) {
int s = (int) Math.round(Math.sqrt(x));
return factor * s * s == target;
}
static boolean isSquare(int x) {
int s = (int) Math.round(Math.sqrt(x));
return x * x == s;
}
static void sort(int a[]) // heap sort
{
PriorityQueue<Integer> q = new PriorityQueue<>();
for (int i = 0; i < a.length; i++)
q.add(a[i]);
for (int i = 0; i < a.length; i++)
a[i] = q.poll();
}
static void shuffle(int[] in) {
for (int i = 0; i < in.length; i++) {
int idx = (int) (Math.random() * in.length);
fast_swap(in, idx, i);
}
}
static boolean isPalindrome(String s)
{
StringBuilder sb=new StringBuilder(s);
sb.reverse();
if(s.equals(sb.toString()))
{
return true;
}
return false;
}
static int[] computeLps(String pat) {
int len = 0, i = 1, m = pat.length();
int lps[] = new int[m];
lps[0] = 0;
while (i < m) {
if (pat.charAt(i) == pat.charAt(len)) {
++len;
lps[i] = len;
++i;
} else {
if (len != 0) {
len = lps[len - 1];
} else {
lps[i] = len;
++i;
}
}
}
return lps;
}
static boolean kmp(String s, String pat) {
int n = s.length(), m = pat.length();
int lps[] = computeLps(pat);
int i = 0, j = 0;
while (i < n) {
if (s.charAt(i) == pat.charAt(j)) {
i++;
j++;
if (j == m) {
return true;
}
} else {
if (j != 0) {
j = lps[j - 1];
} else {
i++;
}
}
}
return false;
}
static void reverse_ruffle_sort(int a[]) {
shuffle(a);
Arrays.sort(a);
for (int l = 0, r = a.length - 1; l < r; ++l, --r)
fast_swap(a, l, r);
}
static void ruffle_sort(int a[]) {
shuffle(a);
Arrays.sort(a);
}
static int getMax(int arr[], int n) {
int mx = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] > mx)
mx = arr[i];
return mx;
}
static ArrayList<Long> primeFactors(long n) {
ArrayList<Long> al = new ArrayList<>();
al.add(1L);
while (n % 2 == 0) {
if(!al.contains(2L))
{
al.add(2L);
}
n /= 2L;
}
for (int i = 3; (long) i * i <= n; i += 2) {
while ((n % i == 0)) {
if(!al.contains((long)i))
{
al.add((long) i);
}
n /= i;
}
}
if (n > 2) {
if(!al.contains(n))
{
al.add(n);
}
}
return al;
}
static int[] z_function(String s) {
int n = s.length(), z[] = new int[n];
for (int i = 1, l = 0, r = 0; i < n; ++i) {
if (i <= r)
z[i] = Math.min(z[i - l], r - i + 1);
while (i + z[i] < n && s.charAt(z[i]) == s.charAt(i + z[i]))
++z[i];
if (i + z[i] - 1 > r) {
l = i;
r = i + z[i] - 1;
}
}
return z;
}
static void swap(int a[], int idx1, int idx2) {
a[idx1] += a[idx2];
a[idx2] = a[idx1] - a[idx2];
a[idx1] -= a[idx2];
}
static void fast_swap(int[] a, int idx1, int idx2) {
if (a[idx1] == a[idx2])
return;
a[idx1] ^= a[idx2];
a[idx2] ^= a[idx1];
a[idx1] ^= a[idx2];
}
public static void fast_sort(long[] array) {
ArrayList<Long> copy = new ArrayList<>();
for (long i : array)
copy.add(i);
Collections.sort(copy);
for (int i = 0; i < array.length; i++)
array[i] = copy.get(i);
}
static int divCount(int n) {
boolean hash[] = new boolean[n + 1];
Arrays.fill(hash, true);
for (int p = 2; p * p < n; p++)
if (hash[p] == true)
for (int i = p * 2; i < n; i += p)
hash[i] = false;
int total = 1;
for (int p = 2; p <= n; p++) {
if (hash[p]) {
int count = 0;
if (n % p == 0) {
while (n % p == 0) {
n = n / p;
count++;
}
total = total * (count + 1);
}
}
}
return total;
}
static long binomialCoeff(int n,int k)
{
long res = 1;
// Since C(n, k) = C(n, n-k)
if (k > n - k)
k = n - k;
// Calculate value of
// [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
for (int i = 0; i < k; ++i) {
res = (res%mod*(n - i)%mod)%mod;
res /= (i + 1);
}
return res%mod;
}
static long c(long fact[],int n,int k)
{
if(k>n) return 0;
long res=fact[n];
res= (int) ((res * Modular_Expo(fact[k], mod - 2))%mod);
res= (int) ((res * Modular_Expo(fact[n - k], mod - 2))%mod);
return res%mod;
}
public static ArrayList<Long> getFactors(long x) {
ArrayList<Long> facts=new ArrayList<>();
for(long i=2;i*i<=x;++i)
{
if(x%i==0)
{
facts.add(i);
if(i!=x/i)
{
facts.add(x/i);
}
}
}
return facts;
}
public static HashMap<Integer, Integer> sortMap(HashMap<Integer, Integer> map) {
List<Map.Entry<Integer,Integer>> list=new LinkedList<>(map.entrySet());
Collections.sort(list,(o1,o2)->o2.getValue()-o1.getValue());
HashMap<Integer,Integer> temp=new LinkedHashMap<>();
for(Map.Entry<Integer,Integer> i:list)
{
temp.put(i.getKey(),i.getValue());
}
return temp;
}
public static long lcm(long l,long l2) {
long val=CP.gcd(l,l2);
return (l*l2)/val;
}
}
static void py() {
System.out.println("YES");
}
static void pn() {
System.out.println("NO");
}
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(int[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void printLine(int[] array) {
print(array);
writer.println();
}
public void close() {
writer.close();
}
public void printLine(long i) {
writer.println(i);
}
public void printLine(int i) {
writer.println(i);
}
public void printLine(char c)
{
writer.println(c);
}
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();
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 68f23a9834a1b23d18141679a3dc6ba5 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Set;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class B_Coloring_Rectangles {
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) {
try {
FastReader s = new FastReader();
int t = s.nextInt();
while (t-- > 0) {
int n = s.nextInt();
int m = s.nextInt();
if ((n * m) % 3 == 0) {
System.out.println(n * m / 3);
}
else {
System.out.println((n*m/3)+1);
}
}
} catch (Exception e) {
return;
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 8e55a10ea6e0ea8064043b37b7d89e41 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
static PrintWriter out = new PrintWriter((System.out));
static Kioken sc = new Kioken();
public static void main(String[] args) {
int t = 1;
t = sc.nextInt();
while (t-- > 0) {
solve();
}
out.close();
}
public static int check(int max, int min){
if (max < 3) {
// 1,2 , 2,2
if (min == 1) {
// out.println(1);
return 1;
} else {
// out.println(2);
return 2;
}
}
return 0;
}
public static void solve() {
int r = sc.nextInt();
int c = sc.nextInt();
int max = Math.max(r, c);
int min = Math.min(r, c);
int ans = solve(max, min);
out.println(ans);
}
static int solve(int max, int min) {
if(check(max, min) > 0){
return check(max, min);
}
int q = max % 3;
int qq = max / 3;
// out.println(q + " min " + qq);
if (q > 0) {
int total = qq*min;
if (q == 1) {
if (min == 1) {
total += 1;
} else {
int newMin = Math.min(q, min);
int newMax = Math.max(q, min);
total += solve(newMax, newMin);
}
} else if (q == 2) {
int newMin = Math.min(q, min);
int newMax = Math.max(q, min);
total += solve(newMax, newMin);
// total += solve(q, min);
}
return total;
// out.println(total);
} else {
int total = qq * min;
return total;
// out.println(total);
}
}
public static long leftShift(long a) {
return (long) Math.pow(2, a);
}
public static int lower_bound(ArrayList<Integer> ar, int k) {
int s = 0, e = ar.size();
while (s != e) {
int mid = s + e >> 1;
if (ar.get(mid) <= k) {
s = mid + 1;
} else {
e = mid;
}
}
return Math.abs(s) - 1;
}
public static int upper_bound(ArrayList<Integer> ar, int k) {
int s = 0;
int e = ar.size();
while (s != e) {
int mid = s + e >> 1;
if (ar.get(mid) < k) {
s = mid + 1;
} else {
e = mid;
}
}
if (s == ar.size()) {
return -1;
}
return s;
}
static class Kioken {
// FileInputStream br = new FileInputStream("input.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public String next() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
try {
return br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public boolean hasNext() {
String next = null;
try {
next = br.readLine();
} catch (Exception e) {
}
if (next == null || next.length() == 0) {
return false;
}
st = new StringTokenizer(next);
return true;
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 2b107b05bf454ad42053f12d3843b52f | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.util.Locale;
import java.util.StringTokenizer;
public class B {
private void solve() {
int n = readInt();
for (int i = 0; i < n; i++) {
int height = readInt();
int width = readInt();
int square = height * width;
for(int j = square/3; j >= 0; j--) {
if ((square - j*3) % 2 == 0) {
int tri = j;
int dva = (square - j*3)/2;
out.println(tri + dva);
break;
}
}
}
}
//////////////////////////////////////////////////////////////////
long sqrtLong(long x) {
long root = (long)Math.sqrt(x);
while (root * root > x) --root;
while ((root + 1) * (root + 1) <= x) ++root;
return root;
}
//////////////////////////////////////////////////////////////////
private boolean yesNo(boolean yes) {
return yesNo(yes, "YES", "NO");
}
private boolean yesNo(boolean yes, String yesString, String noString) {
out.println(yes ? yesString : noString);
return yes;
}
//////////////////////////////////////////////////////////////////
private long readLong() {
return Long.parseLong(readString());
}
private int[] readIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; ++i) a[i] = readInt();
return a;
}
private int readInt() {
return Integer.parseInt(readString());
}
private String readString() {
while (!tok.hasMoreTokens()) {
String nextLine = readLine();
if (null == nextLine) return null;
tok = new StringTokenizer(nextLine);
}
return tok.nextToken();
}
private String readLine() {
try {
return in.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
//////////////////////////////////////////////////////////////////
private BufferedReader in;
private StringTokenizer tok;
private PrintWriter out;
private void initFileIO(String inputFileName, String outputFileName) throws FileNotFoundException {
in = new BufferedReader(new FileReader(inputFileName));
out = new PrintWriter(outputFileName);
}
private void initConsoleIO() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
private void initIO() throws IOException {
Locale.setDefault(Locale.US);
String fileName = "";
if (!fileName.isEmpty()) {
initFileIO(fileName + ".in", fileName + ".out");
} else {
if (new File("input.txt").exists()) {
initFileIO("input.txt", "output.txt");
} else {
initConsoleIO();
}
}
tok = new StringTokenizer("");
}
//////////////////////////////////////////////////////////////////
private void run() {
try {
long timeStart = System.currentTimeMillis();
initIO();
solve();
out.close();
long timeEnd = System.currentTimeMillis();
System.err.println("Time(ms) = " + (timeEnd - timeStart));
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
new B().run();
}
/////////////////////////////////////////////////////////////////
private static boolean isPrime(int input) {
if (input % 2 == 0) return input == 2;
int d = 3;
while (d * d < Math.sqrt(input) + 1) {
if (input % d == 0) return false;
d += 2;
}
return true;
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 4f5e0298ad7e7ad662b5217ef6af49a6 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class GG {
public static int vv(int a, int b){
if (b==1){
if (a%3==0) return a/3;
else return a/3+1;
} else {
if (a==2 && b==2) return 2;
else {
int k=0;
k+=(a/3)*b;
a-=(a/3)*3;
if (a==0) return k;
else return k+vv(b, a);
}
}
}
public static void main(String[] args) throws IOException {
Scanner scanner=new Scanner(System.in);
int d = scanner.nextInt();
for (int i=0; i<d; i++) {
int n = scanner.nextInt();
int m = scanner.nextInt();
if (n > m) {
System.out.println(vv(n, m));
} else {
System.out.println(vv(m, n));
}
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 11 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 9d0cdf5bb0eb953b73444d21f2744c46 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
import java.io.*;
public class B {
public static void main(String[] args) throws IOException {
Reader sc = new Reader();
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-- > 0) {
int n = sc.nextInt(), m = sc.nextInt();
if(n == 1) {
if(m >= 3)
out.println((int)Math.ceil(m / 3.0));
else
out.println(1);
}
else if(n == 2) {
if(m >= 3)
out.println(((m / 3) * n) + (m % 3));
else
out.println(m % 3);
}
else if(n % 3 == 0)
out.println(m * (n / 3));
else {
if(m == 1)
out.println((int)Math.ceil(n / 3.0));
else {
if(m % 3 == 0)
out.println(((n / 3) * m) + ((m / 3) * (n % 3)));
else
out.println(((n / 3) * m) + ((m / 3) * (n % 3)) + Math.min((n % 3),(m % 3)));
}
}
out.flush();
}
}
static class Reader {
BufferedReader br;
StringTokenizer st;
public Reader() {
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;
}
}
}
// ********************* GCD Function *********************
//int gcd(int a, int b){
// if (b == 0)
// return a;
// return gcd(b, a % b);
//}
// ********************* Prime Number Function *********************
//int isPrime(int n){
// if(n < 2)
// return 0;
// if(n < 4)
// return 1;
// if(n % 2 == 0 or n % 3 == 0)
// return 0;
// for(int i = 5; i*i <= n; i += 6)
// if(n % i == 0 or n % (i+2) == 0)
// return 0;
// return 1;
//}
// ********************* Custom Pair Class *********************
//class Pair implements Comparable<Pair> {
// int a,b;
// public Pair(int a,int b) {
// this.a = a;
// this.b = b;
// }
// @Override
// public int compareTo(Pair other) {
//// if(this.b == other.b)
//// return Integer.compare(this.a,other.a);
// return Integer.compare(other.b,this.b);
// }
//}
// ****************** Segment Tree ******************
//public class SegmentTreeNode {
// public SegmentTreeNode left;
// public SegmentTreeNode right;
// public int Start;
// public int End;
// public int Sum;
// public SegmentTreeNode(int start, int end) {
// Start = start;
// End = end;
// Sum = 0;
// }
//}
//public SegmentTreeNode buildTree(int start, int end) {
// if(start > end)
// return null;
// SegmentTreeNode node = new SegmentTreeNode(start, end);
// if(start == end)
// return node;
// int mid = start + (end - start) / 2;
// node.left = buildTree(start, mid);
// node.right = buildTree(mid + 1, end);
// return node;
//}
//public void update(SegmentTreeNode node, int index) {
// if(node == null)
// return;
// if(node.Start == index && node.End == index) {
// node.Sum += 1;
// return;
// }
// int mid = node.Start + (node.End - node.Start) / 2;
// if(index <= mid)
// update(node.left, index);
// else
// update(node.right, index);
// node.Sum = node.left.Sum + node.right.Sum;
//}
//public int SumRange(SegmentTreeNode root, int start, int end) {
// if(root == null || start > end)
// return 0;
// if(root.Start == start && root.End == end)
// return root.Sum;
// int mid = root.Start + (root.End - root.Start) / 2;
// if(end <= mid)
// return SumRange(root.left, start, end);
// else if(start > mid)
// return SumRange(root.right, start, end);
// return SumRange(root.left, start, mid) + SumRange(root.right, mid + 1, end);
//} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 3dcfab023ecc2cbbe1a740c85e4685d2 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.util.*;
public class A {
public static long gcd(long a, long b) {
return a == 0 ? b : gcd(b, a % b);
}
public static void print(int[] a) {
PrintWriter out = new PrintWriter(System.out);
for (int i = 0; i < a.length; i++) {
out.print(a[i] + " ");
}
out.println();
out.close();
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t1 = sc.nextInt();
while (t1-- > 0) {
int n = sc.nextInt();
int m = sc.nextInt();
out.println((long)Math.ceil((n*m)/3.0));
}
out.close();
}
static class Pair implements Comparable<Pair> {
long first;
long second;
public Pair(long first, long second) {
this.first = first;
this.second = second;
}
public int compareTo(Pair p) {
if (first != p.first)
return Long.compare(first, p.first);
else if (second != p.second)
return Long.compare(second, p.second);
else
return 0;
}
}
static final Random random = new Random();
static void shuffleSort(int[] a) {
int n = a.length;
for (int i = 0; i < n; i++) {
int r = random.nextInt(n), temp = a[r];
a[r] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public 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 boolean ready() throws IOException {
return br.ready();
}
long[] readArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 4fc93cf7a3b5591cb69b30d352e29b8f | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
public class ColoringRectrangle {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int m=sc.nextInt();
System.out.println((int)Math.ceil((n*m)/3.0));
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 5b5d977e8e2ea26802ba98d8ab562d4b | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;import java.io.*;import java.math.*;
public class CF1584B
{
static boolean memory = true;
static long mod = 998244353;
static long MOD = 1000000007;
static void ruffleSort(int[] a) {
int n = a.length;
ArrayList<Integer> lst = new ArrayList<>();
for(int i : a)
lst.add(i);
Collections.sort(lst);
for(int i = 0; i < n; i++)
a[i] = lst.get(i);
}
static void ruffleSort(long[] a) {
int n = a.length;
ArrayList<Long> lst = new ArrayList<>();
for(long i : a)
lst.add(i);
Collections.sort(lst);
for(int i = 0; i < n; i++)
a[i] = lst.get(i);
}
public static void process()throws IOException
{
int n = ni(), m = ni();
pn((n*m+2)/3);
}
static AnotherReader sc;
static PrintWriter out;
public static void main(String[] args) throws Exception{
if(memory)new Thread(null, new Runnable() {public void run(){try{new CF1584B().run();}catch(Exception e){e.printStackTrace();System.exit(1);}}}, "1", 1 << 32).start();
else new CF1584B().run();
}
void run()throws Exception
{
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
long s = System.currentTimeMillis();
int t=1;
t=ni();
//int k = t;
while(t-->0) {/*p("Case #"+ (k-t) + ": ")*/;process();}
out.flush();
System.err.println(System.currentTimeMillis()-s+"ms");
out.close();
}
static long power(long k, long c, long mod){
long y = 1;
while(c > 0){
if(c%2 == 1)
y = y * k % mod;
c = c/2;
k = k * k % mod;
}
return y;
}
static int power(int x, int y, int p){
int res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
static int log2(int N)
{
int result = (int)(Math.log(N) / Math.log(2));
return result;
}
static void pn(Object o){out.println(o);}
static void pn(int[] a){for(int i : a)out.print(i+" ");pn("");}
static void pn(long[] a){for(long i : a)out.print(i+" ");pn("");}
static void p(Object o){out.print(o);}
static void YES(){out.println("YES");}
static void NO(){out.println("NO");}
static void yes(){out.println("yes");}
static void no(){out.println("no");}
static void p(int[] a){for(int i : a)out.print(i+" ");}
static void p(long[] a){for(long i : a)out.print(i+" ");}
static void pni(Object o){out.println(o);out.flush();}
static int ni()throws IOException{return sc.nextInt();}
static long nl()throws IOException{return sc.nextLong();}
static double nd()throws IOException{return sc.nextDouble();}
static String nln()throws IOException{return sc.nextLine();}
static String ns()throws IOException{return sc.next();}
static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static class AnotherReader{BufferedReader br; StringTokenizer st;
AnotherReader()throws FileNotFoundException{
br=new BufferedReader(new InputStreamReader(System.in));}
AnotherReader(int a)throws FileNotFoundException{
br = new BufferedReader(new FileReader("input.txt"));}
String next()throws IOException{
while (st == null || !st.hasMoreElements()) {try{
st = new StringTokenizer(br.readLine());}
catch (IOException e){ e.printStackTrace(); }}
return st.nextToken(); } int nextInt() throws IOException{
return Integer.parseInt(next());}
long nextLong() throws IOException
{return Long.parseLong(next());}
double nextDouble()throws IOException { return Double.parseDouble(next()); }
String nextLine() throws IOException{ String str = ""; try{
str = br.readLine();} catch (IOException e){
e.printStackTrace();} return str;}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | eec1da0b63ebc4ebf7847ea45dcf1913 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t-->0) {
int n=s.nextInt();
int m=s.nextInt();
System.out.println(func(n,m));
}
}
public static int func(int n,int m) {
if(n*m%3!=0)
return (n*m/3)+1;
else return n*m/3;
// if(n==1 && m==1)
// return 0;
// else if(n==1) {
// if(m>3) {
// if(m%3==0)
// return m/3;
// else
// return (m/3)+1;
// }
// else
// return m/2;
// }
// else if(m==1) {
// if(n>3)
// if(n%3==0)
// return n/3;
// else return (n/3)+1;
// else
// return n/2;
// }
// else {
// int a=(func(1,m))*(n);
// int b=(m)*(func(n,1));
// return Math.min(a, b);
// }
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 25804f8d7a307669691290c3a87467e8 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
public class ColouringRectangles
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int out[] = new int[t];
for(int i = 0; i<t; i++)
{
int n = sc.nextInt();
int m = sc.nextInt();
out[i] = (n*m+2)/3;
}
for(int i = 0; i<t; i++)
{
System.out.println(out[i]);
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 6b848e7085fdc2bed9765d337265acfe | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
public class ColouringRectangles
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int out[] = new int[t];
for(int i = 0; i<t; i++)
{
int n = sc.nextInt();
int m = sc.nextInt();
out[i] = minpaint(n,m);
}
for(int i = 0; i<t; i++)
{
System.out.println(out[i]);
}
}
public static int minpaint(int n, int m)
{
//int a =(int)(m/3 + 0.5*(m-3*(m/3)));
//int b =n/3;
//int x = m*(n/3) + (n-3*(n/3))*a;
return (n*m+2)/3;
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 57e8e823adb8cd9fee918e763f8aa10a | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static class Pair implements Comparable < Pair > {
int d;
int i;
Pair(int d, int i) {
this.d = d;
this.i = i;
}
public int compareTo(Pair o) {
return this.d - o.d;
}
}
public static class SegmentTree {
long[] st;
long[] lazy;
int n;
SegmentTree(long[] arr, int n) {
this.n = n;
st = new long[4 * n];
lazy = new long[4 * n];
construct(arr, 0, n - 1, 0);
}
public long construct(long[] arr, int si, int ei, int node) {
if (si == ei) {
st[node] = arr[si];
return arr[si];
}
int mid = (si + ei) / 2;
long left = construct(arr, si, mid, 2 * node + 1);
long right = construct(arr, mid + 1, ei, 2 * node + 2);
st[node] = left + right;
return st[node];
}
public long get(int l, int r) {
return get(0, n - 1, l, r, 0);
}
public long get(int si, int ei, int l, int r, int node) {
if (r < si || l > ei)
return 0;
if (lazy[node] != 0) {
st[node] += lazy[node] * (ei - si + 1);
if (si != ei) {
lazy[2 * node + 1] += lazy[node];
lazy[2 * node + 2] += lazy[node];
}
lazy[node] = 0;
}
if (l <= si && r >= ei)
return st[node];
int mid = (si + ei) / 2;
return get(si, mid, l, r, 2 * node + 1) + get(mid + 1, ei, l, r, 2 * node + 2);
}
public void update(int index, int value) {
update(0, n - 1, index, 0, value);
}
public void update(int si, int ei, int index, int node, int val) {
if (si == ei) {
st[node] = val;
return;
}
int mid = (si + ei) / 2;
if (index <= mid) {
update(si, mid, index, 2 * node + 1, val);
} else {
update(mid + 1, ei, index, 2 * node + 2, val);
}
st[node] = st[2 * node + 1] + st[2 * node + 2];
}
public void rangeUpdate(int l, int r, int val) {
rangeUpdate(0, n - 1, l, r, 0, val);
}
public void rangeUpdate(int si, int ei, int l, int r, int node, int val) {
if (r < si || l > ei)
return;
if (lazy[node] != 0) {
st[node] += lazy[node] * (ei - si + 1);
if (si != ei) {
lazy[2 * node + 1] += lazy[node];
lazy[2 * node + 2] += lazy[node];
}
lazy[node] = 0;
}
if (l <= si && r >= ei) {
st[node] += val * (ei - si + 1);
if (si != ei) {
lazy[2 * node + 1] += val;
lazy[2 * node + 2] += val;
}
return;
}
int mid = (si + ei) / 2;
rangeUpdate(si, mid, l, r, 2 * node + 1, val);
rangeUpdate(mid + 1, ei, l, r, 2 * node + 2, val);
st[node] = st[2 * node + 1] + st[2 * node + 2];
}
}
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
} else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
public static void main(String[] args) throws IOException {
if (System.getProperty("ONLINE_JUDGE") == null) {
try {
System.setIn(new FileInputStream(new File("input.txt")));
System.setOut(new PrintStream(new File("output.txt")));
} catch (Exception e) {
}
}
Reader sc = new Reader();
int tc = sc.nextInt();
StringBuilder sb = new StringBuilder();
while (tc-- > 0) {
long a = sc.nextLong();
long b = sc.nextLong();
sb.append((long)Math.ceil((a * b) / 3.0));
sb.append("\n");
}
System.out.println(sb);
}
public static boolean isEqual(HashMap<Integer, Integer> a, HashMap<Integer, Integer> b) {
if (a.size() != b.size())
return false;
for (int key : a.keySet())
if (a.getOrDefault(key, 0) != b.getOrDefault(key, 0))
return false;
return true;
}
public static double digit(long num) {
return Math.floor(Math.log10(num) + 1);
}
public static int count(ArrayList<Integer> al, int num) {
if (al.get(al.size() - 1) == num)
return 0;
int k = al.get(al.size() - 1);
ArrayList<Integer> temp = new ArrayList<>();
for (int i = 0; i < al.size(); i++) {
if (al.get(i) > k)
temp.add(al.get(i));
}
return 1 + count(temp, num);
}
public static String Util(String s) {
for (int i = s.length() - 1; i >= 1; i--) {
int l = s.charAt(i - 1) - '0';
int r = s.charAt(i) - '0';
if (l + r >= 10) {
return s.substring(0, i - 1) + (l + r) + s.substring(i + 1);
}
}
int l = s.charAt(0) - '0';
int r = s.charAt(1) - '0';
return (l + r) + s.substring(2);
}
public static boolean isPos(int idx, long[] arr, long[] diff) {
if (idx == 0) {
for (int i = 0; i <= Math.min(arr[0], arr[1]); i++) {
diff[idx] = i;
arr[0] -= i;
arr[1] -= i;
if (isPos(idx + 1, arr, diff)) {
return true;
}
arr[0] += i;
arr[1] += i;
}
} else if (idx == 1) {
if (arr[2] - arr[1] >= 0) {
long k = arr[1];
diff[idx] = k;
arr[1] = 0;
arr[2] -= k;
if (isPos(idx + 1, arr, diff)) {
return true;
}
arr[1] = k;
arr[2] += k;
} else
return false;
} else {
if (arr[2] == arr[0] && arr[1] == 0) {
diff[2] = arr[2];
return true;
} else {
return false;
}
}
return false;
}
public static boolean isPal(String s) {
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != s.charAt(s.length() - 1 - i))
return false;
}
return true;
}
static int upperBound(ArrayList<Long> arr, long key) {
int mid, N = arr.size();
// Initialise starting index and
// ending index
int low = 0;
int high = N;
// Till low is less than high
while (low < high && low != N) {
// Find the index of the middle element
mid = low + (high - low) / 2;
// If key is greater than or equal
// to arr[mid], then find in
// right subarray
if (key >= arr.get(mid)) {
low = mid + 1;
}
// If key is less than arr[mid]
// then find in left subarray
else {
high = mid;
}
}
// If key is greater than last element which is
// array[n-1] then upper bound
// does not exists in the array
return low;
}
static int lowerBound(ArrayList<Long> array, long key) {
// Initialize starting index and
// ending index
int low = 0, high = array.size();
int mid;
// Till high does not crosses low
while (low < high) {
// Find the index of the middle element
mid = low + (high - low) / 2;
// If key is less than or equal
// to array[mid], then find in
// left subarray
if (key <= array.get(mid)) {
high = mid;
}
// If key is greater than array[mid],
// then find in right subarray
else {
low = mid + 1;
}
}
// If key is greater than last element which is
// array[n-1] then lower bound
// does not exists in the array
if (low < array.size() && array.get(low) < key) {
low++;
}
// Returning the lower_bound index
return low;
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 1bb4111ce5d01aeb5d1400dfd2d05e56 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes |
import java.util.Scanner;
public class Problem1584B {
public static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int tc = scanner.nextInt();
while (tc-->0) {
int row = scanner.nextInt();
int column = scanner.nextInt();
int ans = 0;
int mul = row*column;
if (mul%3==0){
ans = mul/3;
}else {
ans= (mul/3)+1;
}
System.out.println(ans);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | fc58f97c6c9b6a86aa1e3915bc9ae0de | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-- > 0){
String[] s = br.readLine().split(" ");
int a = Integer.parseInt(s[0]);
int b = Integer.parseInt(s[1]);
int area = a * b;
int ans1 = area/3;
if(area % 3 != 0 ){
ans1 +=1;
}
System.out.println(ans1);
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | b3f9ee3a3ad26e0d93b105dff6c51ad8 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader a = new FastReader();
int test = a.nextInt();
while (test-- > 0) {
int row = a.nextInt();
int col = a.nextInt();
int ans = (row*col)/3;
ans = (row*col)%3!=0?ans+1:ans;
System.out.println(ans);
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 04f4a86e51374003b5c2e7073101bb1e | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigInteger;
//code by tishrah_
public class _practise {
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());
}
int[] ia(int n)
{
int a[]=new int[n];
for(int i=0;i<n;i++)a[i]=nextInt();
return a;
}
int[][] ia(int n , int m)
{
int a[][]=new int[n][m];
for(int i=0;i<n;i++) for(int j=0;j<m ;j++) a[i][j]=nextInt();
return a;
}
long[][] la(int n , int m)
{
long a[][]=new long[n][m];
for(int i=0;i<n;i++) for(int j=0;j<m ;j++) a[i][j]=nextLong();
return a;
}
char[][] ca(int n , int m)
{
char a[][]=new char[n][m];
for(int i=0;i<n;i++)
{
String x =next();
for(int j=0;j<m ;j++) a[i][j]=x.charAt(j);
}
return a;
}
long[] la(int n)
{
long a[]=new long[n];
for(int i=0;i<n;i++)a[i]=nextLong();
return a;
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static void sort(long[] a)
{int n=a.length;Random r=new Random();for (int i=0; i<a.length; i++) {long oi=r.nextInt(n), temp=a[i];a[i]=a[(int)oi];a[(int)oi]=temp;}Arrays.sort(a);}
static void sort(int[] a)
{int n=a.length;Random r=new Random();for (int i=0; i<a.length; i++) {int oi=r.nextInt(n), temp=a[i];a[i]=a[oi];a[oi]=temp;}Arrays.sort(a);}
public static long sum(long a[])
{long sum=0; for(long i : a) sum+=i; return(sum);}
public static long count(long a[] , long x)
{long c=0; for(long i : a) if(i==x) c++; return(c);}
public static int sum(int a[])
{ int sum=0; for(int i : a) sum+=i; return(sum);}
public static int count(int a[] ,int x)
{int c=0; for(int i : a) if(i==x) c++; return(c);}
public static int count(String s ,char ch)
{int c=0; char x[] = s.toCharArray(); for(char i : x) if(ch==i) c++; return(c);}
public static boolean prime(int n)
{for(int i=2 ; i<=Math.sqrt(n) ; i++) if(n%i==0) return false; return true;}
public static boolean prime(long n)
{for(long i=2 ; i<=Math.sqrt(n) ; i++) if(n%i==0) return false; return true;}
public static int gcd(int n1, int n2)
{ if (n2 != 0)return gcd(n2, n1 % n2); else return n1;}
public static long gcd(long n1, long n2)
{ if (n2 != 0)return gcd(n2, n1 % n2); else return n1;}
public static int[] freq(int a[], int n)
{ int f[]=new int[n+1]; for(int i:a) f[i]++; return f;}
public static int[] pos(int a[], int n)
{ int f[]=new int[n+1]; for(int i=0; i<n ;i++) f[a[i]]=i; return f;}
public static long mindig(long n)
{
long ans=9; while(n>0) { if(n%10<ans) ans=n%10; n/=10; }
return ans;
}
public static long maxdig(long n)
{
long ans=0; while(n>0) { if(n%10>ans) ans=n%10; n/=10; }
return ans;
}
public static boolean palin(String s)
{
StringBuilder sb = new StringBuilder();
sb.append(s);
String str=String.valueOf(sb.reverse());
if(s.equals(str))
return true;
else return false;
}
public static void main(String args[])
{
FastReader in=new FastReader();
PrintWriter so = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
_practise ob = new _practise();
int T = in.nextInt();
// int T = 1;
tc : while(T-->0)
{
int n = in.nextInt();
int m = in.nextInt();
so.println((n*m+2)/3);
}
so.flush();
/*String s = in.next();
* Arrays.stream(f).min().getAsInt()
* BigInteger f = new BigInteger("1"); 1 ke jagah koi bhi value ho skta jo aap
* initial value banan chahte
int a[] = new int[n];
Stack<Integer> stack = new Stack<Integer>();
Deque<Integer> q = new LinkedList<>(); or Deque<Integer> q = new ArrayDeque<Integer>();
PriorityQueue<Long> pq = new PriorityQueue<Long>();
ArrayList<Integer> al = new ArrayList<Integer>();
StringBuilder sb = new StringBuilder();
HashSet<Integer> st = new LinkedHashSet<Integer>();
Set<Integer> s = new HashSet<Integer>();
Map<Long,Integer> hm = new HashMap<Long, Integer>(); //<key,value>
for(Map.Entry<Integer, Integer> i :hm.entrySet())
HashMap<Integer, Integer> hmap = new HashMap<Integer, Integer>();
so.println("HELLO");
Arrays.sort(a,Comparator.comparingDouble(o->o[0]))
Arrays.sort(a, (aa, bb) -> Integer.compare(aa[1], bb[1]));
Set<String> ts = new TreeSet<>();*/
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 186f6db6009e88f04277cc5f13784135 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
new Thread(null, () -> new Main().run(), "1", 1 << 23).start();
}
private void run() {
FastReader scan = new FastReader();
PrintWriter out = new PrintWriter(System.out);
Solution solve = new Solution();
int t = scan.nextInt();
// int t = 1;
for (int qq = 0; qq < t; qq++) {
solve.solve(scan, out);
out.println();
}
out.close();
}
}
class Solution {
/*
* think and coding
*/
static long MOD = (long) (1e9);
double EPS = 0.000_0001;
int numberCount = 1;
public void solve(FastReader scan, PrintWriter out) {
int n = scan.nextInt(), m = scan.nextInt();
int s = n * m;
if (s % 3 == 0) {
out.println(s / 3);
} else {
out.println(s / 3 + 1);
}
}
int lower(int val, Pair[] arr) {
int l = -1, r = arr.length;
while (r - l > 1) {
int mid = (r + l) / 2;
if (arr[mid].a < val) {
l = mid;
} else r = mid;
}
return r;
}
static class Pair implements Comparable<Pair> {
int a, b;
public Pair(int a, int b) {
this.a = a;
this.b = b;
}
public Pair(Pair p) {
this.a = p.a;
this.b = p.b;
}
@Override
public int compareTo(Pair p) {
return Integer.compare(a, p.a);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair pair = (Pair) o;
return a == pair.a && b == pair.b;
}
@Override
public int hashCode() {
return Objects.hash(a, b);
}
@Override
public String toString() {
return "Pair{" + "a=" + a + ", b=" + b + '}';
}
}
}
class FastReader {
private final BufferedReader br;
private StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws FileNotFoundException {
br = new BufferedReader(new FileReader(new File(s)));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] initInt(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
long[] initLong(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 91d8e2d8644103de9fc39ff9ec2ad2b1 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | // package CP;
import java.util.*;
public class Practice {
static long pow(long a, long b) {
if (b == 0) {
return 1;
}
long ans = 0L;
if (b % 2 == 0) {
long val = pow(a, b / 2);
ans += val * val;
} else {
long val = pow(a, b / 2);
ans += val * val * 2;
}
return ans;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
// sc.nextLine();
while (t-- != 0) {
int n=sc.nextInt();
int m=sc.nextInt();
if((n*m)%3==0){
System.out.println((n*m)/3);
}else{
System.out.println(((n*m)/3) + 1);
}
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 591c970d3ad246c2e6e594e6983e9c0e | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.util.*;
public class ColoringRectangles {
public static void main(String[] args) {
new ColoringRectangles().run();
}
BufferedReader br;
PrintWriter out;
long mod = (long) (1e9 + 7), inf = (long) (3e18);
class pair {
int F, S;
pair(int f, int s) {
F = f; S = s;
}
}
void solve() {
int t = ni();
while(t-- > 0) {
//TODO:
int n = ni();
int m = ni();
out.println(Math.max(m*n/3+(m*n%3==0?0:1), 1));
}
}
// -------- I/O Template -------------
char nc() {
return ns().charAt(0);
}
String nLine() {
try {
return br.readLine();
} catch(IOException e) {
return "-1";
}
}
double nd() {
return Double.parseDouble(ns());
}
long nl() {
return Long.parseLong(ns());
}
int ni() {
return Integer.parseInt(ns());
}
int[] na(int n) {
int a[] = new int[n];
for(int i = 0; i < n; i++) a[i] = ni();
return a;
}
StringTokenizer ip;
String ns() {
if(ip == null || !ip.hasMoreTokens()) {
try {
ip = new StringTokenizer(br.readLine());
if(ip == null || !ip.hasMoreTokens())
ip = new StringTokenizer(br.readLine());
} catch(IOException e) {
throw new InputMismatchException();
}
}
return ip.nextToken();
}
void run() {
try {
if (System.getProperty("ONLINE_JUDGE") == null) {
br = new BufferedReader(new FileReader("/media/ankanchanda/Data1/WORKPLACE/DS and CP/Competitive Programming/VSCODE/IO/input.txt"));
out = new PrintWriter("/media/ankanchanda/Data1/WORKPLACE/DS and CP/Competitive Programming/VSCODE/IO/output.txt");
} else {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
} catch (FileNotFoundException e) {
System.out.println(e);
}
solve();
out.flush();
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 1dce5ae5d9c3c50d351c36f5d1dcfb33 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
public class practice2 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
long n=sc.nextInt();
long k=sc.nextInt();
System.out.println(((n*k)+2)/3);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 18fed8e5c9f2c4f78608f801e1876984 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.Scanner;
public class ColoringRectangles {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt(),x=0;
for (int i=0;i<t;i++){
int n=sc.nextInt(),m=sc.nextInt();
x=n*m;
if (x%3==0){
System.out.println(x/3);
}else
System.out.println(x/3+1);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 68c99b22fd6078cf5a45cad80f957551 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.*;
public class Solution{
static Scanner sc = new Scanner(System.in);
public static void main(String args[]){
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt(), m = sc.nextInt();
if((n == 1 || n == 2) && (m == 1 || m == 2)){
System.out.println(Math.min(m , n));
continue;
}
if(n % 3 == 0 || m % 3 == 0)
System.out.println(n % 3 == 0 ? (n / 3) * m : (m / 3) * n);
else{
int ans = ((n - (n % 3)) / 3) * m + (n % 3) * ((m - (m % 3)) / 3) + Math.min(n % 3, m % 3);
System.out.println(ans);
}
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 914de8934e48f688cd6dfca12470a849 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | /*package whatever //do not write package name here */
import java.io.*;
import java.util.*;
import java.lang.*;
public class GFG {
public static void main (String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
int i = 0;
while (i< t){
double n = in.nextDouble();
double m = in.nextDouble();
System.out.println((int)Math.ceil(n*m/3));
i+=1;
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 50817cd36bcd5506384448b090dd8103 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.Scanner;
/**
*
* @author Acer
*/
public class ColoringRectangles {
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();
int ans = ((n*m)+2)/3;
System.out.println(ans);
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | a5ae8d13ebb8630db702a19428e64d08 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | //---#ON_MY_WAY---
import static java.lang.Math.*;
import java.io.*;
import java.math.*;
import java.util.*;
public class apples {
static class pair {
int x, y;
public pair(int a, int b) {
x = a;
y = b;
}
}
static FastReader x = new FastReader();
static OutputStream outputStream = System.out;
static PrintWriter out = new PrintWriter(outputStream);
/*---------------------------------------CODE STARTS HERE-------------------------*/
public static void main(String[] args) throws NumberFormatException, IOException {
long startTime = System.nanoTime();
int mod = 1000000007;
int t = x.nextInt();
StringBuilder str = new StringBuilder();
while (t > 0) {
int n = x.nextInt();
int m = x.nextInt();
int ans = (n*m)/3;
if((n*m)%3!=0) ans++;
str.append(ans);
str.append("\n");
t--;
}
out.println(str);
out.flush();
long endTime = System.nanoTime();
//System.out.println((endTime-startTime)/1000000000.0);
}
/*--------------------------------------------FAST I/O--------------------------------*/
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
char nextchar() {
char ch = ' ';
try {
ch = (char) br.read();
} catch (IOException e) {
e.printStackTrace();
}
return ch;
}
}
/*--------------------------------------------BOILER PLATE---------------------------*/
static int[] readarr(int n) {
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = x.nextInt();
}
return arr;
}
static int[] sortint(int a[]) {
ArrayList<Integer> al = new ArrayList<>();
for (int i : a) {
al.add(i);
}
Collections.sort(al);
for (int i = 0; i < a.length; i++) {
a[i] = al.get(i);
}
return a;
}
static long[] sortlong(long a[]) {
ArrayList<Long> al = new ArrayList<>();
for (long i : a) {
al.add(i);
}
Collections.sort(al);
for (int i = 0; i < al.size(); i++) {
a[i] = al.get(i);
}
return a;
}
static long pow(long x, long y) {
long result = 1;
while (y > 0) {
if (y % 2 == 0) {
x = x * x;
y = y / 2;
} else {
result = result * x;
y = y - 1;
}
}
return result;
}
static long pow(long x, long y, long mod) {
long result = 1;
x %= mod;
while (y > 0) {
if (y % 2 == 0) {
x = (x%mod * x%mod) % mod;
y /= 2;
} else {
result = (result%mod * x%mod) % mod;
y--;
}
}
return result;
}
static int[] revsort(int a[]) {
ArrayList<Integer> al = new ArrayList<>();
for (int i : a) {
al.add(i);
}
Collections.sort(al, Comparator.reverseOrder());
for (int i = 0; i < a.length; i++) {
a[i] = al.get(i);
}
return a;
}
static int[] gcd(int a, int b, int ar[]) {
if (b == 0) {
ar[0] = a;
ar[1] = 1;
ar[2] = 0;
return ar;
}
ar = gcd(b, a % b, ar);
int t = ar[1];
ar[1] = ar[2];
ar[2] = t - (a / b) * ar[2];
return ar;
}
static boolean[] esieve(int n) {
boolean p[] = new boolean[n + 1];
Arrays.fill(p, true);
for (int i = 2; i * i <= n; i++) {
if (p[i] == true) {
for (int j = i * i; j <= n; j += i) {
p[j] = false;
}
}
}
return p;
}
static ArrayList<Integer> primes(int n) {
boolean p[] = new boolean[n + 1];
ArrayList<Integer> al = new ArrayList<>();
Arrays.fill(p, true);
int i = 0;
for (i = 2; i * i <= n; i++) {
if (p[i] == true) {
al.add(i);
for (int j = i * i; j <= n; j += i) {
p[j] = false;
}
}
}
for (i = i; i <= n; i++) {
if (p[i] == true) {
al.add(i);
}
}
return al;
}
static int etf(int n) {
int res = n;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
res /= i;
res *= (i - 1);
while (n % i == 0) {
n /= i;
}
}
}
if (n > 1) {
res /= n;
res *= (n - 1);
}
return res;
}
static int gcd(int a, int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
static long gcd(long a, long b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 4dd61c38e3bf51bdcf269086ad52ebc9 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes |
import java.io.*;
import java.util.*;
public class Coloring_Regtangles{
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
for(int i = 0; i<N; i++){
int a = sc.nextInt();
int b = sc.nextInt();
int sol = 0;
int r1 = a%3;
int r2 = b%3;
sol = b*((a-r1)/3) + r1*((b-r2)/3);
if(r1 == 0 || r2 == 0){
System.out.println(sol);
}
else if(r1 == 1 || r2 == 1){
System.out.println(sol+1);
}
else{
System.out.println(sol+2);
}
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 5e4887030155f331dcd1e2597ba68927 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.util.Scanner;
public class CodeForces_1584B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int numTestcases = sc.nextInt();
while(numTestcases-->0){
int n = sc.nextInt();
int m = sc.nextInt();
if(m>n){
int t = m;
m=n;
n=t;
}
int temp1 = (n/3) * m;
n%=3;
if(m>n){
int t = m;
m=n;
n=t;
}
if(m>0){
temp1 += (n/3) * m;
}
n%=3;
if(m>n){
int t = m;
m=n;
n=t;
}
if(m==2 & n == 2){
temp1 +=2;
}else if(m == 1 && n == 2 || m == 2 && n == 1 || m == 1 && n == 1 ){
temp1 +=1;
}
System.out.println(temp1);
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 59b37d6a490bdf68c0a34ace314c1b11 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.StringTokenizer;
public class Coloring_Rectangles
{
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static PrintWriter out;
public static void main (String[] args) throws java.lang.Exception
{
out = new PrintWriter(System.out);
try
{
//Scanner obj = new Scanner (System.in);
Reader obj = new Reader ();
int t = obj.nextInt();
while (t > 0)
{
t--;
int n = obj.nextInt();
int m = obj.nextInt();
//String str = obj.next();
out.println ((n * m + 2) / 3);
}
}catch(Exception e){
return;
}
out.flush();
out.close();
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | d84b516dc6a883e7b3a61d029879b15c | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt(), m = sc.nextInt();
int nm = n*m;
int ans = nm / 3;
if (nm % 3 == 1 || nm % 3 == 2) ans++;
out.println(ans);
}
out.close();
}
static final Random random = new Random();
static void shuffleSort(long[] a) {
int n = a.length;
for (int i = 0; i < n; i++) {
int r = random.nextInt(n);
long temp = a[r];
a[r] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public 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 boolean ready() throws IOException {return br.ready();}
int[] readArray(int n) throws IOException {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i] = nextInt();
return a;
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 2ed1049a124cf257ebe5100e103d2bb7 | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt(), m = sc.nextInt();
out.println((int) Math.ceil((double)n*m / 3));
}
out.close();
}
static final Random random = new Random();
static void shuffleSort(long[] a) {
int n = a.length;
for (int i = 0; i < n; i++) {
int r = random.nextInt(n);
long temp = a[r];
a[r] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public 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 boolean ready() throws IOException {return br.ready();}
int[] readArray(int n) throws IOException {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i] = nextInt();
return a;
}
}
} | Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 2c4ed44d02196cb48162ce138e33e4ca | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.*;
import java.lang.Math;
import java.util.StringTokenizer;
public class twentysix {
public static void main(String[] args){
int a[][], b, t;
String str;
FastReader in = new FastReader();
t = in.nextInt();
while(t-- > 0){
int ans = 0;
int count = 0;
int cnt = 0;
int n = in.nextInt();
int m = in.nextInt();
System.out.println((n*m+2)/3);
}
}
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());
}
int[] readArray(int n){
int[] a = new int[n];
for(int i = 0; i < n;i++){
a[i] = nextInt();
}
return a;
}
String nextLine()
{
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output | |
PASSED | 86f28cd367e46b2a925dc9646367187a | train_109.jsonl | 1636869900 | David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class B {
static FastScanner fs=new FastScanner();
static void solve()
{
int n=fs.nextInt();
int m=fs.nextInt();
long S=n*m+2;
System.out.println(S/3);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int t=fs.nextInt();
while (t-->0)
{
solve();
}
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
public String next() {
while (!st.hasMoreElements())
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());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n1 3\n2 2\n2 5\n3 5"] | 1 second | ["1\n2\n4\n5"] | NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case: In the second test case: In the third test case: In the fourth test case: | Java 8 | standard input | [
"greedy",
"math"
] | 70a0b98f2bb12990a0fa46aaf13134af | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$). | 1,000 | For each test case print a single integer — the minimum number of cells David will have to paint blue. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.