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
sequencelengths 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 | 0b5a8180b32f392b2dfd96897e3d2c7f | train_000.jsonl | 1497539100 | You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.For example, the imbalance value of array [1,β4,β1] is 9, because there are 6 different subsegments of this array: [1] (from index 1 to index 1), imbalance value is 0; [1,β4] (from index 1 to index 2), imbalance value is 3; [1,β4,β1] (from index 1 to index 3), imbalance value is 3; [4] (from index 2 to index 2), imbalance value is 0; [4,β1] (from index 2 to index 3), imbalance value is 3; [1] (from index 3 to index 3), imbalance value is 0; You have to determine the imbalance value of the array a. | 256 megabytes | import java.util.*;
public class Main{
public static long getImbalanceArray(int[] nums) {
int len = nums.length;
long result = 0, minSum = 0, maxSum = 0;
Stack<Integer> stack1 = new Stack<>();
Stack<Integer> stack2 = new Stack<>();
stack1.push(-1);
stack2.push(-1);
for (int i = 0; i < len; i++) {
while (stack1.peek() != -1 && nums[i] < nums[stack1.peek()]) {
int x = stack1.pop();
minSum += (long)(i - x) * (x - stack1.peek()) * nums[x];
}
stack1.push(i);
}
while (stack1.peek() != -1) {
int x = stack1.pop();
minSum += (long)(len - x) * (x - stack1.peek()) * nums[x];
}
for (int i = 0; i < len; i++) {
while (stack2.peek() != -1 && nums[i] > nums[stack2.peek()]) {
int x = stack2.pop();
maxSum += (long)(i - x) * (x - stack2.peek()) * nums[x];
}
stack2.push(i);
}
while (stack2.peek() != -1) {
int x = stack2.pop();
maxSum += (long)(len - x) * (x - stack2.peek()) * nums[x];
}
result = maxSum - minSum;
return result;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int len = sc.nextInt();
int[] nums = new int[len];
for (int i = 0; i < len; i++) nums[i] = sc.nextInt();
System.out.println(getImbalanceArray(nums));
}
} | Java | ["3\n1 4 1"] | 2 seconds | ["9"] | null | Java 8 | standard input | [
"data structures",
"dsu",
"divide and conquer",
"sortings"
] | 38210a3dcb16ce2bbc81aa1d39d23112 | The first line contains one integer n (1ββ€βnββ€β106) β size of the array a. The second line contains n integers a1,βa2... an (1ββ€βaiββ€β106) β elements of the array. | 1,900 | Print one integer β the imbalance value of a. | standard output | |
PASSED | cdd42d2e67dad669d4b9acf43da9b41e | train_000.jsonl | 1497539100 | You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.For example, the imbalance value of array [1,β4,β1] is 9, because there are 6 different subsegments of this array: [1] (from index 1 to index 1), imbalance value is 0; [1,β4] (from index 1 to index 2), imbalance value is 3; [1,β4,β1] (from index 1 to index 3), imbalance value is 3; [4] (from index 2 to index 2), imbalance value is 0; [4,β1] (from index 2 to index 3), imbalance value is 3; [1] (from index 3 to index 3), imbalance value is 0; You have to determine the imbalance value of the array a. | 256 megabytes | /**
* DA-IICT
* Author : Savaliya Sagar
*/
import java.io.*;
import java.math.*;
import java.util.*;
public class D817 {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve() {
int n = ni();
int[] a = na(n);
long max = 0;
long min = 0;
int smax[] = new int[n];
int pmax[] = new int[n];
int smin[] = new int[n];
int pmin[] = new int[n];
init1(smax,n);
init2(pmax,n);
init1(smin,n);
init2(pmin,n);
Stack<Integer> s = new Stack<>();
for(int i=0;i<n;i++){
if(s.empty()) s.push(i);
else{
while(!s.empty() && a[s.peek()] < a[i]){
smax[s.peek()] =i-s.peek();
s.pop();
}
s.push(i);
}
}
s.clear();
for(int i=n-1;i>=0;i--){
if(s.empty()) s.push(i);
else{
while(!s.empty() && a[s.peek()] <= a[i]){
pmax[s.peek()] =s.peek()-i;
s.pop();
}
s.push(i);
}
}
s.clear();
for(int i=0;i<n;i++){
if(s.empty()) s.push(i);
else{
while(!s.empty() && a[s.peek()] > a[i]){
smin[s.peek()] =i-s.peek();
s.pop();
}
s.push(i);
}
}
s.clear();
for(int i=n-1;i>=0;i--){
if(s.empty()) s.push(i);
else{
while(!s.empty() && a[s.peek()] >= a[i]){
pmin[s.peek()] =s.peek()-i;
s.pop();
}
s.push(i);
}
}
s.clear();
for(int i=0;i<n;i++){
max += ((long)smax[i]*pmax[i])*a[i];
min += ((long)smin[i]*pmin[i])*a[i];
}
out.println(max-min);
}
void init1(int a[],int n){
for(int i=0;i<n;i++){
a[i] = n-i;
}
}
void init2(int a[],int n){
for(int i=0;i<n;i++){
a[i] = i+1;
}
}
void run() throws Exception {
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
if (!INPUT.isEmpty())
tr(System.currentTimeMillis() - s + "ms");
}
public static void main(String[] args) throws Exception {
new Thread(null, new Runnable() {
public void run() {
try {
new D817().run();
} catch (Exception e) {
e.printStackTrace();
}
}
}, "1", 1 << 26).start();
}
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte() {
if (lenbuf == -1)
throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b))
;
return b;
}
private double nd() {
return Double.parseDouble(ns());
}
private char nc() {
return (char) skip();
}
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b !=
// ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m) {
char[][] map = new char[n][];
for (int i = 0; i < n; i++)
map[i] = ns(m);
return map;
}
private int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = ni();
return a;
}
private int ni() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
private long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
private void tr(Object... o) {
System.out.println(Arrays.deepToString(o));
}
}
| Java | ["3\n1 4 1"] | 2 seconds | ["9"] | null | Java 8 | standard input | [
"data structures",
"dsu",
"divide and conquer",
"sortings"
] | 38210a3dcb16ce2bbc81aa1d39d23112 | The first line contains one integer n (1ββ€βnββ€β106) β size of the array a. The second line contains n integers a1,βa2... an (1ββ€βaiββ€β106) β elements of the array. | 1,900 | Print one integer β the imbalance value of a. | standard output | |
PASSED | 143e6e5e098b9391c8756fd54f6b29af | train_000.jsonl | 1497539100 | You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.For example, the imbalance value of array [1,β4,β1] is 9, because there are 6 different subsegments of this array: [1] (from index 1 to index 1), imbalance value is 0; [1,β4] (from index 1 to index 2), imbalance value is 3; [1,β4,β1] (from index 1 to index 3), imbalance value is 3; [4] (from index 2 to index 2), imbalance value is 0; [4,β1] (from index 2 to index 3), imbalance value is 3; [1] (from index 3 to index 3), imbalance value is 0; You have to determine the imbalance value of the array a. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef{
static PrintWriter out = new PrintWriter(System.out);
public static void main (String[] args) throws java.lang.Exception {
InputReader sc = new InputReader(System.in);
int n = sc.nextInt();
int[] a = new int[n], mnl = new int[n], mnr = new int[n];
int[] mxl = new int[n], mxr = new int[n];
int i;
for(i=0;i<n;i++) a[i] = sc.nextInt();
Stack<Integer> st = new Stack<>();
Arrays.fill(mnl,-1); Arrays.fill(mxl,-1);
Arrays.fill(mnr,n); Arrays.fill(mxr,n);
st.push(0);
for(i=1;i<n;i++){
while(!st.empty() && a[st.peek()]>=a[i]) st.pop();
if(!st.empty()) mnl[i] = st.peek();
st.push(i);
}
st.clear(); st.push(n-1);
for(i=n-2;i>=0;i--){
while(!st.empty() && a[st.peek()]>a[i]) st.pop();
if(!st.empty()) mnr[i] = st.peek();
st.push(i);
}
st.clear(); st.push(0);
for(i=1;i<n;i++){
while(!st.empty() && a[st.peek()]<=a[i]) st.pop();
if(!st.empty()) mxl[i] = st.peek();
st.push(i);
}
st.clear(); st.push(n-1);
for(i=n-2;i>=0;i--){
while(!st.empty() && a[st.peek()]<a[i]) st.pop();
if(!st.empty()) mxr[i] = st.peek();
st.push(i);
}
long max=0L,min=0L;
for(i=0;i<n;i++){
min += a[i]*(1L*(i-mnl[i])*(mnr[i]-i));
max += a[i]*(1L*(i-mxl[i])*(mxr[i]-i));
}
out.println(max-min);
out.close();
}
public static class InputReader {
private static final int BUFFER_LENGTH = 1 << 12;
private InputStream stream;
private byte[] buf = new byte[BUFFER_LENGTH];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
private int next() {
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 char nextChar() {
return (char) skipWhileSpace();
}
public String nextToken() {
int c = skipWhileSpace();
StringBuilder res = new StringBuilder();
do {
res.append((char) c);
c = next();
} while (!isSpaceChar(c));
return res.toString();
}
public int nextInt() {
return (int) nextLong();
}
public long nextLong() {
int c = skipWhileSpace();
long sgn = 1;
if (c == '-') {
sgn = -1;
c = next();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = next();
} while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
return Double.valueOf(nextToken());
}
int skipWhileSpace() {
int c = next();
while (isSpaceChar(c)) {
c = next();
}
return c;
}
boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
} | Java | ["3\n1 4 1"] | 2 seconds | ["9"] | null | Java 8 | standard input | [
"data structures",
"dsu",
"divide and conquer",
"sortings"
] | 38210a3dcb16ce2bbc81aa1d39d23112 | The first line contains one integer n (1ββ€βnββ€β106) β size of the array a. The second line contains n integers a1,βa2... an (1ββ€βaiββ€β106) β elements of the array. | 1,900 | Print one integer β the imbalance value of a. | standard output | |
PASSED | 5a836179fd543f3b8d88e4cb239cccd6 | train_000.jsonl | 1497539100 | You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.For example, the imbalance value of array [1,β4,β1] is 9, because there are 6 different subsegments of this array: [1] (from index 1 to index 1), imbalance value is 0; [1,β4] (from index 1 to index 2), imbalance value is 3; [1,β4,β1] (from index 1 to index 3), imbalance value is 3; [4] (from index 2 to index 2), imbalance value is 0; [4,β1] (from index 2 to index 3), imbalance value is 3; [1] (from index 3 to index 3), imbalance value is 0; You have to determine the imbalance value of the array a. | 256 megabytes | import java.io.DataInputStream;
import java.io.IOException;
public class Educational23PD {
public static void main(String... args) throws IOException {
Reader reader = new Reader();
int n = reader.nextInt();
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = reader.nextInt();
}
long s1 = solve(a);
for (int i = 0; i < n; i++) {
a[i] = -a[i];
}
System.out.println(s1 + solve(a));
}
private static long solve(int[] a) {
int l[] = new int[a.length];
int r[] = new int[a.length];
long sum = 0;
for (int i = 0; i < a.length; i++) {
l[i] = i - 1;
while (l[i] >= 0 && a[i] > a[l[i]]) {
l[i] = l[l[i]];
}
}
for (int i = a.length - 1; i >= 0; i--) {
r[i] = i + 1;
while (r[i] < a.length && a[i] >= a[r[i]]) {
r[i] = r[r[i]];
}
sum += (long)(i - l[i]) * (long)(r[i] - i) * (long)a[i];
}
return sum;
}
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
String readLine() throws IOException {
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
//Will read words with space as delimiters
public String nextWord() throws IOException {
byte[] buf = new byte[64]; // word length
byte c = read();
while (c == ' ')
c = read();
int cnt = 0;
do {
buf[cnt++] = c;
c = read();
} while (c != ' ' && c != '\n');
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;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
}
| Java | ["3\n1 4 1"] | 2 seconds | ["9"] | null | Java 8 | standard input | [
"data structures",
"dsu",
"divide and conquer",
"sortings"
] | 38210a3dcb16ce2bbc81aa1d39d23112 | The first line contains one integer n (1ββ€βnββ€β106) β size of the array a. The second line contains n integers a1,βa2... an (1ββ€βaiββ€β106) β elements of the array. | 1,900 | Print one integer β the imbalance value of a. | standard output | |
PASSED | 9fbd70493ec065944423873f8252a37f | train_000.jsonl | 1497539100 | You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.For example, the imbalance value of array [1,β4,β1] is 9, because there are 6 different subsegments of this array: [1] (from index 1 to index 1), imbalance value is 0; [1,β4] (from index 1 to index 2), imbalance value is 3; [1,β4,β1] (from index 1 to index 3), imbalance value is 3; [4] (from index 2 to index 2), imbalance value is 0; [4,β1] (from index 2 to index 3), imbalance value is 3; [1] (from index 3 to index 3), imbalance value is 0; You have to determine the imbalance value of the array a. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Stack;
import java.util.StringTokenizer;
public class CF817D {
public static void main(String[] args) throws IOException {
FastScanner sc = new FastScanner();
PrintWriter pw = new PrintWriter(System.out);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = sc.nextInt();
pw.println(solve(arr));
sc.close();
pw.close();
}
public static long solve(int[] a) {
int n = a.length;
int[] lMin = new int[a.length], rMin = new int[a.length], lMax = new int[a.length], rMax = new int[a.length];
Stack<Integer> s = new Stack<Integer>();
// Compute lMin
for (int i = 0; i < n; i++) {
while (!s.isEmpty() && a[i] <= a[s.peek()])
s.pop();
lMin[i] = s.isEmpty() ? 0 : s.peek() + 1;
s.push(i);
}
s = new Stack<Integer>();
// Compute rMin
for (int i = n - 1; i >= 0; i--) {
while (!s.isEmpty() && a[i] < a[s.peek()])
s.pop();
rMin[i] = s.isEmpty() ? n - 1 : s.peek() - 1;
s.push(i);
}
s = new Stack<Integer>();
// Compute lMax
for (int i = 0; i < n; i++) {
while (!s.isEmpty() && a[i] >= a[s.peek()])
s.pop();
lMax[i] = s.isEmpty() ? 0 : s.peek() + 1;
s.push(i);
}
s = new Stack<Integer>();
// Compute rMax
for (int i = n - 1; i >= 0; i--) {
while (!s.isEmpty() && a[i] > a[s.peek()])
s.pop();
rMax[i] = s.isEmpty() ? n - 1 : s.peek() - 1;
s.push(i);
}
long sum = 0;
for (int i = 0; i < n; i++)
sum += 1l * a[i] * (i - lMax[i] + 1) * (rMax[i] - i + 1)
- 1l * a[i] * (i - lMin[i] + 1) * (rMin[i] - i + 1);
return sum;
}
static class FastScanner {
BufferedReader in;
StringTokenizer st;
public FastScanner() {
this.in = new BufferedReader(new InputStreamReader(System.in));
}
public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(in.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
public double nextDouble() {
return Double.parseDouble(nextToken());
}
public void close() throws IOException {
in.close();
}
}
} | Java | ["3\n1 4 1"] | 2 seconds | ["9"] | null | Java 8 | standard input | [
"data structures",
"dsu",
"divide and conquer",
"sortings"
] | 38210a3dcb16ce2bbc81aa1d39d23112 | The first line contains one integer n (1ββ€βnββ€β106) β size of the array a. The second line contains n integers a1,βa2... an (1ββ€βaiββ€β106) β elements of the array. | 1,900 | Print one integer β the imbalance value of a. | standard output | |
PASSED | 8cddc40b4bf9f0c6ad5e2d4a45919de2 | train_000.jsonl | 1497539100 | You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.For example, the imbalance value of array [1,β4,β1] is 9, because there are 6 different subsegments of this array: [1] (from index 1 to index 1), imbalance value is 0; [1,β4] (from index 1 to index 2), imbalance value is 3; [1,β4,β1] (from index 1 to index 3), imbalance value is 3; [4] (from index 2 to index 2), imbalance value is 0; [4,β1] (from index 2 to index 3), imbalance value is 3; [1] (from index 3 to index 3), imbalance value is 0; You have to determine the imbalance value of the array a. | 256 megabytes |
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
public class TestClass {
static int MAX = 1000006;
static int arr[] = new int[MAX];
static int st[] = new int[MAX];
static long vs[] = new long[MAX];
static long maxV(int n) {
long result = 0;
long prevV = 0;
int curr;
int topSt = 0;
result += arr[0];
vs[topSt] = (arr[0] * 1L);
st[topSt] = 0;
for(int i=1;i<n;i++) {
while((topSt >= 0) && (arr[st[topSt]] <= arr[i])) {
topSt--;
}
long value = 0;
if(topSt >= 0) {
value += (arr[i] * 1L * (i - st[topSt]));
value += vs[topSt];
} else {
value += (arr[i] * 1L * (i+1));
}
result += value;
topSt++;
vs[topSt] = value;
st[topSt] = i;
}
return result;
}
static long minV(int n) {
long result = 0;
long prevV = 0;
int curr;
int topSt = 0;
result += arr[0];
vs[topSt] = (arr[0] * 1L);
st[topSt] = 0;
for(int i=1;i<n;i++) {
while((topSt >= 0) && (arr[st[topSt]] >= arr[i])) {
topSt--;
}
long value = 0;
if(topSt >= 0) {
value += (arr[i] * 1L * (i - st[topSt]));
value += vs[topSt];
} else {
value += (arr[i] * 1L * (i+1));
}
result += value;
topSt++;
vs[topSt] = value;
st[topSt] = i;
}
return result;
}
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner scanner = new Scanner(System.in);
int n = Integer.parseInt(br.readLine());
String line = br.readLine();
String values[] = line.split(" ");
for(int i=0;i<n;i++) {
arr[i] = Integer.parseInt(values[i]);
}
long result = maxV(n) - minV(n);
System.out.println(result);
}
}
| Java | ["3\n1 4 1"] | 2 seconds | ["9"] | null | Java 8 | standard input | [
"data structures",
"dsu",
"divide and conquer",
"sortings"
] | 38210a3dcb16ce2bbc81aa1d39d23112 | The first line contains one integer n (1ββ€βnββ€β106) β size of the array a. The second line contains n integers a1,βa2... an (1ββ€βaiββ€β106) β elements of the array. | 1,900 | Print one integer β the imbalance value of a. | standard output | |
PASSED | 6750529baca26baa696d34fd96f47d51 | train_000.jsonl | 1497539100 | You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.For example, the imbalance value of array [1,β4,β1] is 9, because there are 6 different subsegments of this array: [1] (from index 1 to index 1), imbalance value is 0; [1,β4] (from index 1 to index 2), imbalance value is 3; [1,β4,β1] (from index 1 to index 3), imbalance value is 3; [4] (from index 2 to index 2), imbalance value is 0; [4,β1] (from index 2 to index 3), imbalance value is 3; [1] (from index 3 to index 3), imbalance value is 0; You have to determine the imbalance value of the array a. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.StringTokenizer;
public class Edu_23D {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int numE = Integer.parseInt(reader.readLine());
int[] elements = new int[numE + 2];
StringTokenizer inputData = new StringTokenizer(reader.readLine());
for (int i = 1; i <= numE; i++) {
elements[i] = Integer.parseInt(inputData.nextToken());
}
long ans = 0;
ArrayDeque<Integer> stack = new ArrayDeque<Integer>();
elements[0] = Integer.MAX_VALUE;
stack.push(0);
int[] left = new int[numE + 1];
for (int i = 1; i <= numE; i++) {
while (elements[stack.peek()] < elements[i]) {
stack.pop();
}
left[i] = stack.peek() + 1;
stack.push(i);
}
stack.clear();
elements[numE + 1] = Integer.MAX_VALUE;
stack.push(numE + 1);
for (int i = numE; i >= 1; i--) {
while (elements[i] >= elements[stack.peek()]) {
stack.pop();
}
int cRight = stack.peek() - 1;
ans += (i - left[i] + 1L) * (cRight - i + 1L) * elements[i];
stack.push(i);
}
stack.clear();
elements[0] = 0;
stack.push(0);
for (int i = 1; i <= numE; i++) {
while (elements[stack.peek()] > elements[i]) {
stack.pop();
}
left[i] = stack.peek() + 1;
stack.push(i);
}
stack.clear();
elements[numE + 1] = 0;
stack.push(numE + 1);
for (int i = numE; i >= 1; i--) {
while (elements[i] <= elements[stack.peek()]) {
stack.pop();
}
int cRight = stack.peek() - 1;
ans -= (i - left[i] + 1L) * (cRight - i + 1L) * elements[i];
stack.push(i);
}
System.out.println(ans);
}
}
| Java | ["3\n1 4 1"] | 2 seconds | ["9"] | null | Java 8 | standard input | [
"data structures",
"dsu",
"divide and conquer",
"sortings"
] | 38210a3dcb16ce2bbc81aa1d39d23112 | The first line contains one integer n (1ββ€βnββ€β106) β size of the array a. The second line contains n integers a1,βa2... an (1ββ€βaiββ€β106) β elements of the array. | 1,900 | Print one integer β the imbalance value of a. | standard output | |
PASSED | b78316d4542c3cce55b7216fee994805 | train_000.jsonl | 1497539100 | You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.For example, the imbalance value of array [1,β4,β1] is 9, because there are 6 different subsegments of this array: [1] (from index 1 to index 1), imbalance value is 0; [1,β4] (from index 1 to index 2), imbalance value is 3; [1,β4,β1] (from index 1 to index 3), imbalance value is 3; [4] (from index 2 to index 2), imbalance value is 0; [4,β1] (from index 2 to index 3), imbalance value is 3; [1] (from index 3 to index 3), imbalance value is 0; You have to determine the imbalance value of the array a. | 256 megabytes | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
//class Declaration
static class pair implements Comparable < pair > {
int x;
int y;
pair(int i, int j) {
x = i;
y = j;
}
public int compareTo(pair p) {
if (this.x != p.x) {
return this.x - p.x;
} else {
return this.y - p.y;
}
}
public int hashCode() {
return (x + " " + y).hashCode();
}
public String toString() {
return x + " " + y;
}
public boolean equals(Object o) {
pair x = (pair) o;
return (x.x == this.x && x.y == this.y);
}
}
// int[] dx = {0,0,1,-1};
// int[] dy = {1,-1,0,0};
// int[] ddx = {0,0,1,-1,1,-1,1,-1};
// int[] ddy = {1,-1,0,0,1,-1,-1,1};
int inf = (int) 1e9 + 5;
long mod = (long)1e9 + 7 ;
void solve() throws Exception {
int n=ni();
int[] arr =na(n);
int[] nheL = new int[n];
int[] nheR = new int[n];
int[] nseR = new int[n];
int[] nseL = new int[n];
LinkedList<Integer> ll = new LinkedList<>();
for(int i=0;i<n;++i){
if( ll.isEmpty() || arr[ll.peekLast()] >= arr[i]){
ll.add(i);
}
else{
while(!ll.isEmpty() && arr[i]>arr[ll.peekLast()])
nheR[ll.pollLast()] = i ;
ll.add(i);
}
}
while(!ll.isEmpty()){
nheR[ll.pollLast()] = -1 ;
}
for(int i=n-1;i>=0;--i){
if( ll.isEmpty() || arr[ll.peekLast()] > arr[i]){
ll.add(i);
}
else{
while(!ll.isEmpty() && arr[i]>=arr[ll.peekLast()])
nheL[ll.pollLast()] = i ;
ll.add(i);
}
}
while(!ll.isEmpty()){
nheL[ll.pollLast()] = -1 ;
}
for(int i=0;i<n ; ++i){
if( ll.isEmpty() || arr[ll.peekLast()] <= arr[i]){
ll.add(i);
}
else{
while(!ll.isEmpty() && arr[i]<arr[ll.peekLast()])
nseR[ll.pollLast()] = i ;
ll.add(i);
}
}
while(!ll.isEmpty()){
nseR[ll.pollLast()] = -1 ;
}
for(int i=n-1;i>=0 ; --i){
if( ll.isEmpty() || arr[ll.peekLast()] < arr[i]){
ll.add(i);
}
else{
while(!ll.isEmpty() && arr[i]<=arr[ll.peekLast()])
nseL[ll.pollLast()] = i ;
ll.add(i);
}
}
while(!ll.isEmpty()){
nseL[ll.pollLast()] = -1 ;
}
// pn("array "+Arrays.toString(arr));
// pn(Arrays.toString(nheR));
// pn(Arrays.toString(nheL));
// pn(Arrays.toString(nseR));
// pn(Arrays.toString(nseL));
long ans =0;
for(int i=0;i<n;++i){
// Higher
long right = nheR[i]==-1?n-i-1:(nheR[i]-i-1) ;
long left = nheL[i]==-1?i:(i-nheL[i]-1) ;
long total = left + right +1 ;
long cntSubArray = (total*(total+1)/2L) - right*(right+1)/2 - left*(left+1)/2 ;
//pn("for i max:"+i+" "+cntSubArray);
ans += (cntSubArray*arr[i]) ;
// lower
right = nseR[i]==-1?n-i-1:(nseR[i]-i-1) ;
left = nseL[i]==-1?i:(i-nseL[i]-1) ;
total = left + right +1 ;
cntSubArray = (total*(total+1)/2L) - right*(right+1)/2 - left*(left+1)/2 ;
//pn("for i min:"+i+" "+cntSubArray);
ans -= (cntSubArray*arr[i]) ;
}
pn(ans);
}
long pow(long a, long b) {
long result = 1;
while (b > 0) {
if (b % 2 == 1) result = (result * a) % mod;
b /= 2;
a = (a * a) % mod;
}
return result;
}
void print(Object o) {
System.out.println(o);
System.out.flush();
}
long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
void run() throws Exception {
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms");
}
public static void main(String[] args) throws Exception {
new Main().run();
}
//output methods
private void pn(Object o) {
out.println(o);
}
private void p(Object o) {
out.print(o);
}
private ArrayList < ArrayList < Integer >> ng(int n, int e) {
ArrayList < ArrayList < Integer >> g = new ArrayList < > ();
for (int i = 0; i <= n; ++i) g.add(new ArrayList < > ());
for (int i = 0; i < e; ++i) {
int u = ni(), v = ni();
g.get(u).add(v);
g.get(v).add(u);
}
return g;
}
private ArrayList < ArrayList < pair >> nwg(int n, int e) {
ArrayList < ArrayList < pair >> g = new ArrayList < > ();
for (int i = 0; i <= n; ++i) g.add(new ArrayList < > ());
for (int i = 0; i < e; ++i) {
int u = ni(), v = ni(), w = ni();
g.get(u).add(new pair(w, v));
g.get(v).add(new pair(w, u));
}
return g;
}
//input methods
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b));
return b;
}
private double nd() {
return Double.parseDouble(ns());
}
private char nc() {
return (char) skip();
}
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m) {
char[][] map = new char[n][];
for (int i = 0; i < n; i++) map[i] = ns(m);
return map;
}
private int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = ni();
return a;
}
private int ni() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
private long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
private void tr(Object...o) {
if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
}
void watch(Object...a) throws Exception {
int i = 1;
print("watch starts :");
for (Object o: a) {
//print(o);
boolean notfound = true;
if (o.getClass().isArray()) {
String type = o.getClass().getName().toString();
//print("type is "+type);
switch (type) {
case "[I":
{
int[] test = (int[]) o;
print(i + " " + Arrays.toString(test));
break;
}
case "[[I":
{
int[][] obj = (int[][]) o;
print(i + " " + Arrays.deepToString(obj));
break;
}
case "[J":
{
long[] obj = (long[]) o;
print(i + " " + Arrays.toString(obj));
break;
}
case "[[J":
{
long[][] obj = (long[][]) o;
print(i + " " + Arrays.deepToString(obj));
break;
}
case "[D":
{
double[] obj = (double[]) o;
print(i + " " + Arrays.toString(obj));
break;
}
case "[[D":
{
double[][] obj = (double[][]) o;
print(i + " " + Arrays.deepToString(obj));
break;
}
case "[Ljava.lang.String":
{
String[] obj = (String[]) o;
print(i + " " + Arrays.toString(obj));
break;
}
case "[[Ljava.lang.String":
{
String[][] obj = (String[][]) o;
print(i + " " + Arrays.deepToString(obj));
break;
}
case "[C":
{
char[] obj = (char[]) o;
print(i + " " + Arrays.toString(obj));
break;
}
case "[[C":
{
char[][] obj = (char[][]) o;
print(i + " " + Arrays.deepToString(obj));
break;
}
default:
{
print(i + " type not identified");
break;
}
}
notfound = false;
}
if (o.getClass() == ArrayList.class) {
print(i + " al: " + o);
notfound = false;
}
if (o.getClass() == HashSet.class) {
print(i + " hs: " + o);
notfound = false;
}
if (o.getClass() == TreeSet.class) {
print(i + " ts: " + o);
notfound = false;
}
if (o.getClass() == TreeMap.class) {
print(i + " tm: " + o);
notfound = false;
}
if (o.getClass() == HashMap.class) {
print(i + " hm: " + o);
notfound = false;
}
if (o.getClass() == LinkedList.class) {
print(i + " ll: " + o);
notfound = false;
}
if (o.getClass() == PriorityQueue.class) {
print(i + " pq : " + o);
notfound = false;
}
if (o.getClass() == pair.class) {
print(i + " pq : " + o);
notfound = false;
}
if (notfound) {
print(i + " unknown: " + o);
}
i++;
}
print("watch ends ");
}
} | Java | ["3\n1 4 1"] | 2 seconds | ["9"] | null | Java 8 | standard input | [
"data structures",
"dsu",
"divide and conquer",
"sortings"
] | 38210a3dcb16ce2bbc81aa1d39d23112 | The first line contains one integer n (1ββ€βnββ€β106) β size of the array a. The second line contains n integers a1,βa2... an (1ββ€βaiββ€β106) β elements of the array. | 1,900 | Print one integer β the imbalance value of a. | standard output | |
PASSED | f97090860228fa4b3d5405aadc680877 | train_000.jsonl | 1497539100 | You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.For example, the imbalance value of array [1,β4,β1] is 9, because there are 6 different subsegments of this array: [1] (from index 1 to index 1), imbalance value is 0; [1,β4] (from index 1 to index 2), imbalance value is 3; [1,β4,β1] (from index 1 to index 3), imbalance value is 3; [4] (from index 2 to index 2), imbalance value is 0; [4,β1] (from index 2 to index 3), imbalance value is 3; [1] (from index 3 to index 3), imbalance value is 0; You have to determine the imbalance value of the array a. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]) {new Main().run();}
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
void run(){
work();
out.flush();
}
long mod=998244353;
long gcd(long a,long b) {
return b==0?a:gcd(b,a%b);
}
void work() {
int n=in.nextInt();
long[] A=new long[n];
for(int i=0;i<n;i++)A[i]=in.nextLong();
int[] maxL=new int[n];
int[] maxR=new int[n];
int[] minL=new int[n];
int[] minR=new int[n];
for(int i=0;i<n;i++) {
int index=i-1;
while(index!=-1&&A[index]<A[i]) {
index=maxL[index];
}
maxL[i]=index;
}
for(int i=n-1;i>=0;i--) {
int index=i+1;
while(index!=n&&A[index]<=A[i]) {
index=maxR[index];
}
maxR[i]=index;
}
for(int i=0;i<n;i++) {
int index=i-1;
while(index!=-1&&A[index]>A[i]) {
index=minL[index];
}
minL[i]=index;
}
for(int i=n-1;i>=0;i--) {
int index=i+1;
while(index!=n&&A[index]>=A[i]) {
index=minR[index];
}
minR[i]=index;
}
long ret=0;
for(int i=0;i<n;i++) {
ret+=A[i]*(maxR[i]-i)*(i-maxL[i]);
ret-=A[i]*(minR[i]-i)*(i-minL[i]);
}
out.println(ret);
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
public String next()
{
if(st==null || !st.hasMoreElements())
{
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt()
{
return Integer.parseInt(next());
}
public long nextLong()
{
return Long.parseLong(next());
}
} | Java | ["3\n1 4 1"] | 2 seconds | ["9"] | null | Java 8 | standard input | [
"data structures",
"dsu",
"divide and conquer",
"sortings"
] | 38210a3dcb16ce2bbc81aa1d39d23112 | The first line contains one integer n (1ββ€βnββ€β106) β size of the array a. The second line contains n integers a1,βa2... an (1ββ€βaiββ€β106) β elements of the array. | 1,900 | Print one integer β the imbalance value of a. | standard output | |
PASSED | a724a57aeb3da1d6b1e78bf5b048ddb9 | train_000.jsonl | 1497539100 | You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.For example, the imbalance value of array [1,β4,β1] is 9, because there are 6 different subsegments of this array: [1] (from index 1 to index 1), imbalance value is 0; [1,β4] (from index 1 to index 2), imbalance value is 3; [1,β4,β1] (from index 1 to index 3), imbalance value is 3; [4] (from index 2 to index 2), imbalance value is 0; [4,β1] (from index 2 to index 3), imbalance value is 3; [1] (from index 3 to index 3), imbalance value is 0; You have to determine the imbalance value of the array a. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;
public class D {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
int[] bGE = new int[n];
int[] aG = new int[n];
int[] bLE = new int[n];
int[] aL = new int[n];
Stack<Integer> stack = new Stack<>();
for (int i = 0; i < n; i++) {
bGE[i] = 0;
while(!stack.isEmpty() && a[stack.peek()] <= a[i])
stack.pop();
if(!stack.isEmpty())
bGE[i] = stack.peek() + 1;
stack.add(i);
}
stack = new Stack<>();
for (int i = 0; i < n; i++) {
bLE[i] = 0;
while(!stack.isEmpty() && a[stack.peek()] >= a[i])
stack.pop();
if(!stack.isEmpty())
bLE[i] = stack.peek() + 1;
stack.add(i);
}
stack = new Stack<>();
for (int i = n - 1; i >= 0; i--) {
aG[i] = n - 1;
while(!stack.isEmpty() && a[stack.peek()] < a[i])
stack.pop();
if(!stack.isEmpty())
aG[i] = stack.peek() - 1;
stack.add(i);
}
stack = new Stack<>();
for (int i = n - 1; i >= 0; i--) {
aL[i] = n - 1;
while(!stack.isEmpty() && a[stack.peek()] > a[i])
stack.pop();
if(!stack.isEmpty())
aL[i] = stack.peek() - 1;
stack.add(i);
}
long ans = 0;
for (int i = 0; i < n; i++)
ans += ((1l * (aG[i] - i + 1) * (i - bGE[i] + 1)) - (1l * (aL[i] - i + 1) * (i - bLE[i] + 1))) * a[i];
out.println(ans);
out.flush();
out.close();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream System){br = new BufferedReader(new InputStreamReader(System));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String nextLine()throws IOException{return br.readLine();}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public double nextDouble() throws IOException {return Double.parseDouble(next());}
public char nextChar()throws IOException{return next().charAt(0);}
public Long nextLong()throws IOException{return Long.parseLong(next());}
public boolean ready() throws IOException{return br.ready();}
public void waitForInput(){for(long i = 0; i < 3e9; i++);}
}
} | Java | ["3\n1 4 1"] | 2 seconds | ["9"] | null | Java 8 | standard input | [
"data structures",
"dsu",
"divide and conquer",
"sortings"
] | 38210a3dcb16ce2bbc81aa1d39d23112 | The first line contains one integer n (1ββ€βnββ€β106) β size of the array a. The second line contains n integers a1,βa2... an (1ββ€βaiββ€β106) β elements of the array. | 1,900 | Print one integer β the imbalance value of a. | standard output | |
PASSED | d499db0911fba46776b12ca139a14b6f | train_000.jsonl | 1497539100 | You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.For example, the imbalance value of array [1,β4,β1] is 9, because there are 6 different subsegments of this array: [1] (from index 1 to index 1), imbalance value is 0; [1,β4] (from index 1 to index 2), imbalance value is 3; [1,β4,β1] (from index 1 to index 3), imbalance value is 3; [4] (from index 2 to index 2), imbalance value is 0; [4,β1] (from index 2 to index 3), imbalance value is 3; [1] (from index 3 to index 3), imbalance value is 0; You have to determine the imbalance value of the array a. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;
import java.util.Stack;
public class ques4 {
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 static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
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 boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
public String next() {
return nextString();
}
public char nextChar(){
int c=read();
while (isSpaceChar(c)) {
c = read();
}
return (char)c;
}
public String nextString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public Long nextLong() {
return Long.parseLong(nextString());
}
public Double nextDouble() {
return Double.parseDouble(nextString());
}
}
public static void main(String[] args) {
InputReader s=new InputReader(System.in);
int n=s.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
a[i]=s.nextInt();
long ansmin=func(a);
for(int i=0;i<n;i++)
{
a[i]=-a[i];
}
long ansmax=-func(a);
System.out.println(ansmax-ansmin);
}
public static long func(int[] a)
{
Stack<Integer> st=new Stack<>();
int left[]=new int[a.length];
int right[]=new int[a.length];
for(int i=0;i<a.length;i++)
{
while(!st.isEmpty()&&a[st.peek()]>=a[i])
st.pop();
if(st.isEmpty())
left[i]=0;
else
left[i]=st.peek()+1;
st.push(i);
}
while(!st.isEmpty())
st.pop();
for(int i=a.length-1;i>=0;i--)
{
while(!st.isEmpty()&&a[st.peek()]>a[i])
st.pop();
if(st.isEmpty())
right[i]=a.length-1;
else
right[i]=st.peek()-1;
st.push(i);
}
long ans=0;
for(int i=0;i<a.length;i++)
{
ans+=a[i]*((right[i]-i+1)*(long)(i-left[i]+1));
}
return ans;
}
} | Java | ["3\n1 4 1"] | 2 seconds | ["9"] | null | Java 8 | standard input | [
"data structures",
"dsu",
"divide and conquer",
"sortings"
] | 38210a3dcb16ce2bbc81aa1d39d23112 | The first line contains one integer n (1ββ€βnββ€β106) β size of the array a. The second line contains n integers a1,βa2... an (1ββ€βaiββ€β106) β elements of the array. | 1,900 | Print one integer β the imbalance value of a. | standard output | |
PASSED | c18a69dfca0d3800c2999e4c9b4c67a9 | train_000.jsonl | 1497539100 | You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.For example, the imbalance value of array [1,β4,β1] is 9, because there are 6 different subsegments of this array: [1] (from index 1 to index 1), imbalance value is 0; [1,β4] (from index 1 to index 2), imbalance value is 3; [1,β4,β1] (from index 1 to index 3), imbalance value is 3; [4] (from index 2 to index 2), imbalance value is 0; [4,β1] (from index 2 to index 3), imbalance value is 3; [1] (from index 3 to index 3), imbalance value is 0; You have to determine the imbalance value of the array a. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.ArrayList;
public class D{
public static void main(String[] args)throws IOException {
Reader.init(System.in);
int n=Reader.nextInt();
node[] a=new node[n+1];
stack s=new stack();
for(int i=1;i<=n;i++)
a[i]=new node(Reader.nextInt());
//finding the greater element on right-->maxr
//System.out.println("maxr");
for(int i=1;i<=n;i++){
while(s.top!=null && a[i].val>=s.peek()){
s.pop().maxr=i;
}
s.push(a[i]);
//s.display();
//System.out.println("");
}
while(s.top!=null){
s.pop().maxr=a.length;
}
//finding the greater element on left-->maxl
//System.out.println("maxl");
for(int i=n;i>=1;i--){
while(s.top!=null && a[i].val>s.peek()){
s.pop().maxl=i;
}
s.push(a[i]);
//s.display();
//System.out.println("");
}
while(s.top!=null){
s.pop().maxl=0;
}
//finding the smaller element on right-->minr
//System.out.println("minr");
for(int i=1;i<=n;i++){
while(s.top!=null && a[i].val<=s.peek()){
s.pop().minr=i;
}
s.push(a[i]);
//s.display();
//System.out.println("");
}
while(s.top!=null){
s.pop().minr=a.length;
}
//finding the smaller element on left-->minl
//System.out.println("minl");
for(int i=n;i>=1;i--){
while(s.top!=null && a[i].val<s.peek()){
s.pop().minl=i;
}
s.push(a[i]);
//s.display();
//System.out.println("");
}
while(s.top!=null){
s.pop().minl=0;
}
long max=0,min=0,left,right;
for(int i=1;i<=n;i++){
left=i-a[i].maxl-1;
right=a[i].maxr-i-1;
max+=a[i].val*(left+right+left*right);
left=i-a[i].minl-1;
right=a[i].minr-i-1;
min+=a[i].val*(left+right+left*right);
}
System.out.println(max-min);
}
}
class stack{
node2 top=null;
void push(node n){
top=new node2(n,top);
}
node pop(){
node val=top.data;
top=top.link;
return val;
}
int peek(){
return top.data.val;
}
void display(){
node2 cur=top;
while(cur!=null){
System.out.print(cur.data.val+" ");
cur=cur.link;
}
}
}
class node2{
node data;
node2 link;
node2(node n, node2 l){
data=n;
link=l;
}
}
class node{
int val,maxl,maxr,minl,minr;
node(int v){
val=v;
}
}
/** Class for buffered reading int and double values */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static long nextLong() throws IOException {
return Long.parseLong( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
} | Java | ["3\n1 4 1"] | 2 seconds | ["9"] | null | Java 8 | standard input | [
"data structures",
"dsu",
"divide and conquer",
"sortings"
] | 38210a3dcb16ce2bbc81aa1d39d23112 | The first line contains one integer n (1ββ€βnββ€β106) β size of the array a. The second line contains n integers a1,βa2... an (1ββ€βaiββ€β106) β elements of the array. | 1,900 | Print one integer β the imbalance value of a. | standard output | |
PASSED | f1dc0f348e9095164d56ad9e3b2ac7fd | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes |
import java.util.*;
import java.util.Arrays;
import java.io.IOException;
import java.lang.*;
import java.math.BigDecimal;
import java.util.Scanner;
/* Name of the class has to be "Main" only if the class is public. */
public class Main {
static Scanner input = new Scanner(System.in);
public static void main(String [] args)
{
int n=0;
int d=0;
n = input.nextInt();
d = input.nextInt();
int count=0;
int [] k = new int[n];
int first = input.nextInt();
for(int j=1; j<n;j++)
{
k[j] = input.nextInt();
if(first >= k[j])
{
int t = (first + 1 - k[j]) / d + ((first + 1 - k[j]) % d == 0 ? 0 :1);
count += t;
first = k[j] + t * d;
}
else
{
first = k[j];
}
}
System.out.println(count);
//////////////////////////////////////////////
//////////
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | a861e68f62856270f295ed4427b22d3d | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.*;
public class IncreasingSequence {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int d = input.nextInt();
int [] arr = new int [n];
for(int i = 0; i < n; i++)
arr [i] = input.nextInt();
int counter = 0;
for(int i = 0; i < n - 1; i++){
if(arr [i] == arr [i + 1]){
counter ++;
arr [i + 1] += d;
}
else if(arr [i] > arr [i + 1]){
int diff = arr [i] - arr [i + 1];
if(diff < d){
counter ++;
arr [i + 1] += d;
}
else if(diff == d){
counter += 2;
arr [i + 1] += (d * 2);
}
else{
counter += ((diff / d) + 1);
arr [i + 1] += (((diff / d) + 1) * d);
}
}
}
System.out.println(counter);
}
} | Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 1287c69e50864e427a7882875f9c1f91 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.Scanner;
public class Ishu
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
int n,d,i,sum=0,diff,r;
int[] b=new int[2000];
n=scan.nextInt();
d=scan.nextInt();
for(i=0;i<n;++i)
{
b[i]=scan.nextInt();
if(i>0)
{
if(b[i]<=b[i-1])
{
diff=b[i-1]+1-b[i];
r=diff/d;
if(diff%d>0)
++r;
sum+=r;
b[i]+=r*d;
}
}
}
System.out.println(sum);
}
} | Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 0e48847f9b6971b5b0ed8568111cae53 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int d = in.nextInt();
int cur = in.nextInt();
int moves = 0;
for(int i = 1; i < n; i++){
int next = in.nextInt();
if(cur >= next){
moves += (cur - next) / d + 1;
cur = next + ((cur - next) / d + 1) * d;
}
else{
cur = next;
}
}
System.out.println(moves);
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | d345b1cc569052ab0ef8cdbb69e4c87f | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.*;
public class Slotuin {
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
int n = x.nextInt();
long d = x.nextLong();
long A0 = x.nextLong();
long A = 0;
long c = 0;
for(int i = 1;i < n;i++)
{
A = x.nextLong();
if(A0 >= A)
{
long z = (A0 - A)/d + 1;
c = c + z;
A0 = A + z * d;
}
else
{
A0 = A;
}
}
System.out.print(c);
x.close();
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 146db6e48316b21fb6aed1902054a4c1 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.Scanner;
public class Test {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int d = in.nextInt();
int move = 0;
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = in.nextInt();
}
int last = a[0];
for(int i=1;i<n;i++){
if(a[i]>last) {
last = a[i];
continue;
}
else{
int x = (last-a[i])/d;
x++;
last = a[i]+x*d;
move+=x;
}
}
System.out.println(move);
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | e3ab345f84946854876775a9589b38fb | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author captainTurtle
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n = in.nextInt();
int d = in.nextInt();
int dizi[] = new int[n];
int check;
int sayac = 0;
for (int i = 0; i < n; i++) {
dizi[i] = in.nextInt();
}
for (int i = 1; i < n; i++) {
if (dizi[i] > dizi[i - 1]) {
continue;
} else if (dizi[i] == dizi[i - 1]) {
dizi[i] += d;
sayac += 1;
} else {
check = (int) Math.ceil((dizi[i - 1] - dizi[i]) / (d / 1.0));
dizi[i] += d * check;
if (dizi[i] == dizi[i - 1]) {
check += 1;
dizi[i] += d;
}
sayac += check;
}
}
System.out.print(sayac);
}
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 4734bb14c219160fd6f87a9affdc9c90 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.Scanner;
public class Codeforces {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int a = in.nextInt();
int result = 0;
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
int k = in.nextInt();
arr[i] = k;
}
for (int i = 1; i < arr.length; i++) {
if (arr[i] <= arr[i - 1]) {
result+=((arr[i-1]-arr[i])/a)+1;
arr[i]+=(((arr[i-1]-arr[i])/a)+1)*a;
}
}
System.out.println(result);
}
} | Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | ae9e89f3806a4116ce28d2f6f7ec85f6 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.*;
import java.math.*;
public class Main{
public static void main(String [] args)
{
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int d=scan.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=scan.nextInt();
}
int ans=0;
for(int i=1;i<n;i++)
{
if(a[i]<=a[i-1])
{
int c =(int)(Math.ceil((a[i-1]-a[i]+1)/(d*1.0)));
ans +=c;
a[i] += d*c;
}
}
System.out.println(ans);
}
} | Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 14c65fe0cc338edccc14c02b7b73c08a | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.*;
//10:39
public class IncreasingSequence {
public static void main(String s[])
{
int nn,d;
Scanner inp = new Scanner(System.in);
int count=0;
nn= inp.nextInt();
d= inp.nextInt();
int arr[] = new int[nn];
for(int i=0;i<nn;i++)
arr[i]= inp.nextInt();
for(int i=1;i<arr.length;i++)
{
if(arr[i]>arr[i-1])
continue;
double n= (arr[i-1]-arr[i])/(double)d;
if( (n - (int)n) ==0)
n = n+1;
arr[i]+= Math.ceil(n)*d;
count+=Math.ceil(n);
}
System.out.println(count);
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 82bdda081963b2e145071de59e811a3e | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | //package main;
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) throws IOException {
Reader.init(System.in);
//StringBuffer outBuffer = new StringBuffer();
int N = Reader.nextInt();
int D = Reader.nextInt();
int[] B = new int[N];
int moves = 0;
int deltaM;
int difference;
for(int i = 0; i < N; i++) {
B[i] = Reader.nextInt();
}
for(int i = 0; i < N-1; i++) {
if(B[i] >= B[i+1]) {
difference = (B[i]+1) - B[i+1];
deltaM = (int)Math.ceil(((double)difference)/D);
B[i+1] += deltaM*D;
moves+=deltaM;
}
}
System.out.print(moves);
}
}
// Class for buffered reading int and double values
// From: http://www.cpe.ku.ac.th/~jim/java-io.html
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
//call this method to initialize reader for InputStream
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
//get next word
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
} | Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | a996c586ee1fbd80d82668dea0dcddbe | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.Scanner;
public class A11 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int d=sc.nextInt();
int res=0;
int prev=sc.nextInt();
for(int i=1; i < n; i++)
{
int next=sc.nextInt();
if(next<=prev){
res+=(prev-next)/d+1;
prev=next+((prev-next)/d + 1)*d;
}
else
prev=next;
}
System.out.println(res);
}
} | Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 9409456c5a61a97b6d83d58884855d4f | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | //http://codeforces.com/problemset/problem/11/A
import java.util.Scanner;
public class GrowingSequence {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int n = sc.nextInt(), d = Integer.parseInt(sc.nextLine().trim()), counter = 0;
int[] elements = new int[n];
for (int i = 0; i < n; i++){
elements[i] = sc.nextInt();
if (i > 0){
if (elements[i] < elements[i-1]){
double temp = Math.ceil(((double) elements[i-1] - (double) elements[i])/d);
elements[i] += d*temp;
counter+=temp;
}
if (elements[i] == elements[i-1]) {
elements[i] += d;
counter++;
}
}
}
System.out.println(counter);
}
} | Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 4340852fc1989f805b5c8bb7a0ec0ae8 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.io.*;
public class CF11A {
static int n, d, count = 0;
static String[] in;
static int[] b = new int[2001];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
in = br.readLine().split(" ");
n = Integer.parseInt(in[0]);
d = Integer.parseInt(in[1]);
in = br.readLine().split(" ");
for (int i = 0; i < n; i++) {
b[i] = Integer.parseInt(in[i]);
}
for (int i = 1; i < n; i++) {
if (b[i - 1] >= b[i]) {
int t = b[i - 1] - b[i];
int s = t / d + 1;
b[i] += s * d;
count += s;
}
}
bw.write(count + "\n");
bw.flush();bw.close();
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 80eb2fb2d7fe07d140deb828b30fd1df | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | //package kitsune;
import java.util.*;
public class increasingseq {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int d = s.nextInt();
int[] num = new int[n];
for(int i =0; i<n; i++){
num[i] = s.nextInt();
}
int diff;
int count = 0;
for(int i=0;i<n-1;i++){
int k =0;
if(!(num[i]<num[i+1])){
diff = num[i]-num[i+1];
if(diff == 0){
num[i+1] += d;
count++;
}
else{
int tmp = 0;
tmp = diff/d+1;
num[i+1] += tmp*d;
count += tmp;
//System.out.println(k);
}
}
}
//for(int x:num)
//System.out.printf("%s ",x);
System.out.println(count);
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 6cc3ba37d6e66bb6bc40cb4589a2c2a0 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.io.*;
/**
* Created by James on 1/29/2015.
*/
public class Driver {
public static void main(String [] args) throws IOException {
BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
String [] pieces = scanner.readLine().split("\\s+");
int N = Integer.parseInt(pieces[0]), D = Integer.parseInt(pieces[1]), count = 0, prev;
pieces = scanner.readLine().split("\\s+");
prev = Integer.parseInt(pieces[0]);
for (int i = 1; i < N; ++i) {
int cur = Integer.parseInt(pieces[i]);
if (cur <= prev) {
int diff = (int)Math.ceil((prev + 1 - cur) / (double)D);
diff = Math.max(diff, 1);
count += diff;
cur += diff * D;
}
prev = cur;
}
out.println(count);
out.close();
}
} | Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 86958eb3f3e154cc36ec56b8dea27733 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.awt.geom.AffineTransform;
import java.io.*;
import java.util.*;
public class A1008 {
public static void main(String [] args) /*throws Exception*/ {
InputStream inputReader = System.in;
OutputStream outputReader = System.out;
InputReader in = new InputReader(inputReader);//new InputReader(new FileInputStream(new File("input.txt")));new InputReader(inputReader);
PrintWriter out = new PrintWriter(outputReader);//new PrintWriter(new FileOutputStream(new File("output.txt")));
Algorithm solver = new Algorithm();
solver.solve(in, out);
out.close();
}
}
class Algorithm {
void solve(InputReader ir, PrintWriter pw) {
int n = ir.nextInt(), d = ir.nextInt(), count = 0;
int [] b = new int[n];
for (int i = 0; i < n; i++) b[i] = ir.nextInt();
for (int i = 1, num; i < n; i++) {
num = b[i - 1] - b[i];
if (num >= 0) {
count += num / d + 1;
b[i] += d * (num / d + 1);
}
}
pw.print(count);
}
boolean isPolyndrom(String str) {
StringBuilder newStr = new StringBuilder();
for (int i = str.length() - 1; i >= 0; i--) newStr.append(str.charAt(i));
return newStr.toString().equals(str);
}
private static void Qsort(int[] array, int low, int high) {
int i = low;
int j = high;
int x = array[low + (high - low) / 2];
do {
while (array[i] < x) ++i;
while (array[j] > x) --j;
if (i <= j) {
int tmp = array[i];
array[i] = array[j];
array[j] = tmp;
i++;
j--;
}
} while (i <= j);
if (low < j) Qsort(array, low, j);
if (i < high) Qsort(array, i, high);
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
String nextLine(){
String fullLine = null;
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
fullLine = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return fullLine;
}
return fullLine;
}
String [] toArray() {
return nextLine().split(" ");
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
} | Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 4dadf88f97d06bda9b252800e5d9b74d | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Locale;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
public class Main {
public static void main(String[] args) throws Exception {
solve(1);
}
public static void solve(int testCases) throws Exception{
int n = StdIn.readInt();
int d = StdIn.readInt();
int[] b = new int[n];
for(int i = 0 ; i < n ; i++) b[i] = StdIn.readInt();
int moves = 0;
for(int i = 1 ; i < n ; i++){
if(b[i] > b[i-1])
continue;
else if(b[i] == b[i-1]){
b[i] = b[i-1] + d;
moves++;
continue;
}
int diff = (b[i-1] - b[i] + 1);
int count = (diff/d);
if(diff % d == 0){
moves += count;
b[i] += (count * d);
}
else{
moves += (count + 1);
b[i] += (count+1)*d;
}
//StdOut.println(i + " : " + moves);
}
StdOut.println(moves);
}
}
final class StdIn {
private StdIn() { }
private static Scanner scanner;
private static final String CHARSET_NAME = "UTF-8";
private static final Locale LOCALE = Locale.US;
private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\p{javaWhitespace}+");
private static final Pattern EMPTY_PATTERN = Pattern.compile("");
private static final Pattern EVERYTHING_PATTERN = Pattern.compile("\\A");
public static boolean isEmpty() {
return !scanner.hasNext();
}
public static boolean hasNextLine() {
return scanner.hasNextLine();
}
public static boolean hasNextChar() {
scanner.useDelimiter(EMPTY_PATTERN);
boolean result = scanner.hasNext();
scanner.useDelimiter(WHITESPACE_PATTERN);
return result;
}
public static String readLine() {
String line;
try { line = scanner.nextLine(); }
catch (Exception e) { line = null; }
return line;
}
public static char readChar() {
scanner.useDelimiter(EMPTY_PATTERN);
String ch = scanner.next();
assert (ch.length() == 1) : "Internal (Std)In.readChar() error!"
+ " Please contact the authors.";
scanner.useDelimiter(WHITESPACE_PATTERN);
return ch.charAt(0);
}
public static String readAll() {
if (!scanner.hasNextLine())
return "";
String result = scanner.useDelimiter(EVERYTHING_PATTERN).next();
// not that important to reset delimeter, since now scanner is empty
scanner.useDelimiter(WHITESPACE_PATTERN); // but let's do it anyway
return result;
}
public static String readString() {
return scanner.next();
}
public static int readInt() {
return scanner.nextInt();
}
public static double readDouble() {
return scanner.nextDouble();
}
public static float readFloat() {
return scanner.nextFloat();
}
public static long readLong() {
return scanner.nextLong();
}
public static short readShort() {
return scanner.nextShort();
}
public static byte readByte() {
return scanner.nextByte();
}
public static boolean readBoolean() {
String s = readString();
if (s.equalsIgnoreCase("true")) return true;
if (s.equalsIgnoreCase("false")) return false;
if (s.equals("1")) return true;
if (s.equals("0")) return false;
throw new InputMismatchException();
}
public static String[] readAllStrings() {
// we could use readAll.trim().split(), but that's not consistent
// because trim() uses characters 0x00..0x20 as whitespace
String[] tokens = WHITESPACE_PATTERN.split(readAll());
if (tokens.length == 0 || tokens[0].length() > 0)
return tokens;
// don't include first token if it is leading whitespace
String[] decapitokens = new String[tokens.length-1];
for (int i = 0; i < tokens.length - 1; i++)
decapitokens[i] = tokens[i+1];
return decapitokens;
}
public static String[] readAllLines() {
ArrayList<String> lines = new ArrayList<String>();
while (hasNextLine()) {
lines.add(readLine());
}
return lines.toArray(new String[0]);
}
public static int[] readAllInts() {
String[] fields = readAllStrings();
int[] vals = new int[fields.length];
for (int i = 0; i < fields.length; i++)
vals[i] = Integer.parseInt(fields[i]);
return vals;
}
public static double[] readAllDoubles() {
String[] fields = readAllStrings();
double[] vals = new double[fields.length];
for (int i = 0; i < fields.length; i++)
vals[i] = Double.parseDouble(fields[i]);
return vals;
}
static {
resync();
}
private static void resync() {
setScanner(new Scanner(new java.io.BufferedInputStream(System.in), CHARSET_NAME));
}
private static void setScanner(Scanner scanner) {
StdIn.scanner = scanner;
StdIn.scanner.useLocale(LOCALE);
}
public static int[] readInts() {
return readAllInts();
}
public static double[] readDoubles() {
return readAllDoubles();
}
public static String[] readStrings() {
return readAllStrings();
}
}
final class StdOut {
private static final String CHARSET_NAME = "UTF-8";
private static final Locale LOCALE = Locale.US;
private static PrintWriter out;
static {
try {
out = new PrintWriter(new OutputStreamWriter(System.out, CHARSET_NAME), true);
}
catch (UnsupportedEncodingException e) { System.out.println(e); }
}
private StdOut() { }
public static void close() {
out.close();
}
public static void println() {
out.println();
}
public static void println(Object x) {
out.println(x);
}
public static void println(boolean x) {
out.println(x);
}
public static void println(char x) {
out.println(x);
}
public static void println(double x) {
out.println(x);
}
public static void println(float x) {
out.println(x);
}
public static void println(int x) {
out.println(x);
}
public static void println(long x) {
out.println(x);
}
public static void println(short x) {
out.println(x);
}
public static void println(byte x) {
out.println(x);
}
public static void print() {
out.flush();
}
public static void print(Object x) {
out.print(x);
out.flush();
}
public static void print(boolean x) {
out.print(x);
out.flush();
}
public static void print(char x) {
out.print(x);
out.flush();
}
public static void print(double x) {
out.print(x);
out.flush();
}
public static void print(float x) {
out.print(x);
out.flush();
}
public static void print(int x) {
out.print(x);
out.flush();
}
public static void print(long x) {
out.print(x);
out.flush();
}
public static void print(short x) {
out.print(x);
out.flush();
}
public static void print(byte x) {
out.print(x);
out.flush();
}
public static void printf(String format, Object... args) {
out.printf(LOCALE, format, args);
out.flush();
}
public static void printf(Locale locale, String format, Object... args) {
out.printf(locale, format, args);
out.flush();
}
} | Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 1cb56a4ef3d1037a18b10a82424f5128 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.Scanner;
public class Task11A {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int d = scn.nextInt();
int[] b = new int[n];
for (int i = 0; i < n; i++) {
b[i] = scn.nextInt();
}
int x = 0;
for (int i = 1; i < n; i++) {
if (b[i] <= b[i - 1]) {
int kol = (b[i - 1] - b[i]) / d + 1;
x = x + kol;
b[i] = b[i] + d * kol;
}
}
System.out.println(x);
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | eb4cbba3283cb896359ee219f2279007 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.Scanner;
public class Increasing {
static Scanner sr = new Scanner(System.in);
public static void main(String args[]){
int n = sr.nextInt();
int d = sr.nextInt();
int a[] = new int[n];
for (int i = 0; i < n; i++){
a[i] = sr.nextInt();
}
int b = 0;
for (int i = 1; i < n; i++){
if (a[i] <= a[i-1]){
b = b + ((a[i-1]-a[i])/d + 1);
a[i] = a[i] + d * ((a[i-1]-a[i])/d + 1);}
}
System.out.println(b);
}
} | Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 9fdcf66ab736504a05ceb0a7c577d057 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes |
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
Reader sc = new Reader();
int n = sc.nextInt();
int d = sc.nextInt();
int ans = 0;
int curr;
int prev = sc.nextInt();
int tries = 0;
for (int i = 1; i < n; i++) {
curr = sc.nextInt();
while (true) {
if (curr < prev) {
tries = (prev - curr + d - 1) / d;
ans += tries;
curr += tries * d;
}
else if (curr == prev) {
ans += 1;
curr += d;
}
else break;
}
// while (curr <= prev) {
// ans++;
// curr += d;
// }
prev = curr;
}
System.out.println(ans);
}
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | ebfe32d835abdb1a37f3b6586b643b92 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.Scanner;
public class IncreasingSequence {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n=scan.nextInt();
int d=scan.nextInt();
int b0=0,c=0;;
while(n-->0)
{
int b=scan.nextInt();
if(b<=b0)
{
int x=(b0-b)/d+1;
c+=x;
b0=b+x*d;
}
else
{
b0=b;
}
}
System.out.println(c);
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 4365ab0b56916fb8644b8310d168d268 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int n = Integer.parseInt(scan.next());
int d = Integer.parseInt(scan.next());
int[] b = new int[n];
for(int i=0; i<n; i++)
b[i] = Integer.parseInt(scan.next());
int moves = 0;
for(int i=1; i<n; i++)
{
if(b[i] <= b[i-1])
{
int k = (b[i-1]-b[i])/d;
k++;
moves+=k;
b[i]+=k*d;
}
}
System.out.println(moves);
}
} | Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 4607d7aebe4e455e1b37ce8806f2e6aa | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | public class IncreasingSequence {
public static void main(String[] args) {
try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
int n = sc.nextInt();
int d = sc.nextInt();
int s = 0;
int bin = Integer.MIN_VALUE;
for (int i = 0; i < n; i++) {
int b = sc.nextInt();
if (b <= bin) {
int diff = (bin - b) / d + 1;
s += diff;
bin = b + diff * d;
} else {
bin = b;
}
}
System.out.println(s);
}
}
} | Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 817f336fe275d5d304e947f16f78e7a9 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.ArrayList;
import java.util.Scanner;
import java.util.stream.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
int n=0, d=0;
ArrayList<Integer> container=new ArrayList<Integer>();
Scanner scn=new Scanner(System.in);
n=scn.nextInt();
d=scn.nextInt();
//I method
for(int i=0; i<n; i++)
container.add(scn.nextInt());
//method II
//container=(ArrayList<Integer>) Stream.of(scn.nextLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
scn.close();
/* System.out.print("n=" + n + " d= " +d);
System.out.println();
System.out.print(container);
*/
int ans=0;
for(int i=0; i<n-1; i++) {
if(container.get(i)>=container.get(i+1)) {
//I method
/*while(container.get(i)>=container.get(i+1)) {
int item = container.get(i+1)+d;
container.set(i+1,item);
ans++;
}
//end while loop
*/
//method II
int difference=container.get(i)-container.get(i+1);
int required_d=difference/d+1;
container.set(i+1, container.get(i+1)+required_d*d);
ans+=required_d;
}
}
//and for loop
System.out.println(ans);
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 6db7db20517dcb953566a196902a473d | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.*;
import java.io.*;
public class P11A {
private static void solve() {
int n = nextInt();
int d = nextInt();
int last = nextInt();
long ans = 0;
for (int i = 1; i < n; i++) {
int cur = nextInt();
if (cur < last) {
int diff = last - cur;
int count = diff / d + 1;
cur += d * count;
ans += count;
} else if (cur == last) {
cur += d;
ans++;
}
last = cur;
}
System.out.println(ans);
}
private static void run() {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
private static StringTokenizer st;
private static BufferedReader br;
private static PrintWriter out;
private static String next() {
while (st == null || !st.hasMoreElements()) {
String s;
try {
s = br.readLine();
} catch (IOException e) {
return null;
}
st = new StringTokenizer(s);
}
return st.nextToken();
}
private static int nextInt() {
return Integer.parseInt(next());
}
private static long nextLong() {
return Long.parseLong(next());
}
public static void main(String[] args) {
run();
}
} | Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 68199e1c6f6eec86a09aeca0332924eb | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes |
import java.util.Scanner;
public class IncreasingSequence {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(), d = in.nextInt();
int[] nums = new int[n];
int move = 0;
for (int i = 0; i < n; i++) {
nums[i] = in.nextInt();
if (i > 0 && nums[i] <= nums[i-1]) {
int tmp = (nums[i-1] - nums[i])/d+1;
move += tmp;
nums[i] += d*tmp;
}
}
System.out.println(move);
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | ecd2b16006bdad221753325804272982 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
// InputStream inputStream = new FileInputStream("sum.in");
OutputStream outputStream = System.out;
// OutputStream outputStream = new FileOutputStream("sum.out");
// Path path = Paths.get(URI.create("file:///foo/bar/Main.java"));
// System.out.print(path.getName(200));
// Path p = Paths.get("/foo/bar/Main.java");
// for (Path e : p) {
// System.out.println(e);
// }
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Answer solver = new Answer();
solver.solve(in, out);
out.close();
}
}
class Answer {
private final int INF = (int) (1e9 + 7);
private final int MOD = (int) (1e9 + 7);
private final int MOD1 = (int) (1e6 + 3);
private final long INF_LONG = (long) (1e18 + 1);
private final double EPS = 1e-9;
public void solve(InputReader in, PrintWriter out) throws IOException {
int n = in.nextInt();
int d = in.nextInt();
long[] b = in.nextArrayLong(n);
long ans = 0;
for (int i = 1; i < n; i++) {
long kol = 0;
if (b[i] <= b[i - 1]) {
kol = (b[i - 1] - b[i]) / d + 1;
}
ans += kol;
b[i] += 1L * kol * d;
}
out.println(ans);
// for (int i = 0; i < n; i++) {
// out.print(b[i] + " ");
// }
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int[] nextArrayInt(int count) {
int[] a = new int[count];
for (int i = 0; i < count; i++) {
a[i] = nextInt();
}
return a;
}
public long[] nextArrayLong(int count) {
long[] a = new long[count];
for (int i = 0; i < count; i++) {
a[i] = nextLong();
}
return a;
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | 00dda7aa9d289528bbce05e9dea47814 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
FastScanner input = new FastScanner();
int N = input.nextInt();
int d = input.nextInt();
long[] arr = new long[N];
for (int i = 0; i < N; i++) arr[i] = input.nextLong();
int count = 0;
for (int i = 1; i < N; i++) {
if (arr[i - 1] >= arr[i]) {
int change = (int) Math.ceil((arr[i - 1] - arr[i] + 1 * 1.00) / d);
arr[i] += change * d;
count += change;
}
}
System.out.println(count);
}
// https://github.com/detel/Faster-InputOutput-Implementations/blob/master/FastScanner.java
// Fast I/O
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
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) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | a3954c55fc7d0308d744d68688db4669 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes | import java.util.Scanner;
public class A11 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int i;
int k=0,k1=0;
int n=scan.nextInt();
int d=scan.nextInt();
scan.nextLine();
int []a=new int[n];
for(i=0;i<n;i++)
a[i]=scan.nextInt();
for(i=1;i<n;i++)
{
if (a[i]<=a[i-1])
{
k=(a[i-1]-a[i])/d+1;
a[i]+=d*k;
k1+=k;
}
}
System.out.println(k1);
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | e539e277a8366efdb17cd458f37a0072 | train_000.jsonl | 1272294000 | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing? | 64 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
*
* @author Haya
*/
public class JavaApplication141 {
public static void main(String[] args) {
FastReader in = new FastReader();
int n = in.nextInt();
int dif = in.nextInt();
int nums[] = new int[n];
for (int i = 0; i < n; i++) {
nums[i]=in.nextInt();
}
int count = 0;
for (int i = 1; i < n; i++) {
if (nums[i-1]<nums[i])
continue;
int toadd = (int) Math.ceil((nums[i-1]-nums[i]+1)/(dif*1.0));
count += toadd;
nums[i]+=toadd*dif;
}
System.out.println(count);
}
public 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 string = "";
try {
string = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return string;
}
}
}
| Java | ["4 2\n1 3 3 2"] | 1 second | ["3"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 0c5ae761b046c021a25b706644f0d3cd | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | 900 | Output the minimal number of moves needed to make the sequence increasing. | standard output | |
PASSED | ea73b196c13c97910bc2efa58478f63b | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class newyear {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int nq=s.nextInt();
while(nq-->0) {
System.out.println((60*(23-s.nextInt()))+60-s.nextInt());
}
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 68d999b3b31fd9804b6854aea8146c66 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class MinutesBeforetheNewYear
{
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
int n =sc.nextInt();
int i=0;
for(i=0;i<n;i++)
{
int a=sc.nextInt();
int b=sc.nextInt();
if(b==0)
{
System.out.println((24-a)*60);
}
else
{
System.out.println((23-a)*60+(60-b));
}
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 3b2b8117108ded2a8b047ef5bdcf7d9c | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class stack
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int htm=0;
int min=0;
int n=s.nextInt();
for(int i=0;i<n;i++) {
int h=s.nextInt();
int m=s.nextInt();
htm=((24-h)*60);
min=htm-m;
System.out.println(min);
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 063d0f194198d2f9e1d6217afc3aa291 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | 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 Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t =sc.nextInt();
while(t-- > 0){
int h = sc.nextInt(), m = sc.nextInt();
System.out.println((23 - h) * 60 + 60 - m);
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | cdaf2f0b1e43c2d4c0c6862b8d076f91 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class Solution{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int h = sc.nextInt();
int m = sc.nextInt();
h *=60;
System.out.println(1440-h-m);
}
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 45fd1eb980c28bc53658372973372d9f | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int h=sc.nextInt();
int m=sc.nextInt();
int k=23-h;
int p=60-m;
System.out.println(k*60+p);
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 749a4b65b7478312d337131d8ca28ad6 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class file{
public static void main(String[] args){
Scanner s=new Scanner(System.in);
int test =s.nextInt();
for(int i=0 ;i<test ;i++){
int h =s.nextInt();
int m =s.nextInt();
System.out.println(1440 - ( (h * 60)+m));
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 9999fb1e3372bfa50f273f04652af9e1 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes |
import java.util.*;
public class MinutesBeforeNewYear
{
static Scanner s1=new Scanner(System.in);
public static void main(String[] args)
{
int x=s1.nextInt();
int[] y=new int[2];
for(int i=0;i<x;i++)
{
for(int a=0;a<2;a++)
{
y[a]=s1.nextInt();
}
System.out.println((23-y[0])*60+(60-y[1]));
}
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 6929667f4caaf1287a8bab0521c142c5 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testCases = sc.nextInt(),x,y,z;
for (int i = 0; i < testCases; i++) {
x=sc.nextInt();
y=sc.nextInt();
System.out.println((24*60)-((x*60)+y));
}
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 7a78d6671b4ce50eebdb342f641cc288 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class Main implements Runnable {
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
}
catch (IOException e) {
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
public static void main(String args[]) throws Exception {
new Thread(null, new Main(),"Main",1<<27).start();
}
public void run() {
InputReader sc = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
for(int x = 0; x < t; ++x) {
int h = sc.nextInt();
int m = sc.nextInt();
int ans = 60 - m + (24 - h - 1) * 60;
out.println(ans);
}
out.close();
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 4facc8ff618ec981862a84737d9d354a | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 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 sc=new Scanner(System.in);
int tst=sc.nextInt();
while(--tst>=0)
{
int hr=sc.nextInt();
int min=sc.nextInt();
long var=((23-hr)*60)+(60-min);
System.out.println(var);
}
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | db1a031ae71b1d2b160151ffba0a8f4f | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class Minute {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for (; n >0; n--) {
int hour = in.nextInt();
int minut = in.nextInt();
int total = 60 * (23 - hour) + (60 - minut);
System.out.println(total);
}
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 8b54f779f0881bb1cc0bf405712d72a5 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes |
import java.util.Scanner;
/**
*
* @author SAKIB UDDIN
*/
public class C19 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int p = 0;
int n = in.nextInt();
for (int i = 0; i < n; i++) {
int x = in.nextInt();
int y = in.nextInt();
p = ((23 - x) * 60) + (60 - y);
System.out.println(p);
}
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | c6c59ed142d26eb39a5468d1647198b2 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class mins
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
while(n-->0)
{
String[] input=br.readLine().split(" ");
int h=Integer.parseInt(input[0]);
int min=Integer.parseInt(input[1]);
int l=(24-h)*60-min;
System.out.println(l);
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | f130e08f42e91a7616d4683dbf262aa3 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class mins
{
public static void main(String args[])
{
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
while(n-->0)
{
int h=scan.nextInt();
int min=scan.nextInt();
int l=(24-h)*60-min;
System.out.println(l);
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 16c9c2f821623b12612fd40fb8ffa952 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class newyear
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
int h,m;
while(t>0)
{
--t;
h=sc.nextInt();
m=sc.nextInt();
System.out.println((23-h)*60 + (60-m));
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | ba6f9e6a9ade8dfaa457f07550340fb0 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 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 h=sc.nextInt();
int m=sc.nextInt();
int min=0;
min=1440-((h*60)+m);
System.out.println(min);
t--;
}
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | be8032bf26c5519472d476e5f7ef5b2e | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class newyear {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
int a=23;
int b=60;
int e=0;
while (t!=0) {
int c=s.nextInt();
int d=s.nextInt();
if(a-c>=0) {
e=(a-c)*60;
}
if(b-d>0) {
e=e+(b-d);
}
System.out.println(e);
t--;
}
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | f41601d8b3101b0ee74a41e098b0ebe1 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author ch
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int t = in.nextInt();
for (int tt = 0; tt < t; tt++) {
out.println(60 * (23 - in.nextInt()) + 60 - in.nextInt());
}
}
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 2e9aef2b938d5745b0dce13cdb37fd10 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class NewYear {
public static void main(String[] args) {
NewYear newYear = new NewYear();
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
for (int i = 0 ; i < T ; i++) {
int h = scanner.nextInt();
int m = scanner.nextInt();
int remainingTime = newYear.findRemainingTime(h,m);
System.out.println(remainingTime);
}
}
private int findRemainingTime(int h, int m) {
if (h == 0 && m == 0 ) {
return 0;
}
if (h >= 0) {
return (24-h) * 60 - m;
}
return 0;
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | bcffdbfd055405279958b25b79e5d780 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int o =sc.nextInt();
while(o-->0) {
int sum=24*60;
int a=sc.nextInt()*60;
int b=sc.nextInt();
System.out.println(sum-a-b);
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | b1dbf611aa9f1e886fc41c03a1e4adce | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
FastIO fastIO = new FastIO();
StringBuilder output = new StringBuilder();
int t,h,m;
t=fastIO.readInt();
while(t-->0)
{
h=fastIO.readInt();
m=fastIO.readInt();
output.append((23-h)*60 + (60-m));
output.append("\n");
}
System.out.println(output.toString());
}
private static class FastIO
{
private StringTokenizer stringTokenizer;
private BufferedReader bufferedReader;
public FastIO()
{
bufferedReader = new BufferedReader(new InputStreamReader(System.in));
stringTokenizer = null;
}
public String read()
{
if (stringTokenizer == null || !stringTokenizer.hasMoreTokens())
{
try
{
stringTokenizer = new StringTokenizer(bufferedReader.readLine());
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
return stringTokenizer.nextToken();
}
public int readInt()
{
return Integer.parseInt(read());
}
public long readLong()
{
return Long.parseLong(read());
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 8f00e5520a13d9690baf9d2b13f344e3 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes |
import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
for (int i = 0 ; i < t ; i++) {
int h = scan.nextInt();
int m = scan.nextInt();
System.out.println(((23 - h) * 60) + (60 - m));
}
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | df5d594e5144da8e2425320b4382ca43 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class A{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
int T=s.nextInt();
for(int y=0;y<T;y++){
int hr=s.nextInt();
int min=s.nextInt();
int ans=0;
while(hr!=0||min!=0){
ans++;
min++;
if(min==60){
min=0;
hr++;
if(hr==24)
hr=0;
}
}
System.out.println(ans);
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 8ab925dbc1c67d59f2e8bb4b75dac4e2 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | /*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
****************************************
*/
import java.util.*;
import java.awt.Point;
import java.lang.Math;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Scanner;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Comparator;
import java.util.stream.IntStream;
public class Main {
static int oo = (int)1e9;
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
MuskA solver = new MuskA();
solver.solve(1, in, out);
out.close();
}
static class MuskA {
static int inf = (int) 1e9 + 7;
public void solve(int testNumber, Scanner in, PrintWriter out) {
int t = in.nextInt();
int z=1440;
while(t-->0){
int h= in.nextInt();
int m = in.nextInt();
int i=(h*60+m);
int ans=z-i;
out.println(ans);
}
}
}
public int factorial(int n) {
int fact = 1;
int i = 1;
while(i <= n) {
fact *= i;
i++;
}
return fact;
}
public static long gcd(long x,long y)
{
if(x%y==0)
return y;
else
return gcd(y,x%y);
}
public static int gcd(int x,int y)
{
if(x%y==0)
return y;
else
return gcd(y,x%y);
}
public static int abs(int a,int b)
{
return (int)Math.abs(a-b);
}
public static long abs(long a,long b)
{
return (long)Math.abs(a-b);
}
public static int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
public static int min(int a,int b)
{
if(a>b)
return b;
else
return a;
}
public static long max(long a,long b)
{
if(a>b)
return a;
else
return b;
}
public static long min(long a,long b)
{
if(a>b)
return b;
else
return a;
}
public static long pow(long n,long p,long m)
{
long result = 1;
if(p==0)
return 1;
if (p==1)
return n;
while(p!=0)
{
if(p%2==1)
result *= n;
if(result>=m)
result%=m;
p >>=1;
n*=n;
if(n>=m)
n%=m;
}
return result;
}
public static long pow(long n,long p)
{
long result = 1;
if(p==0)
return 1;
if (p==1)
return n;
while(p!=0)
{
if(p%2==1)
result *= n;
p >>=1;
n*=n;
}
return result;
}
static long sort(int a[]){
int n=a.length;
int b[]=new int[n];
return mergeSort(a,b,0,n-1);
}
static long mergeSort(int a[],int b[],long left,long right){
long c=0;
if(left<right){
long mid=left+(right-left)/2;
c= mergeSort(a,b,left,mid);
c+=mergeSort(a,b,mid+1,right);
c+=merge(a,b,left,mid+1,right);
}
return c;
}
static long merge(int a[],int b[],long left,long mid,long right){
long c=0;int i=(int)left;int j=(int)mid; int k=(int)left;
while(i<=(int)mid-1&&j<=(int)right){
if(a[i]<=a[j]){
b[k++]=a[i++];
}
else{
b[k++]=a[j++];c+=mid-i;
}
}
while (i <= (int)mid - 1)
b[k++] = a[i++];
while (j <= (int)right)
b[k++] = a[j++];
for (i=(int)left; i <= (int)right; i++)
a[i] = b[i];
return c;
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 79e9573cdd22826e5365ecebe452aa0b | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | public class Solution {
public static void main(String[] args) {
java.util.Scanner scanner = new java.util.Scanner(System.in);
java.time.LocalTime ny = java.time.LocalTime.of(23, 59);
int n = scanner.nextInt();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
java.time.LocalTime time = java.time.LocalTime.of(scanner.nextInt(), scanner.nextInt());
java.time.LocalTime nt = ny.minusMinutes((time.getHour() * 60) + time.getMinute());
sb.append(nt.getHour() * 60 + nt.getMinute() + 1).append('\n');
}
System.out.println(sb.toString());
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 7ab14c71984c3409ff7ea1975e9e227c | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | /* @nikhil_supertramp */
import java.awt.*;
import java.io.*;
import java.math.*;
import java.util.*;
public class MinutesBeforeTheNewYear
{
public static void main(String[] args)throws Exception
{
new Solver().solve();
}
}
class Solver {
final Helper hp;
final int MAXN = 1000_006;
final long MOD = (long) 1e9 + 7;
////javac -d ../../classes MinutesBeforeTheNewYear
//problem link : https://codeforces.com/contest/978/problem/F
void solve() throws Exception
{
for(int tc = hp.nextInt(); tc > 0; tc--)
{
int h = hp.nextInt();
int m = hp.nextInt();
int ans = process(h, m);
hp.println(ans);
}
hp.flush();
}
int process(int hours, int minutes)
{
int total_mins = 0;
total_mins += ((60 * hours) + minutes);
return (1440 - total_mins) % 1440;
}
Solver() {
hp = new Helper(MOD, MAXN);
hp.initIO(System.in, System.out);
}
}
class Helper {
final long MOD;
final int MAXN;
final Random rnd;
public Helper(long mod, int maxn) {
MOD = mod;
MAXN = maxn;
rnd = new Random();
}
public static int[] sieve;
public static ArrayList<Integer> primes;
public void setSieve() {
primes = new ArrayList<>();
sieve = new int[MAXN];
int i, j;
for (i = 2; i < MAXN; ++i)
if (sieve[i] == 0) {
primes.add(i);
for (j = i; j < MAXN; j += i) {
sieve[j] = i;
}
}
}
public static long[] factorial;
public void setFactorial() {
factorial = new long[MAXN];
factorial[0] = 1;
for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD;
}
public long getFactorial(int n) {
if (factorial == null) setFactorial();
return factorial[n];
}
public long ncr(int n, int r) {
if (r > n) return 0;
if (factorial == null) setFactorial();
long numerator = factorial[n];
long denominator = factorial[r] * factorial[n - r] % MOD;
return numerator * pow(denominator, MOD - 2, MOD) % MOD;
}
public long[] getLongArray(int size) throws Exception {
long[] ar = new long[size];
for (int i = 0; i < size; ++i) ar[i] = nextLong();
return ar;
}
public int[] getIntArray(int size) throws Exception {
int[] ar = new int[size];
for (int i = 0; i < size; ++i) ar[i] = nextInt();
return ar;
}
public int[] getIntArray(String s)throws Exception
{
s = s.trim().replaceAll("\\s+", " ");
String[] strs = s.split(" ");
int[] arr = new int[strs.length];
for(int i = 0; i < strs.length; i++)
{
arr[i] = Integer.parseInt(strs[i]);
}
return arr;
}
public long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
public int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
public long max(long[] ar) {
long ret = ar[0];
for (long itr : ar) ret = Math.max(ret, itr);
return ret;
}
public int max(int[] ar) {
int ret = ar[0];
for (int itr : ar) ret = Math.max(ret, itr);
return ret;
}
public long min(long[] ar) {
long ret = ar[0];
for (long itr : ar) ret = Math.min(ret, itr);
return ret;
}
public int min(int[] ar) {
int ret = ar[0];
for (int itr : ar) ret = Math.min(ret, itr);
return ret;
}
public long sum(long[] ar) {
long sum = 0;
for (long itr : ar) sum += itr;
return sum;
}
public long sum(int[] ar) {
long sum = 0;
for (int itr : ar) sum += itr;
return sum;
}
public void shuffle(int[] ar) {
int r;
for (int i = 0; i < ar.length; ++i) {
r = rnd.nextInt(ar.length);
if (r != i) {
ar[i] ^= ar[r];
ar[r] ^= ar[i];
ar[i] ^= ar[r];
}
}
}
public void shuffle(long[] ar) {
int r;
for (int i = 0; i < ar.length; ++i) {
r = rnd.nextInt(ar.length);
if (r != i) {
ar[i] ^= ar[r];
ar[r] ^= ar[i];
ar[i] ^= ar[r];
}
}
}
public long pow(long base, long exp, long MOD) {
base %= MOD;
long ret = 1;
while (exp > 0) {
if ((exp & 1) == 1) ret = ret * base % MOD;
base = base * base % MOD;
exp >>= 1;
}
return ret;
}
static byte[] buf = new byte[1000_006];
static int index, total;
static InputStream in;
static BufferedWriter bw;
public void initIO(InputStream is, OutputStream os) {
try {
in = is;
bw = new BufferedWriter(new OutputStreamWriter(os));
} catch (Exception e) {
}
}
public void initIO(String inputFile, String outputFile) {
try {
in = new FileInputStream(inputFile);
bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(outputFile)));
} catch (Exception e) {
}
}
private int scan() throws Exception {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0)
return -1;
}
return buf[index++];
}
public String nextLine() throws Exception {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c >= 32; c = scan())
sb.append((char) c);
return sb.toString();
}
public String next() throws Exception {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan())
sb.append((char) c);
return sb.toString();
}
public int nextInt() throws Exception {
int c, val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+')
c = scan();
for (; c >= '0' && c <= '9'; c = scan())
val = (val << 3) + (val << 1) + (c & 15);
return neg ? -val : val;
}
public long nextLong() throws Exception {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+')
c = scan();
for (; c >= '0' && c <= '9'; c = scan())
val = (val << 3) + (val << 1) + (c & 15);
return neg ? -val : val;
}
public void print(Object a) throws Exception {
bw.write(a.toString());
}
public void printsp(Object a) throws Exception {
print(a);
print(" ");
}
public void println() throws Exception {
bw.write("\n");
}
public void println(Object a) throws Exception {
print(a);
println();
}
public void flush() throws Exception {
bw.flush();
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | fe29424eb1d2555f7c2374cd311fd929 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
while (T > 0) {
T--;
int answer = 0;
int N = scanner.nextInt();
int K = scanner.nextInt();
if(N == 0 && K == 0) {
System.out.println(answer);
continue;
}
answer = 1440 - (N * 60 + K);
System.out.println(answer);
}
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | e365adb263dae88c86f2cb9b190e37c0 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes |
import java.util.*;
public class time {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
n = sc.nextInt();
int hr[] = new int[n];
int min[] = new int[n];
int ans[] = new int[n];
for(int i=0;i<n;i++) {
hr[i] = sc.nextInt();
min[i] = sc.nextInt();
ans[i] = ((23-hr[i])*60)+(60-min[i]);
}
for(int i=0;i<n;i++) {
System.out.println(ans[i]);
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 121a2e9de483f23bfd91b0982a7e0309 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | //author @markysans
import java.util.*;
import java.io.*;
public class a{
static Scanner sc=new Scanner(System.in);
static int cnt;
public static void main(String args[]){
int k=1;
k=sc.nextInt();
while(k--!=0){
solve();
}
}
static void solve(){
int h=sc.nextInt();
int m=sc.nextInt();
// System.out.println(h+" "+m);
System.out.println((23-h)*60+(60-m));
}
static int[] initarray(int n){
int A[]=new int[n];
for(int i=0;i<n;i++)
A[i]=sc.nextInt();
return A;
}
// static ArrayList<Integer> initlist(int n){
// ArrayList<Integer> A=new ArrayList<Integer>();
// for(int i=0;i<n;i++)
// A.add(sc.nextInt());
// return A;
// }
// static long[] initarray2(int n){
// long A[]=new long[n];
// for(int i=0;i<n;i++)
// A[i]=sc.nextLong();
// return A;
// }
// static ArrayList<Long> initlist2(long n){
// ArrayList<Long> A=new ArrayList<Long>();
// for(long i=0;i<n;i++)
// A.add(sc.nextLong());
// return A;
// }
}
//System.out.println();
// A.add(5);
// A.remove(5);
// A.get(5);
// A.set(1,5);
// A.indexOf(5);
// A.lastIndexOf(5);
// A.subList(2,4);
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | af2e0d8bb7b21a99a7fec5cb02a35dbb | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.lang.*;
import java.io.*;
import java.util.*;
public class NewYear {
public static void main(String args[]){
int n, hour, min, res;
String inpTime="";
String[] timeParts;
Scanner sc= new Scanner(System.in);
if(sc.hasNextLine()) {
n= Integer.parseInt(sc.nextLine());
while(n-->0 && sc.hasNextLine()) {
inpTime= sc.nextLine();
timeParts= inpTime.split("\\s+");
hour= Integer.parseInt(timeParts[0]);
min= Integer.parseInt(timeParts[1]);
res= (23-hour)*60+(60-min);
System.out.println(res);
}
}
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 9ccbddd2b5d7bbb2b90094d77c25923a | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class a{
static int[] count;
// static int[] count1;
static int[] arr;
static char[] c,c1;
static long[] darr;
static long x;
static long maxl;
static double dec;
// static long minl;
static int mx = (int)1e6;
static long mod = 998244353l;
// static int minl = -1;
// static int n;
static long n;
static long a;
static long b;
// static long c;
static long d;
static long y;
static int m;
static long k;
static int q;
static String[] str,str1;
static Set<Long> set;
static Set<Integer> list;
static Map<Long,Integer> map;
static StringBuilder sb;
public static void solve(){
System.out.println((23-n)*60 + (60-k));
}
public static void main(String[] args) {
// FastScanner sc = new FastScanner();
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t > 0){
// set = new HashSet<>();
// map = new HashMap<>();
// x = sc.nextLong();
// y = sc.nextLong();
// a = sc.nextLong();
// b = sc.nextLong();
// c = sc.nextLong();
// d = sc.nextLong();
// long x = sc.nextLong();
n = sc.nextLong();
k = sc.nextLong();
// dec = sc.nextDouble();
// n = sc.nextLong();
// arr = new long[n];
// for(int i = 0; i < n ; i++){
// arr[i] = sc.nextLong();
// }
// darr = new long[n];
// for(int i = 0; i < n ; i++){
// darr[i] = sc.nextLong();
// }
// System.out.println(solve()?"YES":"NO");
solve();
// System.out.println(solve());
// sb = new StringBuilder();
// sb.append(str);
t -= 1;
}
}
public static int log(long n){
if(n == 0)
return 0;
if(n == 1)
return 0;
if(n == 2)
return 1;
double num = Math.log(n);
double den = Math.log(2);
if(den == 0)
return 0;
return (int)(num/den);
}
// public static void swap(int i,int j){
// long temp = arr[j];
// arr[j] = arr[i];
// arr[i] = temp;
// }
static final Random random=new Random();
static void ruffleSort(long[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n);
long temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static class Node{
int first;
int second;
Node(int f,int s){
this.first = f;
this.second = s;
}
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | f795f1b32a74cd48a4165272b931197b | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution{
public static void main(String args[]){
int t;
Scanner sc=new Scanner(System.in);
t=sc.nextInt();
sc.nextLine();
while(t!=0)
{
t--;
int h,m;
h=sc.nextInt();
m=sc.nextInt();
sc.nextLine();
h=23-h;
m=60-m;
h=h*60;
int ans=h+m;
System.out.println(ans);
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 10c64ebfb0b88b7973b6fe97b973a4ee | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
int th=23, tm=60, th2, tm2;
int t = x.nextInt();
for (int i = 0; i < t; i++) {
th2=x.nextInt();
tm2=x.nextInt();
int a1=th-th2;
int a2=tm-tm2;
int ans=a1*60+a2;
System.out.println(ans);
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | e3f8f3c42dccaab9aa0f86e816b1f746 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.stream.Collectors;
public class p001283A {
static public void main(String[] args) throws IOException {
new Solver() {{{ nameIn = "p001283A.in"; singleTest = false;}}
@Override
public void process(BufferedReader br, PrintWriter pw) throws IOException {
int[] hm = readIntArray(br);
solve(hm[0], hm[1], pw);
}
private void solve(int h, int m, PrintWriter pw) {
int res = (24 - h) * 60 - m;
pw.println(res);
}
}.run();
}
// begin import package net.leksi.contest;
static abstract class Solver{protected String nameIn=null;protected String nameOut=null
;protected boolean singleTest=false;private void preProcess(final BufferedReader
br,final PrintWriter pw)throws IOException{if(!singleTest){int t=Integer.valueOf
(br.readLine().trim());while(t-->0){process(br,pw);}}else{process(br,pw);}}abstract
public void process(final BufferedReader br,final PrintWriter pw)throws IOException
;protected int[]readIntArray(final BufferedReader br)throws IOException{return Arrays
.stream(br.readLine().trim().split("\\s+")).mapToInt(v->Integer.valueOf(v)).toArray
();}protected long[]readLongArray(final BufferedReader br)throws IOException{return
Arrays.stream(br.readLine().trim().split("\\s+")).mapToLong(v->Long.valueOf(v)).toArray
();}protected String readString(final BufferedReader br)throws IOException{return
br.readLine().trim();}protected String intArrayToString(final int[]a){return Arrays
.stream(a).mapToObj(v->Integer.toString(v)).collect(Collectors.joining(" "));}protected
String longArrayToString(final long[]a){return Arrays.stream(a).mapToObj(v->Long
.toString(v)).collect(Collectors.joining(" "));}public void run()throws IOException
{try{try(FileReader fr=new FileReader(nameIn);BufferedReader br=new BufferedReader
(fr);PrintWriter pw=select_output();){preProcess(br,pw);}}catch(Exception ex){try
(InputStreamReader fr=new InputStreamReader(System.in);BufferedReader br=new BufferedReader
(fr);PrintWriter pw=select_output();){preProcess(br,pw);}}}private PrintWriter select_output
()throws FileNotFoundException{if(nameOut !=null){return new PrintWriter(nameOut
);}return new PrintWriter(System.out);}}
// end import package net.leksi.contest;
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 3cec78071dba363c49ef98db833800a3 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
public class _p001283A {
static public void main(final String[] args) throws java.io.IOException {
p001283A._main(args);
}
//begin p001283A.java
static private class p001283A extends Solver{public p001283A(){nameIn="p001283A.in"
;singleTest=false;}int h;int m;@Override protected void solve(){int res=(24-h)*60
-m;pw.println(res);}@Override public void readInput()throws IOException{h=sc.nextInt
();m=sc.nextInt();sc.nextLine();}static public void _main(String[]args)throws IOException
{new p001283A().run();}}
//end p001283A.java
//begin net/leksi/contest/Solver.java
static private abstract class Solver{protected String nameIn=null;protected String
nameOut=null;protected boolean singleTest=false;protected boolean preprocessDebug
=false;protected boolean doNotPreprocess=false;protected Scanner sc=null;protected
PrintWriter pw=null;private void process()throws IOException{if(!singleTest){int
t=lineToIntArray()[0];while(t-->0){readInput();solve();}}else{readInput();solve(
);}}abstract protected void readInput()throws IOException;abstract protected void
solve()throws IOException;protected int[]lineToIntArray()throws IOException{return
Arrays.stream(sc.nextLine().trim().split("\\s+")).mapToInt(Integer::valueOf).toArray
();}protected long[]lineToLongArray()throws IOException{return Arrays.stream(sc.nextLine
().trim().split("\\s+")).mapToLong(Long::valueOf).toArray();}protected String intArrayToString
(final int[]a){return Arrays.stream(a).mapToObj(Integer::toString).collect(Collectors
.joining(" "));}protected String longArrayToString(final long[]a){return Arrays.stream
(a).mapToObj(Long::toString).collect(Collectors.joining(" "));}protected List<Long>
longArrayToList(final long[]a){return Arrays.stream(a).mapToObj(Long::valueOf).collect
(Collectors.toList());}protected List<Integer>intArrayToList(final int[]a){return
Arrays.stream(a).mapToObj(Integer::valueOf).collect(Collectors.toList());}protected
List<Long>intArrayToLongList(final int[]a){return Arrays.stream(a).mapToObj(Long
::valueOf).collect(Collectors.toList());}protected void run()throws IOException{
try{try(FileInputStream fis=new FileInputStream(nameIn);PrintWriter pw0=select_output
();){sc=new Scanner(fis);pw=pw0;process();}}catch(IOException ex){try(PrintWriter
pw0=select_output();){sc=new Scanner(System.in);pw=pw0;process();}}}private PrintWriter
select_output()throws FileNotFoundException{if(nameOut !=null){return new PrintWriter
(nameOut);}return new PrintWriter(System.out);}}
//end net/leksi/contest/Solver.java
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | b25675979b8a2a6cb959e3b51664e8ad | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
public class Main {
public static void main(String args[]){
Scanner obj=new Scanner(System.in);
int t=0;
t = obj.nextInt();
int i,h,m,c=1440;
int f[] = new int[t];
for(i=0;i<t;i++)
{
h = obj.nextInt();
m = obj.nextInt();
f[i] = c-(h*60)-m;
}
for(i=0;i<t;i++)
{
System.out.println(f[i]);
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 1ee3ab5acf8c805902c9da62b10513ea | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | /*
ID: srihank1
LANG: JAVA
PROG: template
*/
import java.util.*;
import java.io.*;
public class MinutesBeforeTheNewYear {
public static class FastReader {
// Fast class in order to quickly read inputs
BufferedReader br;
StringTokenizer st;
public FastReader(String str) throws IOException {
br = new BufferedReader(new FileReader(str));
}
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());
}
char nextChar() {
return (next().charAt(0));
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static class Pair implements Comparable {
public int x;
public int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Object o) {
if (this.y==((Pair) o).y) {
return 0;
}
return this.y>((Pair) o).y?1:-1;
}
}
public static int big(int... x) {
int curr = x[0];
for (int n:x) {
curr = Math.max(curr, n);
}
return curr;
}
public static void print(String s) {
System.out.print(s);
}
public static void println(String s) {
System.out.println(s);
}
public static void main(String[] args) throws IOException{
String input1 = "template.in";
String input2 = "input.txt";
//FastReader fs = new FastReader(input2);
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("template.out")));
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
for (int i = 0; i < n; i++) {
String[] inputs = sc.nextLine().split(" ");
int a = Integer.parseInt(inputs[0]);
int b = Integer.parseInt(inputs[1]);
int time = 0;
time = 24-a;
time*=60;
time-=b;
System.out.println(time);
}
pw.close();
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 69ba7870b95c965d9ab9015f3077e455 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | /*
ID: srihank1
LANG: JAVA
PROG: template
*/
import java.util.*;
import java.io.*;
public class MinutesBeforeTheNewYear {
public static class FastReader {
// Fast class in order to quickly read inputs
BufferedReader br;
StringTokenizer st;
public FastReader(String str) throws IOException {
br = new BufferedReader(new FileReader(str));
}
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());
}
char nextChar() {
return (next().charAt(0));
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static class Pair implements Comparable {
public int x;
public int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Object o) {
if (this.y==((Pair) o).y) {
return 0;
}
return this.y>((Pair) o).y?1:-1;
}
}
public static int big(int... x) {
int curr = x[0];
for (int n:x) {
curr = Math.max(curr, n);
}
return curr;
}
public static void print(String s) {
System.out.print(s);
}
public static void println(String s) {
System.out.println(s);
}
public static void main(String[] args) throws IOException{
String input1 = "template.in";
String input2 = "input.txt";
//FastReader fs = new FastReader(input2);
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("template.out")));
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
for (int i = 0; i < n; i++) {
String[] inputs = sc.nextLine().split(" ");
int a = Integer.parseInt(inputs[0]);
int b = Integer.parseInt(inputs[1]);
int time = 0;
time = 24-a;
time*=60;
time-=b;
System.out.println(time);
}
pw.close();
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | fe7d347e689fdbce28e0f5a746756a00 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
public class Solution{
public static void main(String args[]) throws IOException{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(b.readLine());
while(t--!=0){
String s[]=b.readLine().split(" ");
int a=Integer.parseInt(s[0])*60;
a+=Integer.parseInt(s[1]);
System.out.println(1440-a);
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 78ecd0d7a94fd0f9d171fb1710c846fe | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class Main{
public static void main(String[] args) {
// Use the Scanner class
Scanner sc = new Scanner(System.in);
/*
int n = sc.nextInt(); // read input as integer
long k = sc.nextLong(); // read input as long
double d = sc.nextDouble(); // read input as double
String str = sc.next(); // read input as String
String s = sc.nextLine(); // read whole line as String
*/
int n = sc.nextInt();
for (int i = 0; i < n; ++i) {
int h = sc.nextInt();
int m = sc.nextInt();
int count = 0;
count += (23 - h) * 60;
count += (60 - m);
print(count);
}
}
private static <T> void print(T str) {
System.out.println(str);
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | a176a2eccaa45fefa6fc20d65c1adc8e | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int numOfCases = s.nextInt();
for (int i = 0; i < numOfCases; i++) {
int hour = s.nextInt();
int minute = s.nextInt();
System.out.println((23-hour)*60 + (60-minute));
}
// TODO code application logic here
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | ecfc74f288642535444b75cef3df6540 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 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 h=sc.nextInt();
int m=sc.nextInt();
int x = 23-h;
int y = 60-m;
System.out.println((x*60) + (y));
t--;
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | da64cfaf1eb4af7b62b8d2daba09ba67 | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes |
import java.util.*;
public class MinutesBeforeNewYear {
public static Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
int t = scn.nextInt();
while(t-->0) {
int h = scn.nextInt();
int m = scn.nextInt();
int ans = ((23-h)*60)+(60-m) ;
System.out.println(ans);
}
}
}
| Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 7a01904125b315022c9f1a76f3ba524e | train_000.jsonl | 1577552700 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class problemSet1283A {
public static void main(String[] args) {
Scanner myInput = new Scanner(System.in);
int trial = myInput.nextInt();
if(trial>0 && trial<1440){
for(int i=0;i<trial;i++){
int hour= myInput.nextInt();
int min =myInput.nextInt();
int hourToMins= hour*60;
int totalMins= hourToMins+ min;
int minsRemaining=1440-totalMins;
System.out.println(minsRemaining);
}
}
}
} | Java | ["5\n23 55\n23 0\n0 1\n4 20\n23 59"] | 1 second | ["5\n60\n1439\n1180\n1"] | null | Java 8 | standard input | [
"math"
] | f4982de28aca7080342eb1d0ff87734c | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) β the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. | 800 | For each test case, print the answer on it β the number of minutes before the New Year. | standard output | |
PASSED | 89b9b8d7b6c6d19e98f273201990e3ec | train_000.jsonl | 1286463600 | In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. | 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 whatIsForDinner {
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 sc = new FastReader();
int n=sc.nextInt();
int m=sc.nextInt();
int k=sc.nextInt();
HashMap<Integer,Integer> h=new HashMap<Integer,Integer>();
ArrayList<Integer> l=new ArrayList<Integer>();
while(n-->0)
{
int r=sc.nextInt();
int c=sc.nextInt();
if(!l.contains(r))
{
l.add(r);
}
if(!h.containsKey(r))
{
h.put(r,c);
}
else
{
h.put(r,Math.min(h.get(r),c));
}
}
long sum=0;
for(int i=0;i<l.size();i++)
{
sum=sum+h.get(l.get(i));
}
System.out.println(Math.min(k,sum));
}
} | Java | ["4 3 18\n2 3\n1 2\n3 6\n2 3", "2 2 13\n1 13\n2 12"] | 2 seconds | ["11", "13"] | null | Java 11 | standard input | [
"implementation",
"greedy"
] | 65eb0f3ab35c4d95c1cbd39fc7a4227b | The first line contains three integers n, m, k (1ββ€βmββ€βnββ€β1000,β0ββ€βkββ€β106) β total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1ββ€βrββ€βm) β index of the row, where belongs the corresponding tooth, and c (0ββ€βcββ€β106) β its residual viability. It's guaranteed that each tooth row has positive amount of teeth. | 1,200 | In the first line output the maximum amount of crucians that Valerie can consume for dinner. | standard output | |
PASSED | a6554050c6f2de2facff1a7f4dfe5b6d | train_000.jsonl | 1286463600 | In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. | 256 megabytes | //package pkg33a;
import static java.lang.Math.min;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt(),m=sc.nextInt(),k=sc.nextInt();
int array[]=new int[m+1];
Arrays.fill(array,1000000);
array[0]=0;
for(int i=0;i<n;i++)
{
int r=sc.nextInt();
int c=sc.nextInt();
array[r]=min(array[r],c);
}
int sum=0;
for(int i:array)
{
sum=sum + i;
}
System.out.println(min(sum,k));
}
}
| Java | ["4 3 18\n2 3\n1 2\n3 6\n2 3", "2 2 13\n1 13\n2 12"] | 2 seconds | ["11", "13"] | null | Java 11 | standard input | [
"implementation",
"greedy"
] | 65eb0f3ab35c4d95c1cbd39fc7a4227b | The first line contains three integers n, m, k (1ββ€βmββ€βnββ€β1000,β0ββ€βkββ€β106) β total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1ββ€βrββ€βm) β index of the row, where belongs the corresponding tooth, and c (0ββ€βcββ€β106) β its residual viability. It's guaranteed that each tooth row has positive amount of teeth. | 1,200 | In the first line output the maximum amount of crucians that Valerie can consume for dinner. | standard output | |
PASSED | 9be287b95554f96dc4c5210a1dc96dd1 | train_000.jsonl | 1286463600 | In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. | 256 megabytes | import java.util.*;
// Funny name
public class WhatIsForDinner {
static int[][] t = null;
static int[] i = null;
static void solve(){
Scanner sc = new Scanner(System.in);
int c=sc.nextInt(), r=sc.nextInt(), n=sc.nextInt(), NOC=c, R=r, m=1000001, ans=0;
t = new int[r][c];
i = new int[r];
while(--R>=0) Arrays.fill(t[R],m);
while(NOC-->0){
int index = sc.nextInt()-1; int no = sc.nextInt();
t[index][i[index]]=no; i[index]++;
}
R = r;
// Greeeeedy
while(--R>=0) Arrays.sort(t[R]);
for(int a=0; a<r; a++){
if((t[a][0]>0)&&(t[a][0]!=m)) {
ans+=(t[a][0]>n) ? n : t[a][0];
n-=(t[a][0]>n) ? n : t[a][0];
if(n<=0) break;
}
}
System.out.println(ans);
sc.close();
}
public static void main(String args[]) {
solve();
}
} | Java | ["4 3 18\n2 3\n1 2\n3 6\n2 3", "2 2 13\n1 13\n2 12"] | 2 seconds | ["11", "13"] | null | Java 11 | standard input | [
"implementation",
"greedy"
] | 65eb0f3ab35c4d95c1cbd39fc7a4227b | The first line contains three integers n, m, k (1ββ€βmββ€βnββ€β1000,β0ββ€βkββ€β106) β total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1ββ€βrββ€βm) β index of the row, where belongs the corresponding tooth, and c (0ββ€βcββ€β106) β its residual viability. It's guaranteed that each tooth row has positive amount of teeth. | 1,200 | In the first line output the maximum amount of crucians that Valerie can consume for dinner. | standard output | |
PASSED | f7c2d5eb9c30f829d1dcb7df06ad6e7e | train_000.jsonl | 1286463600 | In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. | 256 megabytes | import java.util.*;
public class ExtraordinaryDice {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int[][] arr = new int[n][2];
for(int i=0; i<arr.length; i++) {
arr[i][0] = sc.nextInt();
arr[i][1] = sc.nextInt();
}
int[] min = new int[m+1];
for(int i=0; i<min.length; i++) {
min[i] = Integer.MAX_VALUE;
}
for(int i=1; i<min.length; i++) {
for(int j=0; j<arr.length; j++) {
if( i == arr[j][0]) {
min[i] = Math.min(min[i], arr[j][1]);
}
}
}
int sum = 0;
for(int i=1; i<min.length; i++) {
sum += min[i];
}
System.out.println(Math.min(sum, k));
}
} | Java | ["4 3 18\n2 3\n1 2\n3 6\n2 3", "2 2 13\n1 13\n2 12"] | 2 seconds | ["11", "13"] | null | Java 11 | standard input | [
"implementation",
"greedy"
] | 65eb0f3ab35c4d95c1cbd39fc7a4227b | The first line contains three integers n, m, k (1ββ€βmββ€βnββ€β1000,β0ββ€βkββ€β106) β total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1ββ€βrββ€βm) β index of the row, where belongs the corresponding tooth, and c (0ββ€βcββ€β106) β its residual viability. It's guaranteed that each tooth row has positive amount of teeth. | 1,200 | In the first line output the maximum amount of crucians that Valerie can consume for dinner. | standard output | |
PASSED | 6557baaf9c018154f69cd10b82d6ef0a | train_000.jsonl | 1585233300 | A number is ternary if it contains only digits $$$0$$$, $$$1$$$ and $$$2$$$. For example, the following numbers are ternary: $$$1022$$$, $$$11$$$, $$$21$$$, $$$2002$$$.You are given a long ternary number $$$x$$$. The first (leftmost) digit of $$$x$$$ is guaranteed to be $$$2$$$, the other digits of $$$x$$$ can be $$$0$$$, $$$1$$$ or $$$2$$$.Let's define the ternary XOR operation $$$\odot$$$ of two ternary numbers $$$a$$$ and $$$b$$$ (both of length $$$n$$$) as a number $$$c = a \odot b$$$ of length $$$n$$$, where $$$c_i = (a_i + b_i) \% 3$$$ (where $$$\%$$$ is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by $$$3$$$. For example, $$$10222 \odot 11021 = 21210$$$.Your task is to find such ternary numbers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class Main implements Runnable
{
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int read()
{
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = stream.read(buf);
}
catch (IOException e)
{
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
public int nextInt()
{
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.')
{
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
// if modulo is required set value accordingly
public static long[][] matrixMultiply2dL(long t[][],long m[][])
{
long res[][]= new long[t.length][m[0].length];
for(int i=0;i<t.length;i++)
{
for(int j=0;j<m[0].length;j++)
{
res[i][j]=0;
for(int k=0;k<t[0].length;k++)
{
res[i][j]+=t[i][k]+m[k][j];
}
}
}
return res;
}
static long combination(long n,long r)
{
long ans=1;
for(long i=0;i<r;i++)
{
ans=(ans*(n-i))/(i+1);
}
return ans;
}
public static void main(String args[]) throws Exception
{
new Thread(null, new Main(),"Main",1<<27).start();
}
public void run()
{
InputReader sc = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
char fnum[] = new char[n];
char snum[] = new char[n];
int ind = n;
boolean f = false;
String x = sc.next();
char a[] = x.toCharArray();
for (int i=0;i<n;i++) {
char c = a[i];
if(c=='0'){
fnum[i] = '0';
snum[i] = '0';
}
else if(c=='1'){
ind = i;
f = true;
break;
}
else{
fnum[i] = '1';
snum[i] = '1';
}
}
if(f){
fnum[ind] = '1';
snum[ind] = '0';
for (int i=ind+1; i<n; i++) {
fnum[i] = '0';
snum[i] = a[i];
}
}
System.out.println(String.valueOf(fnum));
System.out.println(String.valueOf(snum));
}
System.out.flush();
w.close();
}
}
//https://codeforces.com/problemset/problem/1311/B
//https://codeforces.com/problemset/problem/1326/B | Java | ["4\n5\n22222\n5\n21211\n1\n2\n9\n220222021"] | 1 second | ["11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010"] | null | Java 8 | standard input | [
"implementation",
"greedy"
] | c4c8cb860ea9a5b56bb35532989a9192 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^4$$$) β the length of $$$x$$$. The second line of the test case contains ternary number $$$x$$$ consisting of $$$n$$$ digits $$$0, 1$$$ or $$$2$$$. It is guaranteed that the first digit of $$$x$$$ is $$$2$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^4$$$ ($$$\sum n \le 5 \cdot 10^4$$$). | 1,200 | For each test case, print the answer β two ternary integers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros such that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible. If there are several answers, you can print any. | standard output | |
PASSED | 8e7b79d496f1b89cae6db7a8308f0474 | train_000.jsonl | 1585233300 | A number is ternary if it contains only digits $$$0$$$, $$$1$$$ and $$$2$$$. For example, the following numbers are ternary: $$$1022$$$, $$$11$$$, $$$21$$$, $$$2002$$$.You are given a long ternary number $$$x$$$. The first (leftmost) digit of $$$x$$$ is guaranteed to be $$$2$$$, the other digits of $$$x$$$ can be $$$0$$$, $$$1$$$ or $$$2$$$.Let's define the ternary XOR operation $$$\odot$$$ of two ternary numbers $$$a$$$ and $$$b$$$ (both of length $$$n$$$) as a number $$$c = a \odot b$$$ of length $$$n$$$, where $$$c_i = (a_i + b_i) \% 3$$$ (where $$$\%$$$ is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by $$$3$$$. For example, $$$10222 \odot 11021 = 21210$$$.Your task is to find such ternary numbers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class xor {
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t-- > 0)
{
int n = s.nextInt();
String q = s.next();
StringBuilder a = new StringBuilder("");
StringBuilder b= new StringBuilder("");
for(int i=0;i<n;i++)
{
int temp = Integer.parseInt(q.charAt(i)+"");
if(temp==0) {
a.append(0);
b.append(0);
}
else if(temp==1) {
a.append(1);
b.append(0);
for(int j=(i+1);j<n;j++) {
a.append(0);
b.append(q.charAt(j));
}
break;
}
else {
a.append(1);
b.append(1);
}
}
System.out.println(a.toString());
System.out.println(b.toString());
}
}
} | Java | ["4\n5\n22222\n5\n21211\n1\n2\n9\n220222021"] | 1 second | ["11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010"] | null | Java 8 | standard input | [
"implementation",
"greedy"
] | c4c8cb860ea9a5b56bb35532989a9192 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^4$$$) β the length of $$$x$$$. The second line of the test case contains ternary number $$$x$$$ consisting of $$$n$$$ digits $$$0, 1$$$ or $$$2$$$. It is guaranteed that the first digit of $$$x$$$ is $$$2$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^4$$$ ($$$\sum n \le 5 \cdot 10^4$$$). | 1,200 | For each test case, print the answer β two ternary integers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros such that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible. If there are several answers, you can print any. | standard output | |
PASSED | 7010c92e528f2d9c68991ea0a17aa104 | train_000.jsonl | 1585233300 | A number is ternary if it contains only digits $$$0$$$, $$$1$$$ and $$$2$$$. For example, the following numbers are ternary: $$$1022$$$, $$$11$$$, $$$21$$$, $$$2002$$$.You are given a long ternary number $$$x$$$. The first (leftmost) digit of $$$x$$$ is guaranteed to be $$$2$$$, the other digits of $$$x$$$ can be $$$0$$$, $$$1$$$ or $$$2$$$.Let's define the ternary XOR operation $$$\odot$$$ of two ternary numbers $$$a$$$ and $$$b$$$ (both of length $$$n$$$) as a number $$$c = a \odot b$$$ of length $$$n$$$, where $$$c_i = (a_i + b_i) \% 3$$$ (where $$$\%$$$ is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by $$$3$$$. For example, $$$10222 \odot 11021 = 21210$$$.Your task is to find such ternary numbers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;
public class B {
public void run() throws Exception {
FastScanner sc = new FastScanner();
int test = sc.nextInt();
outer:
for (int q = 0; q<test; q++) {
int n = sc.nextInt();
String s = sc.next();
StringBuilder a = new StringBuilder();
StringBuilder b = new StringBuilder();
boolean big = false;
for (int i = 0; i<n; i++) {
if (s.charAt(i) == '0') {
a.append('0');
b.append('0');
}
else if (s.charAt(i) == '2') {
if (big) {
a.append('0');
b.append('2');
}
else {
a.append('1');
b.append('1');
}
}
else {
if (big) {
a.append('0');
b.append('1');
}
else {
a.append('1');
b.append('0');
big = true;
}
}
}
System.out.println(a);
System.out.println(b);
}
}
static class FastScanner {
public BufferedReader reader;
public StringTokenizer tokenizer;
public FastScanner() {
reader = new BufferedReader(new InputStreamReader(System.in), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
public static void main (String[] args) throws Exception {
new B().run();
}
public 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\n5\n22222\n5\n21211\n1\n2\n9\n220222021"] | 1 second | ["11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010"] | null | Java 8 | standard input | [
"implementation",
"greedy"
] | c4c8cb860ea9a5b56bb35532989a9192 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^4$$$) β the length of $$$x$$$. The second line of the test case contains ternary number $$$x$$$ consisting of $$$n$$$ digits $$$0, 1$$$ or $$$2$$$. It is guaranteed that the first digit of $$$x$$$ is $$$2$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^4$$$ ($$$\sum n \le 5 \cdot 10^4$$$). | 1,200 | For each test case, print the answer β two ternary integers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros such that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible. If there are several answers, you can print any. | standard output | |
PASSED | 57ce9f0a3e0abe97044724e316ea6f3d | train_000.jsonl | 1585233300 | A number is ternary if it contains only digits $$$0$$$, $$$1$$$ and $$$2$$$. For example, the following numbers are ternary: $$$1022$$$, $$$11$$$, $$$21$$$, $$$2002$$$.You are given a long ternary number $$$x$$$. The first (leftmost) digit of $$$x$$$ is guaranteed to be $$$2$$$, the other digits of $$$x$$$ can be $$$0$$$, $$$1$$$ or $$$2$$$.Let's define the ternary XOR operation $$$\odot$$$ of two ternary numbers $$$a$$$ and $$$b$$$ (both of length $$$n$$$) as a number $$$c = a \odot b$$$ of length $$$n$$$, where $$$c_i = (a_i + b_i) \% 3$$$ (where $$$\%$$$ is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by $$$3$$$. For example, $$$10222 \odot 11021 = 21210$$$.Your task is to find such ternary numbers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
JScanner in = new JScanner();
StringBuilder out = new StringBuilder();
int t = in.nextInt();
while(t-->0)
{
int n = in.nextInt();
String s = in.nextLine();
StringBuilder a = new StringBuilder("1");
StringBuilder b = new StringBuilder("1");
int i;
boolean amin = false;
for(i=1; i<n; i++)
{
if(s.charAt(i) == '1' && amin)
{
a.append("0");
b.append("1");
}
else if(s.charAt(i) == '1')
{
a.append("1");
b.append("0");
amin = true;
}
else if(s.charAt(i) == '2' && amin)
{
a.append("0");
b.append("2");
}
else if(s.charAt(i) == '2')
{
a.append("1");
b.append("1");
}
else if(s.charAt(i) == '2' && amin)
{
a.append("1");
b.append("1");
}
else
{
a.append("0");
b.append("0");
}
}
out.append(a).append("\n");
out.append(b).append("\n");
}
System.out.println(out);
}
//Scanner
static class JScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
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\n5\n22222\n5\n21211\n1\n2\n9\n220222021"] | 1 second | ["11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010"] | null | Java 8 | standard input | [
"implementation",
"greedy"
] | c4c8cb860ea9a5b56bb35532989a9192 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^4$$$) β the length of $$$x$$$. The second line of the test case contains ternary number $$$x$$$ consisting of $$$n$$$ digits $$$0, 1$$$ or $$$2$$$. It is guaranteed that the first digit of $$$x$$$ is $$$2$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^4$$$ ($$$\sum n \le 5 \cdot 10^4$$$). | 1,200 | For each test case, print the answer β two ternary integers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros such that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible. If there are several answers, you can print any. | standard output | |
PASSED | d7f45280d583188a1c7d75cb6d52b147 | train_000.jsonl | 1585233300 | A number is ternary if it contains only digits $$$0$$$, $$$1$$$ and $$$2$$$. For example, the following numbers are ternary: $$$1022$$$, $$$11$$$, $$$21$$$, $$$2002$$$.You are given a long ternary number $$$x$$$. The first (leftmost) digit of $$$x$$$ is guaranteed to be $$$2$$$, the other digits of $$$x$$$ can be $$$0$$$, $$$1$$$ or $$$2$$$.Let's define the ternary XOR operation $$$\odot$$$ of two ternary numbers $$$a$$$ and $$$b$$$ (both of length $$$n$$$) as a number $$$c = a \odot b$$$ of length $$$n$$$, where $$$c_i = (a_i + b_i) \% 3$$$ (where $$$\%$$$ is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by $$$3$$$. For example, $$$10222 \odot 11021 = 21210$$$.Your task is to find such ternary numbers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// Scanner sc= new Scanner(System.in);
int tc =Integer.parseInt(br.readLine());
for(int i=0;i<tc;i++){
int x = Integer.parseInt(br.readLine());
String n= br.readLine();
int y =x-1;
char[] arr = new char[x];
for(int u = 0 ;u<x;u++){
arr[u]= n.charAt(u);
}
boolean flag = false;
char[] a = new char[x];
char[]b = new char[x];
a[0]='1';
b[0]='1';
for(int l = 1 ;l <x;l++){
if(arr[l]=='2'&&flag==false){
a[l] ='1';
b[l]= '1';
continue;
}
else if(arr[l]=='2' && flag==true){
a[l]='0';
b[l]='2';
continue;
}
else if(arr[l]=='0'){
a[l]='0';
b[l]='0';
continue;
}
else if(arr[l]=='1' && flag==false){
a[l]='1';
b[l]='0';
flag=true;
continue;
}
else if(arr[l]=='1' && flag==true){
a[l]='0';
b[l]='1';
continue;
}
}
System.out.println(new String(a));
System.out.println(new String(b));
}
}
}
| Java | ["4\n5\n22222\n5\n21211\n1\n2\n9\n220222021"] | 1 second | ["11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010"] | null | Java 8 | standard input | [
"implementation",
"greedy"
] | c4c8cb860ea9a5b56bb35532989a9192 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^4$$$) β the length of $$$x$$$. The second line of the test case contains ternary number $$$x$$$ consisting of $$$n$$$ digits $$$0, 1$$$ or $$$2$$$. It is guaranteed that the first digit of $$$x$$$ is $$$2$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^4$$$ ($$$\sum n \le 5 \cdot 10^4$$$). | 1,200 | For each test case, print the answer β two ternary integers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros such that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible. If there are several answers, you can print any. | standard output | |
PASSED | f5a9bdd79005f24b3fc268fe2823e620 | train_000.jsonl | 1585233300 | A number is ternary if it contains only digits $$$0$$$, $$$1$$$ and $$$2$$$. For example, the following numbers are ternary: $$$1022$$$, $$$11$$$, $$$21$$$, $$$2002$$$.You are given a long ternary number $$$x$$$. The first (leftmost) digit of $$$x$$$ is guaranteed to be $$$2$$$, the other digits of $$$x$$$ can be $$$0$$$, $$$1$$$ or $$$2$$$.Let's define the ternary XOR operation $$$\odot$$$ of two ternary numbers $$$a$$$ and $$$b$$$ (both of length $$$n$$$) as a number $$$c = a \odot b$$$ of length $$$n$$$, where $$$c_i = (a_i + b_i) \% 3$$$ (where $$$\%$$$ is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by $$$3$$$. For example, $$$10222 \odot 11021 = 21210$$$.Your task is to find such ternary numbers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class Contest1 {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-->0){
int n = sc.nextInt();
char[] x= sc.nextLine().toCharArray();
char[]a = new char[n];
char[]b = new char[n];
int id=-1;
for (int i =0;i<n;i++){
if (x[i]=='1'){
id=i;
break;
}
}
if (id==-1){
for (int i =0;i<n;i++){
if (x[i]=='2'){
a[i]='1';
b[i]='1';
}
else {
a[i]='0';
b[i]='0';
}
}
}
else {
for (int i =0;i<id;i++){
if (x[i]=='2'){
a[i]='1';
b[i]='1';
}
else {
a[i]='0';
b[i]='0';
}
}
a[id]='1';
b[id]='0';
for (int i =id+1;i<n;i++){
a[i]='0';
b[i]=x[i];
}
}
pw.println(a);
pw.println(b);
}
pw.flush();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
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();
}
}
} | Java | ["4\n5\n22222\n5\n21211\n1\n2\n9\n220222021"] | 1 second | ["11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010"] | null | Java 8 | standard input | [
"implementation",
"greedy"
] | c4c8cb860ea9a5b56bb35532989a9192 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^4$$$) β the length of $$$x$$$. The second line of the test case contains ternary number $$$x$$$ consisting of $$$n$$$ digits $$$0, 1$$$ or $$$2$$$. It is guaranteed that the first digit of $$$x$$$ is $$$2$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^4$$$ ($$$\sum n \le 5 \cdot 10^4$$$). | 1,200 | For each test case, print the answer β two ternary integers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros such that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible. If there are several answers, you can print any. | standard output | |
PASSED | 7282846b440af73e3a9b95caef89ba61 | train_000.jsonl | 1585233300 | A number is ternary if it contains only digits $$$0$$$, $$$1$$$ and $$$2$$$. For example, the following numbers are ternary: $$$1022$$$, $$$11$$$, $$$21$$$, $$$2002$$$.You are given a long ternary number $$$x$$$. The first (leftmost) digit of $$$x$$$ is guaranteed to be $$$2$$$, the other digits of $$$x$$$ can be $$$0$$$, $$$1$$$ or $$$2$$$.Let's define the ternary XOR operation $$$\odot$$$ of two ternary numbers $$$a$$$ and $$$b$$$ (both of length $$$n$$$) as a number $$$c = a \odot b$$$ of length $$$n$$$, where $$$c_i = (a_i + b_i) \% 3$$$ (where $$$\%$$$ is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by $$$3$$$. For example, $$$10222 \odot 11021 = 21210$$$.Your task is to find such ternary numbers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
public class TernaryXOR {
static int mod = 1000000007;
static long L_INF = (1L << 60L);
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(int n) throws IOException {
byte[] buf = new byte[10*n]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
public static void main(String[] args) throws IOException {
Reader in = new Reader();
int i, t, n, j, k;
t = in.nextInt();
StringBuilder ans = new StringBuilder();
String s;
char c;
while (t-- > 0) {
n = in.nextInt();
in.readLine(n);
s = in.readLine(n).substring(0, n);
StringBuilder x = new StringBuilder();
StringBuilder y = new StringBuilder();
i = 0;
x.append('1');
y.append('1');
int b = -1;
for (i = 1; i < n; i++) {
c = s.charAt(i);
if (c == '0') {
x.append('0');
y.append('0');
} else if (c == '1') {
x.append('1');
y.append('0');
b = i + 1;
break;
} else {
x.append('1');
y.append('1');
}
}
if (b != -1) {
for (i = b; i < n; i++) {
x.append('0');
y.append(s.charAt(i));
}
}
ans.append(x.toString() + "\n" + y.toString() + "\n");
}
System.out.println(ans);
}
} | Java | ["4\n5\n22222\n5\n21211\n1\n2\n9\n220222021"] | 1 second | ["11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010"] | null | Java 8 | standard input | [
"implementation",
"greedy"
] | c4c8cb860ea9a5b56bb35532989a9192 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^4$$$) β the length of $$$x$$$. The second line of the test case contains ternary number $$$x$$$ consisting of $$$n$$$ digits $$$0, 1$$$ or $$$2$$$. It is guaranteed that the first digit of $$$x$$$ is $$$2$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^4$$$ ($$$\sum n \le 5 \cdot 10^4$$$). | 1,200 | For each test case, print the answer β two ternary integers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros such that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible. If there are several answers, you can print any. | standard output | |
PASSED | dc3b3da0b713fdbcfa1649686c8f0012 | train_000.jsonl | 1585233300 | A number is ternary if it contains only digits $$$0$$$, $$$1$$$ and $$$2$$$. For example, the following numbers are ternary: $$$1022$$$, $$$11$$$, $$$21$$$, $$$2002$$$.You are given a long ternary number $$$x$$$. The first (leftmost) digit of $$$x$$$ is guaranteed to be $$$2$$$, the other digits of $$$x$$$ can be $$$0$$$, $$$1$$$ or $$$2$$$.Let's define the ternary XOR operation $$$\odot$$$ of two ternary numbers $$$a$$$ and $$$b$$$ (both of length $$$n$$$) as a number $$$c = a \odot b$$$ of length $$$n$$$, where $$$c_i = (a_i + b_i) \% 3$$$ (where $$$\%$$$ is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by $$$3$$$. For example, $$$10222 \odot 11021 = 21210$$$.Your task is to find such ternary numbers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class C629C
{
static PrintWriter out=new PrintWriter((System.out));
public static void main(String args[])throws IOException
{
Reader sc=new Reader();
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
String s=sc.next();
solve(s,n);
}
out.close();
}
public static void solve(String s,int n)
{
StringBuilder a=new StringBuilder("");
StringBuilder b=new StringBuilder("");
boolean active=false;
for(int x=0;x<n;x++)
{
char ch=s.charAt(x);
if(ch=='1')
{
a.append('1');
b.append('0');
for(int y=x+1;y<n;y++)
{
a.append('0');
b.append(s.charAt(y));
}
break;
}
else if(ch=='2')
{
a.append('1');
b.append('1');
}
else
{
a.append('0');
b.append('0');
}
}
out.println(a+"\n"+b);
}
static class Reader
{
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)
{
return false;
}
st=new StringTokenizer(next);
return true;
}
}
} | Java | ["4\n5\n22222\n5\n21211\n1\n2\n9\n220222021"] | 1 second | ["11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010"] | null | Java 8 | standard input | [
"implementation",
"greedy"
] | c4c8cb860ea9a5b56bb35532989a9192 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^4$$$) β the length of $$$x$$$. The second line of the test case contains ternary number $$$x$$$ consisting of $$$n$$$ digits $$$0, 1$$$ or $$$2$$$. It is guaranteed that the first digit of $$$x$$$ is $$$2$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^4$$$ ($$$\sum n \le 5 \cdot 10^4$$$). | 1,200 | For each test case, print the answer β two ternary integers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros such that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible. If there are several answers, you can print any. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.