Algorithm


A. Park Lighting
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.

The park is a rectangular table with n">n rows and m">m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1">11. For example, park with n=m=2">n=m=2�=�=2 has 12">1212 streets.

You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).

The park sizes are: n=4">n=4�=4m=5">m=5�=5. The lighted squares are marked yellow. Please note that all streets have length 1">11. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.

Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.

Input

The first line contains a single integer t">t (1≤t≤104">1t1041≤�≤104) — the number of test cases in the input. Then t">t test cases follow.

Each test case is a line containing two integers n">nm">m (1≤n,m≤104">1n,m1041≤�,�≤104) — park sizes.

Output

Print t">t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.

Example
input
Copy
5
1 1
1 3
2 2
3 3
5 3
output
Copy
1
2
2
5
8
Note

Possible optimal arrangement of the lanterns for the 2">22-nd test case of input data example:

Possible optimal arrangement of the lanterns for the 3">33-rd test case of input data example:

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include<bits/stdc++.h>
using namespace std;


#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t;
  cin>>t;
  int n, m;
  while(t--){
    cin>>n>>m;
    int lights;
    lights = (n*m)%2 == 0 ? ((n * m) / 2) : (((n * m) / 2) + 1);
    cout<<lights<<endl;
  }

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5
1 1
1 3
2 2
3 3
5 3

Output

x
+
cmd
1
2
2
5
8
Advertisements

Demonstration


Codeforcess solution 1358-A A. Park Lighting ,C++, Java, Js and Python,1358-A,Codeforcess solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+