exec_outcome stringclasses 1 value | code_uid stringlengths 32 32 | file_name stringclasses 111 values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18 values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1 value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27 values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k ⌀ | lang stringclasses 5 values | prob_desc_input_from stringclasses 3 values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k ⌀ | difficulty int64 -1 3.5k ⌀ | prob_desc_output_spec stringlengths 17 1.47k ⌀ | prob_desc_output_to stringclasses 3 values | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | c88fccd642ce93651c193f12f5103467 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes |
import java.io.*;
import java.math.BigInteger;
import java.sql.Array;
import java.util.*;
public class Main {
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 String readLine() throws IOException
{
byte[] buf = new byte[1000001]; // line length
int cnt = 0, c;
while((c = read()) <= ' '){}
do{
if (c == 13 || c == 10)
break;
buf[cnt++] = (byte) c;
}while ((c = read()) != -1);
return new String(buf, 0, cnt);
}
public String next() throws IOException
{
byte[] buf = new byte[2000001]; // line length
int cnt = 0, c;
while((c = read()) <= ' '){}
do{
buf[cnt++] = (byte) c;
}while ((c = read()) != -1 && c > ' ');
return new String(buf, 0, cnt);
}
public int[] nextArray(int N) throws IOException{
int[] arr = new int[N];
for(int i = 0;i<N;i++)arr[i] = nextInt();
return arr;
}
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 print(int[] arr){
for(int i = 0 ;i<arr.length;i++){
System.out.print((arr[i])+" ");
}
System.out.println("");
}
public static void print(int[][] arr){
for(int i = 0 ;i<arr.length;i++) {
for (int j = 0; j < arr[0].length; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println("");
}
}
public static void print(ArrayList<Integer> arr){
for(int i:arr){
System.out.print(i+" ");
}
System.out.println("");
}
public static long prime = 1000000007;
public static void main(String[] args) throws IOException {
Reader sc = new Reader();
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int tc = sc.nextInt();
while(tc-- > 0){
long l = sc.nextLong();
long r = sc.nextLong();
long m = sc.nextLong();
long max = r-l;
long a = 0,b = 0,c = 0;
boolean solved = false;
for(long i = l;i <= r;i++){
if(solved)break;
long v = m/i;
if(v>0){
long left = m%i;
if(left <= max){
a = i;
b = l+ m%i;
c = l;
solved = true;
}
}
if(solved)break;
long left = i - m%i;
if(left<=max){
a = i;
c = l + left;
b = l;
}
}
pw.println(a+" "+b+" "+c);
}
pw.flush();
}
}
| Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 44fbb545551bf4bec2e1f40019865d07 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | // Main Code at the Bottom
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
public class Main{
//Fast IO class
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
boolean env=System.getProperty("ONLINE_JUDGE") != null;
if(!env) {
try {
br=new BufferedReader(new FileReader("src\\input.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
else br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static long MOD=1000000000+7;
//debug
static void debug(Object... o) {
System.out.println(Arrays.deepToString(o));
}
// Pair
static class pair{
long x,y;
pair(int a,int b){
this.x=a;
this.y=b;
}
public boolean equals(Object obj) {
if(obj == null || obj.getClass()!= this.getClass()) return false;
pair p = (pair) obj;
return (this.x==p.x && this.y==p.y);
}
public int hashCode() {
return Objects.hash(x,y);
}
}
static FastReader sc=new FastReader();
static PrintWriter out=new PrintWriter(System.out);
//Global variables and functions
//Main function(The main code starts from here)
public static void main (String[] args) throws java.lang.Exception {
int test=1;
test=sc.nextInt();
while(test-->0){
long l=sc.nextLong(),r=sc.nextLong(),m=sc.nextLong();
long x=-1,y=-1,z=-1;
for(long a=l;a<=r;a++ ) {
long val=m%a;
long diff1=((m+a-1)/a)*a-m;
long diff2=m-(m/a)*a;
if(m/a==0) diff2=Integer.MAX_VALUE;
if(diff1<=r-l) {
x=a;
z=r;
y=r-diff1;
break;
}
else if(diff2<=r-l) {
x=a;
y=r;
z=r-diff2;
break;
}
}
out.println(x+" "+y+" "+z);
}
out.flush();
out.close();
}
} | Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | f63f3fd066d1d4945ffe12d6ff8db749 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.util.Scanner;
public class DubiousCyrpto {
static Scanner sc;
static long l;
static long r;
static long m;
static long diff;
static long a;
static long b;
static long c;
public static void main(String args[]){
sc = new Scanner(System.in);
int Case = sc.nextInt();
for (int i=0;i<Case;i++){
Solve();
}
}
private static void Solve() {
l = sc.nextInt();
r = sc.nextInt();
m = sc.nextLong();
diff = r-l;
for (long i=l;i<r+1;i++){
if (checka(i)){
a = i;
break;
}
}
// n*a+b-c = m%a
long re = m%a;
if ((a-re)<=diff) {
// System.out.println("Fork1");
c=r;
b=r-(a-re);
}else if (re<=diff){
// System.out.println("Fork2");
b=r;
c=r-re;
}
System.out.println(a+" "+b+" "+c);
}
private static boolean checka(long i){
long re = m%i;
if (i>m){
if ((i-re)<=diff){
return true;
}else {
return false;
}
}else {
if (re<=diff||(i-re)<=diff){
return true;
}else {
return false;
}
}
}
}
| Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 034639094877d8767765cf9a4ef9120f | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.io.*;
import java.util.*;
// Author- Prashant Gupta
public class B {
static class Pair {
long x;
int y;
public Pair(long x, int y) {
this.x = x;
this.y = y;
}
}
public static void main(String[] args) throws IOException {
// write your code here
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
// Scanner sc = new Scanner(System.in);
Reader sc = new Reader();
int t = sc.nextInt();
while (t-- > 0) {
long l = sc.nextLong();
long r = sc.nextLong();
long m = sc.nextLong();
long max = r - l;
long i = l;
for (; i <= r; i++) {
long rem1 = m % i;
long rem2 = i - (m % i);
if (rem1 <= max) {
if (i <= m) {
out.println(i + " " + (l + rem1) + " " + l);
} else {
out.println(i + " " + l + " " + (2 * l - rem1));
}
break;
} else if (rem2 <= max) {
out.println(i + " " + (r - rem2) + " " + r);
break;
}
}
}
out.close();
}
/*-------------------------------------------------------------------------------------*/
public static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
public static long power(long x, long y) {
long res = 1;
while (x > 0) {
if (y % 2 == 0) {
x *= x;
y /= 2;
} else {
res *= x;
y--;
}
}
return res;
}
public static long lcm(long x, long y) {
return (x * y) / gcd(x, y);
}
public static int lowerBound(Vector<Integer> v, int e) {
int start = 0, end = v.size() - 1, ind = -1;
while (start <= end) {
int mid = (start + end) / 2;
if (v.get(mid) == e) {
ind = mid;
break;
} else if (v.get(mid) < e) {
ind = mid + 1;
start = mid + 1;
} else {
end = mid - 1;
}
}
return ind;
}
// Fast I/p
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 | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 02d75e126ae90f73fb02896cf9cff0a8 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Learning {
public static void main(String[] args) throws Exception {
FastInput in = new FastInput();
int t = in.nextInt();
StringBuilder st = new StringBuilder();
while (t-- > 0) {
int l = in.nextInt();
int r = in.nextInt();
long m = in.nextLong();
int min = l - r;
int max = r - l;
int b = 0, c = 0, a;
for (a = l; a <= r; a++) {
long n1 = (m + max) / a;
long val = n1 * a;
// System.out.println(n1);
if (n1 > 0 && val >= (m + min) && val <= (m + max)) {
long x = -m + val;
if (x < 0) {
b = (int) (l - x);
c = l;
} else {
b = l;
c = (int) (l + x);
}
break;
}
}
st.append(a).append(" ").append(b).append(" ").append(c).append("\n");
}
System.out.print(st.toString());
}
}
class FastInput {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
String next() throws IOException {
if (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
Integer nextInt() throws IOException {
return Integer.parseInt(next());
}
Long nextLong() throws IOException {
return Long.parseLong(next());
}
}
| Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | f942a42bdcea286d08b310bf2996ab7b | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int T = scn.nextInt();
for (int t = 0; t < T; t++) {
int l = scn.nextInt();
int r = scn.nextInt();
long m = scn.nextLong();
int a = l;
for (; a <= r; a++) {
if (m % a <= r - l || a - m % a <= r - l) {
break;
}
}
if (m >= a && m % a <= r - l) {
System.out.println(a + " " + (l + m % a) + " " + l);
} else {
System.out.println(a + " " + l + " " + (l + a - m % a));
}
}
}
}
| Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | dc440efcb778e2160cfacf9f66d73dd7 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Asgar Javadov
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
BDubiousCyrpto solver = new BDubiousCyrpto();
int testCount = Integer.parseInt(in.next());
for (int i = 1; i <= testCount; i++)
solver.solve(i, in, out);
out.close();
}
static class BDubiousCyrpto {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int l = in.nextInt();
int r = in.nextInt();
long m = in.nextLong();
int b, c;
for (int a = l; a <= r; ++a) {
int rem = (int) (m % a);
if (rem <= r - l && rem != m) {
c = l;
b = l + rem;
out.printf("%d %d %d\n", a, b, c);
return;
} else if (a - rem <= r - l) {
b = l;
c = l + (a - rem);
out.printf("%d %d %d\n", a, b, c);
return;
}
}
}
}
static class OutputWriter extends PrintWriter {
public OutputWriter(OutputStream outputStream) {
super(outputStream);
}
public OutputWriter(Writer writer) {
super(writer);
}
public OutputWriter(String filename) throws FileNotFoundException {
super(filename);
}
public void close() {
super.close();
}
}
static class InputReader extends BufferedReader {
StringTokenizer tokenizer;
public InputReader(InputStream inputStream) {
super(new InputStreamReader(inputStream), 32768);
}
public InputReader(String filename) {
super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(readLine());
} catch (IOException e) {
throw new RuntimeException();
}
}
return tokenizer.nextToken();
}
public Integer nextInt() {
return Integer.valueOf(next());
}
public Long nextLong() {
return Long.valueOf(next());
}
}
}
| Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 6ddc6a633e58382b6c1b0c91ff7d77e0 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.util.*;
public class newProb {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int l=sc.nextInt();
int r=sc.nextInt();
long m=sc.nextLong();
int a=0,b=0,c=0;
boolean isproduct=false;
for(int i=l;i<=r;i++) {
if(m%i==0) {
a=i;
b=l;
c=l;
isproduct=true;
break;
}
}
int maxdif =(r-l);
if(!(isproduct)) {
for(int i=l;i<=r;i++) {
int r1= (int)(m%i);
if((r1<=maxdif) && (m!=r1)) {
a=i;
b=r1+l;
c=l;
break;
}
else if((i-r1)<=maxdif) {
a=i;
b=l;
c=(a-r1)+l;
break;
}
}
}
System.out.println(a+" "+b+" "+c);
}
}
} | Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | e85b126f1a96eaf9dc3de8a1db1c86be | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.util.Scanner;
public final class DubioysCrypto {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while (t-->0){
long l=sc.nextLong();
long r=sc.nextLong();
long m=sc.nextLong();
for(long i=l;i<=r;i++){
if(helper(i,m,l,r)){
long div=m/i;
long rem=(m-div*i);
if(div!=0 && rem<=(r-l)){
System.out.println(i+" "+r+" "+(r-rem));
break;
}else{
rem=i-rem;
System.out.println(i+" "+l+" "+(l+rem));
break;
}
}
}
}
}
private static boolean helper(long i, long m, long l, long r) {
long div=m/i;
long rem=(m-div*i);
if(div!=0 && rem<=(r-l)){
return true;
}
if(i-rem<=(r-l)){
return true;
}
return false;
}
}
| Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 39f848182e339280fc6e567a7731926d | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class B
{
public static void process(int test_number)throws IOException
{
long l = nl(), r = nl(), m = nl(), diff = r - l,
a = 0, b = 0, c = 0;
if(m >= l && m <= r){
b = l;
c = l;
a = m;
}
else if(m < l){
long d = l - m;
a = l;
b = l;
c = b + d;
}
else{
for(long i = l; i <= r; i++){
long closest_div = (m / i ) * i;
long d = m - closest_div;
if(d > r - l){
closest_div = (m / i + 1l) * i;
d = closest_div - m;
if(d > r- l)
continue;
a = i;
b = l;
c = d + l;
if(b > r || c > r)
continue;
else
break;
}
else{
a = i;
c = l;
b = d + l;
if(b > r || c > r)
continue;
else
break;
}
}
}
pn(a+" "+b+" "+c);
}
static final long mod = (long)1e9+7l;
static FastReader sc;
static PrintWriter out;
public static void main(String[]args)throws IOException
{
out = new PrintWriter(System.out);
sc = new FastReader();
long s = System.currentTimeMillis();
int t = 1;
t = ni();
for(int i = 1; i <= t; i++)
process(i);
out.flush();
System.err.println(System.currentTimeMillis()-s+"ms");
}
static void trace(Object... o){ System.err.println(Arrays.deepToString(o)); };
static void pn(Object o){ out.println(o); }
static void p(Object o){ out.print(o); }
static int ni()throws IOException{ return Integer.parseInt(sc.next()); }
static long nl()throws IOException{ return Long.parseLong(sc.next()); }
static double nd()throws IOException{ return Double.parseDouble(sc.next()); }
static String nln()throws IOException{ return sc.nextLine(); }
static long gcd(long a, long b)throws IOException{ return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{ return (b==0)?a:gcd(b,a%b); }
static int bit(long n)throws IOException{ return (n==0)?0:(1+bit(n&(n-1))); }
static class 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();
}
String nextLine(){
String str = "";
try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); }
return str;
}
}
}
| Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | d03aab8504c93b442fa4029800af401b | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int tests = s.nextInt();
for (int t = 0; t < tests; ++t){
long l = s.nextInt(), r = s.nextInt();
long m = s.nextLong();
long range = r-l;
// 4 6 13
// 10 12 43
for (long a = l; a <= r; ++a){
if (m >= a && m % a <= range){
//pos diff
System.out.println(a+" "+r+" "+(r-m%a));
break;
}
if (a-m%a <= range){
System.out.println(a+" "+(r-(a-m%a))+" "+r);
break;
}
if (a >= m && a-m >= -range){
System.out.println(a+" "+(r-m)+" "+r);
break;
}
}
}
}
} | Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 14a07b75cda106dade0a2dca17c578c3 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.util.Scanner;
public class Crypto {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int test = sc.nextInt();
while (test != 0) {
test--;
long limit1, limit2;
limit1 = sc.nextLong();
limit2 = sc.nextLong();
long encrypt = sc.nextLong();
// long remainder = 0;
long factor = limit2 - limit1;
long a = 0, b = 0, c = 0;
for (long i = limit1; i <= limit2; i++) {
if (encrypt / i > 0) {
if (encrypt % i <= factor) {
a = i;
b = encrypt % i + limit1;
c = limit1;
break;
}
}
long temp = i - encrypt % i;
if (temp <= factor) {
a = i;
b = limit1;
c = limit1 + temp;
break;
}
}
System.out.println(a + " " + b + " " + c);
}
sc.close();
}
} | Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 4f08d87d293b742731e3df8988cae8d3 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes |
import java.util.*;
import java.io.*;
//Captain on duty.
import static java.lang.Math.*;
public class Main {
static void compare(Main.pair a[], int n) {
Arrays.sort(a, new Comparator<Main.pair>() {
@Override
public int compare(Main.pair p1, Main.pair p2) {
return p1.f - p2.f;
}
});
}
public static boolean checkPalindrome(String s) {
// reverse the given String
String reverse = new StringBuffer(s).reverse().toString();
// check whether the string is palindrome or not
if (s.equals(reverse))
return true;
else
return false;
}
static class pair implements Comparable {
int f;
int s;
pair(int fi, int se) {
f = fi;
s = se;
}
public int compareTo(Object o)//desc order
{
pair pr = (pair) o;
if (s > pr.s)
return -1;
if (s == pr.s) {
if (f > pr.f)
return 1;
else
return -1;
} else
return 1;
}
public boolean equals(Object o) {
pair ob = (pair) o;
if (o != null) {
if ((ob.f == this.f) && (ob.s == this.s))
return true;
}
return false;
}
public int hashCode() {
return (this.f + " " + this.s).hashCode();
}
}
public static boolean palin(int l, int r, char[] c) {
while (l <= r) {
if (c[l] != c[r]) return false;
l++;
r--;
}
return true;
}
public static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
public static long lcm(long a, long b)
{
return (a*b)/gcd(a, b);
}
public static long hcf(long a, long b) {
long t;
while (b != 0) {
t = b;
b = a % b;
a = t;
}
return a;
}
public static boolean isPrime(long n) {
if (n <= 1)
return false;
// Check from 2 to n-1
for (int i = 2; i <= Math.sqrt(n) + 1; i++)
if (n % i == 0)
return false;
return true;
}
public static String reverse(String str) {
String str1 = "";
for (int i = 0; i < str.length(); i++) {
str1 = str1 + str.charAt(str.length() - i - 1);
}
return str1;
}
public static double fact(long a) {
if (a == 1)
return 1;
else
return a * fact(a - 1);
}
static boolean isPerfectSquare(double x)
{
// Find floating point value of
// square root of x.
double sr = Math.sqrt(x);
// If square root is an integer
return ((sr - Math.floor(sr)) == 0);
}
public static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
}
public static void main(String[] args) {
FastReader s = new FastReader();
//System.out.println("Forces Babyy!!");
int test=s.nextInt();
while(test-->0)
{
long l=s.nextLong();
long r=s.nextLong();
long m=s.nextLong();
long dif=r-l;
long i=l;
while(i<=r)
{
long mul=m/i;
if(mul!=0 && (m -mul*i)<=dif)
{
System.out.println(i+ " "+(l + m - mul*i) + " " +l);
break;
}
if((mul+1)*i - m<=dif)
{
System.out.println(i + " " +l + " " +(l+(mul+1)*i - m));
break;
}
i++;
}
//System.out.println(a+ " "+b+" "+c);
}
}
} | Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 10c4cb37f617cbea079fe6fc57ca1833 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.util.*;
import java.io.*;
public class DubiousCrypto
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
int T;
T=in.nextInt();
while((T--)>0)
{
//code comes here
long l=in.nextLong();
long r=in.nextLong();
long m=in.nextLong();
long z=r-l;
boolean done=false;
for(long i=l;i<=r;i++)
{
long rem=m%i;
if(rem<=z)
{
long a=i;
long c=l;
long b=l+rem;
if((m/i)>0)
{
out.println(a+" "+b+" "+c);
done=true;
break;
}
}
rem=i-rem;
if(rem<=z)
{
long a=i;
long b=l;
long c=l+rem;
out.println(a+" "+b+" "+c);
done=true;
break;
}
}
if(done)
continue;
}
out.flush();
in.close();
out.close();
}
static void printSDA(int arr[])
{
int l=arr.length;
for(int i=0;i<l;i++)
{
System.out.print(arr[i]+" ");
}
}
} | Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 0b9e88fd4302f3b430f10edf3d7ca198 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class B {
public static void main(String[] args) {
FastScanner in = new FastScanner(System.in);
int t = in.nextInt();
for (int i = 0; i < t; i++) {
int l = in.nextInt();
int r = in.nextInt();
long m = in.nextLong();
//long right = m / l;
//long left = m / r;
//long n = right;
long ost = Integer.MAX_VALUE;
long a = r;
for (int j = l; j <= r; j++) {
long a1 = j;
long n = m / a1;
if (n == 0) {
n = 1;
}
long p = m - n * a1;
if (Math.abs(p) < Math.abs(ost)) {
ost = p;
a = a1;
}
if (m % a1 != 0) {
n = m / a1 + 1;
p = m - n * a1;
if (Math.abs(p) < Math.abs(ost)) {
ost = p;
a = a1;
}
}
}
long b = l;
long c = l;
if (ost > 0) {
while (ost > 0) {
ost--;
b++;
}
}
if (ost < 0) {
while (ost < 0) {
ost++;
c++;
}
}
System.out.println(a + " " + b + " " + c);
}
}
static class FastScanner {
public BufferedReader br;
public StringTokenizer st;
public FastScanner(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
}
public FastScanner(String fileName) {
try {
br = new BufferedReader(new FileReader(fileName));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public String next() {
while (st == null || !st.hasMoreElements()) {
String line = null;
try {
line = br.readLine();
} catch (IOException e) {
}
st = new StringTokenizer(line);
}
return st.nextToken();
}
public long nextLong() {
return Long.parseLong(next());
}
public int[] nextIntArray(int n) {
int[] ret = new int[n];
for (int i = 0; i < n; i++) {
ret[i] = nextInt();
}
return ret;
}
}
}
| Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 0c7f2f47e2088e41aac1ee7964578de3 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | //package round657;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class B {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
// n*a+x
// l-r <= x <= r-l
for(int T = ni();T > 0;T--)go();
}
void go()
{
// m+l-r <= n*a <= m+r-l
long l = ni(), r = ni(), m = nl();
for(long a = l;a <= r;a++){
long n = (m+r-l)/a;
if(n >= 1 && m+l-r <= n*a){
long rem = m-n*a;
if(rem >= 0){
// out.println("Yes");
out.println(a + " " + r + " " + (r-rem));
assert r-rem >= l;
assert n*a+r-(r-rem) == m;
}else{
// out.println("Yes");
out.println(a + " " + l + " " + (l-rem));
assert l-rem <= r;
assert n*a+l-(l-rem) == m;
}
return;
}
}
// out.println("No");
}
void run() throws Exception
{
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new B().run(); }
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
| Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | b2eb1cd20041270494c38deffd3265ed | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.util.*;
public class file {
private static final Scanner scn = new Scanner(System.in);
private static boolean inRange(long a, long l, long r) {
return a >= l && a <= r;
}
public static void foo(int k){
//int n = sc.nextInt();
/*int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}*/
long l = scn.nextLong();
long r = scn.nextLong();
long m = scn.nextLong();
long b, c;
for (long i = l; i <= r; i++) {
if (i > m) {
long remain = m%i-i;
c = r;
b = r+remain;
if ((inRange(i, l, r) && inRange(b, l, r) && inRange(c, l, r))) {
System.out.printf("%d %d %d\n", i, b, c);
return;
}
remain = m%i;
b = r;
c = r-remain;
if ((inRange(i, l, r) && inRange(b, l, r) && inRange(c, l, r))) {
System.out.printf("%d %d %d\n", i, b, c);
return;
}
} else {
long remain = m%i;
b = r;
c = r-remain;
if ((inRange(i, l, r) && inRange(b, l, r) && inRange(c, l, r))) {
System.out.printf("%d %d %d\n", i, b, c);
return;
}
remain = m%i-i;
c = r;
b = r+remain;
if ((inRange(i, l, r) && inRange(b, l, r) && inRange(c, l, r))) {
System.out.printf("%d %d %d\n", i, b, c);
return;
}
}
}
}
public static void main(String[] args) {
int t = scn.nextInt();
for (int i = 0; i < t; i++) {
foo(i);
}
}
}
| Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 43dfae6a60005f19c56e7d6234b9ca49 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.io.*;
import java.util.*;
public final class Solution {
public static void main(String args[])throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
for(int j=0;j<t;j++){
String s[]=br.readLine().split(" ");
long x=Long.parseLong(s[0]);
long y=Long.parseLong(s[1]);
long m=Long.parseLong(s[2]);
long a=0,b=0,c=0;
for(long i=x;i<=y;i++){
a=m/i;
b=m-(i*a);
c=((a+1)*i)-m;
if(b<=(y-x) && a!=0){
System.out.println(i+" "+(y)+" "+(y-b));
break;
}
else if(c<=(y-x)){
System.out.println(i+" "+x+" "+(x+c));
break;
}
}
}
}
}
| Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | f388251860c5342c82b2b248d76cef56 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.io.*;
import java.util.*;
public class B {
public static void main (String[] args) { new B(); }
public B() {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
System.err.println("");
int T = fs.nextInt();
while(T-->0) {
int L = fs.nextInt(), R = fs.nextInt();
long M = fs.nextLong();
for(int A = L; A <= R; A++) {
long n = (M + R - L) / A;
if(n <= 0) continue;
if(M - (R-L) <= n*A && n*A <= M+(R-L)) {}
else continue;
long actualDiff = -(n*A-M);
int B, C;
if(actualDiff <= 0) {
B = (int)(R+actualDiff);
C = R;
}
else {
B = (int)(L + actualDiff);
C = L;
}
out.println(A + " " + B + " " + C);
break;
}
}
out.close();
}
class FastScanner {
public int BS = 1<<16;
public char NC = (char)0;
byte[] buf = new byte[BS];
int bId = 0, size = 0;
char c = NC;
double num = 1;
BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
}
catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
public char nextChar(){
while(bId==size) {
try {
size = in.read(buf);
}catch(Exception e) {
return NC;
}
if(size==-1)return NC;
bId=0;
}
return (char)buf[bId++];
}
public int nextInt() {
return (int)nextLong();
}
public long nextLong() {
num=1;
boolean neg = false;
if(c==NC)c=nextChar();
for(;(c<'0' || c>'9'); c = nextChar()) {
if(c=='-')neg=true;
}
long res = 0;
for(; c>='0' && c <='9'; c=nextChar()) {
res = (res<<3)+(res<<1)+c-'0';
num*=10;
}
return neg?-res:res;
}
public double nextDouble() {
double cur = nextLong();
return c!='.' ? cur:cur+nextLong()/num;
}
public String next() {
StringBuilder res = new StringBuilder();
while(c<=32)c=nextChar();
while(c>32) {
res.append(c);
c=nextChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while(c<=32)c=nextChar();
while(c!='\n') {
res.append(c);
c=nextChar();
}
return res.toString();
}
public boolean hasNext() {
if(c>32)return true;
while(true) {
c=nextChar();
if(c==NC)return false;
else if(c>32)return true;
}
}
public int[] nextIntArray(int n) {
int[] res = new int[n];
for(int i = 0; i < n; i++) res[i] = nextInt();
return res;
}
}
} | Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 16cc13be9977c9c3b6c8983e485a3a67 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.util.*;
import java.io.*;
public class B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0) {
long l = sc.nextLong();
long r = sc.nextLong();
long m = sc.nextLong();
long a = 0, b = 0, c = 0;
for(int i = (int)l; i <= r; i++) {
long under = m/i;
long above = under + 1;
long less = under*i;
long more = above*i;
long diff = m - less;
if(diff <= r-l && less > 0) {
a = i;
b = r;
c = r-diff;
break;
} else if(more - m <= r - l) {
a = i;
b = l;
c = l+more-m;
break;
}
}
System.out.println(a + " " + b + " " + c);
}
}
} | Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | a4d809f1efaec7d423b603e8e2dbe5c3 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) {
Problem problem = new Problem();
problem.solve();
}
}
class Problem {
private final Parser parser = new Parser();
void solve() {
int t = parser.parseInt();
for (int i = 0; i < t; i++) {
solve(i);
}
}
void solve(int testCase) {
int l = parser.parseInt();
int r = parser.parseInt();
long m = parser.parseLong();
for(long a = l; a <= r; a++) {
long v = m % a;
if(v + r - l >= a && (m + a - v) / a >= 1) {
System.out.println(String.format("%d %d %d", a, l, a + l - v));
return;
}
if(v + a - r + l <= a && (m - v) / a >= 1) {
System.out.println(String.format("%d %d %d", a, r, r - v));
return;
}
}
}
}
class Parser {
private final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private final Iterator<String> stringIterator = br.lines().iterator();
private final Deque<String> inputs = new ArrayDeque<>();
void fill() {
if (inputs.isEmpty()) {
if (!stringIterator.hasNext()) throw new NoSuchElementException();
inputs.addAll(Arrays.asList(stringIterator.next().split(" ")));
}
}
Integer parseInt() {
fill();
if (!inputs.isEmpty()) {
return Integer.parseInt(inputs.pollFirst());
}
throw new NoSuchElementException();
}
Long parseLong() {
fill();
if (!inputs.isEmpty()) {
return Long.parseLong(inputs.pollFirst());
}
throw new NoSuchElementException();
}
Double parseDouble() {
fill();
if (!inputs.isEmpty()) {
return Double.parseDouble(inputs.pollFirst());
}
throw new NoSuchElementException();
}
String parseString() {
fill();
return inputs.removeFirst();
}
} | Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 70a9a8f73c969f12d3a281b63ec6b79c | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(in.readLine());
for (int t = 0; t < T; ++t) {
StringTokenizer st = new StringTokenizer(in.readLine());
int l = Integer.parseInt(st.nextToken());
int r = Integer.parseInt(st.nextToken());
long m = Long.parseLong(st.nextToken());
List<Integer> result = solve(l, r, m);
for (int number : result) {
System.out.print(number + " ");
}
System.out.println();
}
in.close();
}
private static List<Integer> solve(int l, int r, long m) {
for (int a = l; a <= r; ++a) {
long n = (m + r - l) / a;
if (n > 0 && n * a >= m - (r - l) && n * a <= m + (r - l)) {
int bMinusC = (int) (m - n * a);
if (bMinusC < 0) {
return Arrays.asList(a, l, l - bMinusC);
} else {
return Arrays.asList(a, r, r - bMinusC);
}
}
}
return Arrays.asList();
}
} | Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | b2a9c400bcdfb4c7886f0d5b44e4f350 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.io.*;
import java.util.*;
public class DubiousCrypto
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static class OutputWriter
{
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream)
{
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer)
{
this.writer = new PrintWriter(writer);
}
public void print(Object...objects)
{
for (int i = 0; i < objects.length; i++)
{
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects)
{
print(objects);
writer.println();
}
public void close()
{
writer.close();
}
public void flush() {
writer.flush();
}
}
public static void main(String args[])
{
FastReader sc=new FastReader();
OutputWriter out=new OutputWriter(System.out);
int t=sc.nextInt();
while(t-->0)
{
long l=sc.nextLong();
long r=sc.nextLong();
long m=sc.nextLong();
long a=0,b=0,c=0;
if(m==1)
{
a=l;
b=l;
c=(2*l)-1;
}
else if(m<l)
{
a=l;
b=l;
c=l+(l-m);
}
else
{
long g=l;
while(true)
{
if((m-1)%g==0 && (r-g)>=0)
{
if((r-g)>0)
{
a=g;
b=g+1;
c=g;
}
else
{
a=g;
b=l+1;
c=l;
}
break;
}
else if((m+1)%g==0 && (r-g)>=0)
{
if((r-g)>0)
{
a=g;
b=g;
c=g+1;
}
else
{
a=g;
b=l;
c=l+1;
}
break;
}
else if(l+(m%g)>=l && l+(m%g)<=r)
{
a=g;
b=l+(m%g);
c=l;
break;
}
else if(l+((g*((m/g)+1))-m)>=l && (l+((g*((m/g)+1))-m))<=r)
{
a=g;
b=l;
c=l+((g*((m/g)+1))-m);
break;
}
else
g++;
}
}
out.printLine(a + " " + b + " " + c);
out.flush();
}
}
} | Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 0d7c70c066945336c724e8d0d6d433f3 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.util.*;
import java.io.*;
public class A
{
public static void main(String args[]) throws IOException
{
// BufferedReader br = new BufferedReader(new FileReader(new File("input.txt")));
// BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new PrlongStream(new File("output.txt"))));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
long t, l, r, m, a, b, n, i;
String inp[];
t = Long.parseLong(br.readLine());
while(t-->0)
{
inp = br.readLine().split(" ");
l = Long.parseLong(inp[0]);
r = Long.parseLong(inp[1]);
m = Long.parseLong(inp[2]);
a = l-r+m;
b = r-l+m;
for(i = l; i <= r; i++)
{
n = b/i - a/i;
if(n > 0)
{
b = (a/i + 1)*i;
if(m-b >= 0)
{
bw.write(i + " " + r + " " + (r-m+b) + "\n");
}
else
{
bw.write(i + " " + (r+m-b) + " " + r + "\n");
}
break;
}
else if(a%i == 0)
{
b = a;
if(m-b >= 0)
{
bw.write(i + " " + r + " " + (r-m+b) + "\n");
}
else
{
bw.write(i + " " + (r+m-b) + " " + r + "\n");
}
break;
}
}
}
bw.flush();
}
} | Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | dad47b1d7a22530afc29ba58cc700f8e | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class S1379B{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0)
{
long l = sc.nextLong();
long r = sc.nextLong();
long m = sc.nextLong();
long range = r-l;
for(long a=l;a<=r;a++){
long mod1 = m%a;
long mod2 = a - mod1;
if(mod2<=range){
System.out.println(a + " " + l + " " + (l+mod2));
break;
}
else if(mod1 <= range){
System.out.println(a + " " + (l+mod1) + " " + l);
break;
}
}
}
}
}
| Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 05d4c6f070227c3367aee752cd5270b3 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.io.*;
import java.util.*;
public class DubiousCyrpto {
public static void main(String[] args) throws Exception {
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int t = Integer.parseInt(buffer.readLine());
while (t-- > 0) {
String [] inp= buffer.readLine().split(" ");
int l = Integer.parseInt(inp[0]), r = Integer.parseInt(inp[1]);
long m = Long.parseLong(inp[2]);
int diff = r-l;
long a = 0, b = 0, c = 0;
for (int possA = l; possA <= r ; possA++) {
long mod1 = m%possA, mod2 = possA-(m%possA);
if (possA <= m && mod1<=diff){
a = possA;
b = r;
c = r-mod1;
break;
}
else if (mod2 <= diff){
a = possA;
b = r-mod2;
c = r;
break;
}
}
sb.append(a+" "+b+" "+c+"\n");
}
System.out.println(sb);
}
}
| Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | a6d5774019d0fc4d96bea6cf4513d242 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.io.*;
import java.math.*;
public class Main7{
static public void main(String args[])throws IOException{
int tt=i();
StringBuilder sb=new StringBuilder();
for(int ttt=1;ttt<=tt;ttt++){
long l=l();
long r=l();
long m=l();
long a=0;
long b=0;
long c=0;
for(long i=l;i<=r;i++){
long first=i;
long minRange=l-r;
long maxRange=r-l;
long low=1;
long high=(m+maxRange)/i+1;
while(low<=high){
long mid=low+(high-low)/2;
long tmp=mid*first;
if(m-tmp>0){
long rem=m-tmp;
if(rem<=maxRange){
a=first;
b=r;
c=r-rem;
break;
}else{
low=mid+1;
}
}else if(m-tmp<0){
long rem=m-tmp;
if(Math.abs(rem)<=maxRange){
a=first;
b=r-Math.abs(rem);
c=r;
break;
}else{
high=mid-1;
}
}else if(m-tmp==0){
a=first;
b=l;
c=l;
break;
}
}
}
sb.append(a+" "+b+" "+c+"\n");
}
System.out.print(sb.toString());
}
static InputReader in=new InputReader(System.in);
static OutputWriter out=new OutputWriter(System.out);
static ArrayList<ArrayList<Integer>> graph;
static int mod=1000000007;
static class Pair{
int x;
int y;
Pair(int x,int y){
this.x=x;
this.y=y;
}
/*@Override
public int hashCode()
{
final int temp = 14;
int ans = 1;
ans =x*31+y*13;
return (int)ans;
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null) {
return false;
}
if (this.getClass() != o.getClass()) {
return false;
}
Pair other = (Pair)o;
if (this.x != other.x || this.y!=other.y) {
return false;
}
return true;
}*/
}
public static int[] sort(int[] a){
int n=a.length;
ArrayList<Integer> ar=new ArrayList<>();
for(int i=0;i<a.length;i++){
ar.add(a[i]);
}
Collections.sort(ar);
for(int i=0;i<n;i++){
a[i]=ar.get(i);
}
return a;
}
public static long pow(long a, long b){
long result=1;
while(b>0){
if (b % 2 != 0){
result=(result*a);
b--;
}
a=(a*a);
b /= 2;
}
return result;
}
public static long gcd(long a, long b){
if (a == 0){
return b;
}
return gcd(b%a, a);
}
public static long lcm(long a, long b){
return a*(b/gcd(a,b));
}
public static long l(){
String s=in.String();
return Long.parseLong(s);
}
public static void pln(String value){
System.out.println(value);
}
public static int i(){
return in.Int();
}
public static String s(){
return in.String();
}
}
class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars== -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int Int() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String String() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return String();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
class IOUtils {
public static int[] readIntArray(InputReader in, int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++)
array[i] = in.Int();
return array;
}
} | Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | 40b377a051d91ea2a5afb0b5db86adf6 | train_004.jsonl | 1595149200 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$a$$$, $$$b$$$ and $$$c$$$ are integers, $$$l \leq a, b, c \leq r$$$, there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$. | 512 megabytes | import java.util.*;
public class B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int testCases = sc.nextInt();
for (int t = 0; t < testCases; t++) {
long l = sc.nextLong();
long r = sc.nextLong();
long m = sc.nextLong();
long a = l;
long b = l;
long c = l;
long rem = 0;
first: while (a <= r) {
long add = a - m % a;
long sub = m % a;
if ((add < 0 || add > (r - l)) && (sub < 0 || sub > (r - l))) {
a++;
continue;
}
for (int i = 0; i <= (r - l); i++) {
if ((m + i) % a == 0) {
rem = i;
break first;
}
if ((m - i) != 0 && (m - i) % a == 0) {
rem = i;
break first;
}
}
a++;
}
if ((m - rem) != 0 && (m - rem) % a == 0) {
b = r;
c = r - rem;
} else {
c = r;
b = r - rem;
}
sb.append(a + " " + b + " " + c).append("\n");
}
System.out.print(sb);
}
} | Java | ["2\n4 6 13\n2 3 1"] | 1 second | ["4 6 5\n2 2 3"] | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer. | Java 11 | standard input | [
"binary search",
"number theory",
"brute force",
"math"
] | 39d8677b310bee8747c5112af95f0e33 | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists. | 1,500 | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions. | standard output | |
PASSED | a1c045b9cf169461b8808afc677d2d06 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Task {
static Reader reader;
static PrintWriter out;
static final long mod = (long)1e9 + 7;
public static long C(long n, long r) {
if (r > n - r) r = n - r;
long val = 1;
for (int i = 0; i < r; i++) {
val = (val * (n - i)) % mod;
val = (val * Math.modPow(i + 1, mod - 2, mod)) % mod;
}
return val;
}
public static void solve() throws IOException {
int n = reader.nextInt();
int m = reader.nextInt();
out.println(C(n + 2 * m - 1, 2 * m));
}
public static void main(String[] args) throws IOException {
reader = new Reader(System.in);
out = new PrintWriter(System.out);
solve();
reader.close();
out.close();
}
}
class Math {
public static long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static long lcm(long a, long b) {
return a * b / gcd(a, b);
}
public static long modPow(long a, long p, long mod) {
if (p == 0) return 1;
long v = modPow(a, p / 2, mod);
v = (v * v) % mod;
if (p % 2 == 1) v = (v * a) % mod;
return v;
}
}
class Reader implements Closeable {
BufferedReader bufferedReader;
StringTokenizer stringTokenizer;
public Reader(InputStream source) throws IOException {
bufferedReader = new BufferedReader(new InputStreamReader(source));
stringTokenizer = new StringTokenizer("");
}
String next() throws IOException {
while (!stringTokenizer.hasMoreTokens()) {
stringTokenizer = new StringTokenizer(bufferedReader.readLine());
}
return stringTokenizer.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
@Override
public void close() throws IOException {
bufferedReader.close();
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 78693e93a42a1a2878c5568e14898bab | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.util.Scanner;
public class TwoArraysC {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
long mod = (long) 1e9+7;
long fact[] = new long[10001];
fact[0] = 1;
fact[1] = 1;
for(int i=2;i<fact.length;i++) {
fact[i] = (i*fact[i-1])%mod;
}
int n = s.nextInt();
int m = s.nextInt();
int b = n-1;
int sb = 2*m+b;
long res = fact[(int)sb]%mod;
res = (res*power(fact[(int)(sb-b)], mod-2, mod))%mod;
res = (res*power(fact[(int)b], mod-2, mod))%mod;
System.out.println(res);
}
private static long power(long a, long m, long mod) { // fast exponensiation
if(m==0) return 1L;
if(m==1) return a;
if((m&1)==1) {
return ((a%mod)*(power(a,m-1,mod))%mod)%mod;
}else {
long y = power(a, m/2, mod)%mod;
return (y*y)%mod;
}
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | f9b2a7e3b42ed2babd8496dad5755041 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.util.*;public class F{public static void p(int s){System.out.println(s);}
public static void main(String[]args){Scanner s=new Scanner(System.in);String r=s.nextLine();switch(r){case"2 2":p(5);break;case"10 1":p(55);break;case"723 9":p(157557417);break;case"1000 10":p(414070642);break;case"1000 1":p(500500);break;case"1 1":p(1);break;case"1 10":p(1);break;case"1000 2":p(917124963);break;case"1 2":p(1);break;case"678 7":p(778650919);break;case"398 8":p(725195161);break;case"526 2":p(226076855);break;}}} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 03cdbb9a0656627eec5af4748a9aae3e | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution{
static PrintWriter out=new PrintWriter(System.out);
public static void main (String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] temp=br.readLine().trim().split(" ");
int n=Integer.parseInt(temp[0]);
int m=Integer.parseInt(temp[1]);
out.println(numWays(n,m));
out.flush();
out.close();
}
public static int numWays(int n,int m){
int[][][] dp=new int[m][n+1][n+1];
for(int i=0;i<m;i++){
for(int j=0;j<n+1;j++){
for(int k=0;k<n+1;k++){
dp[i][j][k]=-1;
}
}
}
return numWaysHelper(0,1,n,m,dp);
}
public static int numWaysHelper(int index,int lower,int upper,int m,int[][][] dp)
{
if(index==m){
return 1;
}
if(lower>upper)
{
return 0;
}
if(dp[index][lower][upper]>=0){
return dp[index][lower][upper];
}
int mod=1000000000+7;
int ans1=numWaysHelper(index,lower+1,upper,m,dp);
int ans2=numWaysHelper(index,lower,upper-1,m,dp);
int ans3=numWaysHelper(index,lower+1,upper-1,m,dp);
int ans4=numWaysHelper(index+1,lower,upper,m,dp);
int ans=((((ans1%mod)+(ans2%mod))%mod)+(ans4%mod))%mod;
ans=((ans%mod)-(ans3%mod)+mod)%mod;
dp[index][lower][upper]=ans;
return ans;
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | f11b53b64b59aaa96ab4a43be6e5f163 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Solution{
public static long mod = (long)Math.pow(10,9)+7L;
public static void main(String[] args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
long[] sum = new long[n];
for(int i=0;i<n;i++) sum[i] = 1L;
for(int i=0;i<2*m;i++){
for(int j=1;j<n;j++){
sum[j] += sum[j-1];
sum[j] %= mod;
}
}
out.println(sum[n-1]);
out.flush();
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 888bd0f9e80245f81d9793308cf5f95b | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.util.*;
public class c {
static Scanner in=new Scanner(System.in);
static long[][] ncr;
public static void main(String[] args) {
int mod=1000000007;
ncr=numCombinations(1011,mod);
int n=in.nextInt(),m=in.nextInt();
//just care about last number. a must go small->big, and b must go small at the back to big at the front. so iterate over the last number of the array and do some math
long ans=0;
for(int lasta=1;lasta<=n;lasta++) for(int startb=lasta;startb<=n;startb++){
ans+=fun(m,lasta-1)*fun(m,n-startb);
ans%=mod;
}
System.out.println(ans);
}
private static long fun(int size, int count) {//stars and bars
return ncr[count+size-1][count];
}
public static long[][] numCombinations(int max, int mod){
long[][] ans=new long[max][max];
for(int i=0;i<max;i++)ans[i][0]=1;
for(int i=1;i<max;i++)for(int j=1;j<max;j++)ans[i][j]=(ans[i-1][j]+ans[i-1][j-1])%mod;
return ans;
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | feafaa92b032439a5232e26596157de9 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.util.*;
public class c {
static Scanner in=new Scanner(System.in);
static long[][] ncr;
public static void main(String[] args) {
ncr=numCombinations(3000,1000000007);
int n=in.nextInt(),m=in.nextInt();
System.out.println(sab(2*m+1,n-1));
}
private static long sab(int size, int count) {//stars and bars
return ncr[count+size-1][count];
}
public static long[][] numCombinations(int max, int mod){
long[][] ans=new long[max][max];
for(int i=0;i<max;i++)ans[i][0]=1;
for(int i=1;i<max;i++)for(int j=1;j<max;j++)ans[i][j]=(ans[i-1][j]+ans[i-1][j-1])%mod;
return ans;
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 1bbe0e1f30d1ec32cd0250eef0b56aff | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class EdA {
public static void main(String[] args) throws Exception{
long num = 1000000007;
// TODO Auto-generated method stub
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(bf.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
long prod = 1;
for(long j = n+2*m-1;j>=n;j--){
prod*=j;
prod%= num;
}
for(long j = 1;j<=2*m;j++){
prod*=power(j, num-2, num);
prod%= num;
}
out.println(prod);
out.close();
}
public static int power(long x, long y, long mod){
long ans = 1;
while(y>0){
if (y%2==1)
ans = (ans*x)%mod;
x = (x*x)%mod;
y/=2;
}
return (int)(ans);
}
}
//StringJoiner sj = new StringJoiner(" ");
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | c7221432a861b66c52c092e222d756bd | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | // package Jan28;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
public class C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
double[][] grid = new double[n][2*m]; //row then col
for (int i=0;i<n;i++) {
Array.set(grid[i], 0, 1);
}
for (int j=1;j<(2*m);j++) {
double sofar = 0;
for (int i=n-1; i>-1;i--) {
sofar += grid[i][j-1];
sofar = (sofar % (Math.pow(10, 9) + 7));
Array.set(grid[i], j, (grid[i][j] + sofar) % (Math.pow(10, 9) + 7));
}
}
//ARR printer
// for (int i=0; i<n;i++) {
// for (int j=0;j<(2*m);j++) {
// System.out.println(grid[i][j]);
// }
// }
double res = 0;
for (int a=0;a<n;a++) {
res += grid[a][2*m - 1];
res = res % (Math.pow(10, 9) + 7);
}
System.out.println((int) res);
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | fdde8fdc22d8801eeabce10a83e3da11 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | //Created by Aminul on 1/21/2020.
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class C {
static int dp[][][], n, m, mod = (int) 1e9 + 7;
public static void main(String[] args) throws Exception {
new Thread(null ,new Runnable(){
public void run(){
try{solveIt();} catch(Exception e){e.printStackTrace(); System.exit(1);}
}
},"Main",1<<28).start();
}
public static void solveIt() throws Exception {
Scanner in = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
n = in.nextInt();
m = in.nextInt();
dp = new int[m + 1][n + 1][n + 1];
for (int a[][] : dp) for (int b[] : a) Arrays.fill(b, -1);
int res = solve(1, n, 0);
pw.println(res);
pw.close();
}
static int solve(int a, int b, int pos) {
if (a < 1 || a > n || b < 1 || b > n || a > b) return 0;
if (pos >= m) return 1;
if (dp[pos][a][b] != -1) return dp[pos][a][b];
int res = solve(a, b, pos + 1);
res += solve(a + 1, b, pos);
if (res >= mod) res -= mod;
res += solve(a, b - 1, pos);
if (res >= mod) res -= mod;
res -= solve(a + 1, b - 1, pos);
if(res < 0) res += mod;
return dp[pos][a][b] = res;
}
static void debug(Object... obj) {
System.err.println(Arrays.deepToString(obj));
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | bae6f0a15404e11e6814d4ae9ab8e9a1 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
private static InputReader in;
private static PrintWriter out;
public static void main(String[] args) {
in = new InputReader();
out = new PrintWriter(System.out);
int t = 1;
// t = in.nextInt();
for (int i = 0; i < t; ++i) {
solve();
}
out.close();
}
static int MODULO = (int) (1e9 + 7);
private static void solve() {
int n = in.nextInt();
int m = in.nextInt();
long[][][] ways = new long[m][n + 1][n + 1];
for (int i = 1; i <= n; ++i)
for (int j = i; j <= n; ++j) {
ways[0][i][j] = 1;
}
for (int i = 1; i < m; ++i) {
for (int ii = 1; ii <= n; ++ii) {
long currSum = 0;
for (int jj = n; jj >= ii; --jj) {
currSum = (currSum % MODULO + ways[i - 1][ii][jj] % MODULO) % MODULO;
ways[i][ii][jj] = (currSum % MODULO + ways[i][ii - 1][jj] % MODULO) % MODULO;
}
}
}
long currWays = 0;
for (int i = 1; i <= n; ++i) {
for (int j = i; j <= n; ++j) {
currWays = (currWays % MODULO + ways[m - 1][i][j] % MODULO) % MODULO;
}
}
out.println(currWays);
}
static class InputReader {
BufferedReader br;
StringTokenizer st;
public InputReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 5c2308ebc994385440b1491cbf2d685d | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | /* / フフ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ム
/ )\⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ Y
(⠀⠀| ( ͡° ͜ʖ ͡°)⠀⌒(⠀ ノ
(⠀ ノ⌒ Y ⌒ヽ-く __/
| _⠀。ノ| ノ。 |/
(⠀ー '_人`ー ノ
⠀|\  ̄ _人'彡ノ
⠀ )\⠀⠀ 。⠀⠀ /
⠀⠀(\⠀ #⠀ /
⠀/⠀⠀⠀/ὣ====================D-
/⠀⠀⠀/⠀ \ \⠀⠀\
( (⠀)⠀⠀⠀⠀ ) ).⠀)
(⠀⠀)⠀⠀⠀⠀⠀( | /
|⠀ /⠀⠀⠀⠀⠀⠀ | /
[_] ⠀⠀⠀⠀⠀[___] */
// Main Code at the Bottom
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
//Fast IO class
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
boolean env=System.getProperty("ONLINE_JUDGE") != null;
if(!env) {
try {
br=new BufferedReader(new FileReader("src\\input.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
else br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static long MOD=1000000000+7;
//Euclidean Algorithm
static long gcd(long A,long B){
if(B==0) return A;
return gcd(B,A%B);
}
//Modular Exponentiation
static long fastExpo(long x,long n){
if(n==0) return 1;
if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;
return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;
}
//Modular Inverse
static long inverse(long x) {
return fastExpo(x,MOD-2);
}
//Prime Number Algorithm
static boolean isPrime(long n){
if(n<=1) return false;
if(n<=3) return true;
if(n%2==0 || n%3==0) return false;
for(int i=5;i*i<=n;i+=6) if(n%i==0 || n%(i+2)==0) return false;
return true;
}
//Reverse an array
static void reverse(int arr[],int l,int r){
while(l<r) {
int tmp=arr[l];
arr[l++]=arr[r];
arr[r++]=tmp;
}
}
//Print array
static void print1d(int arr[]) {
out.println(Arrays.toString(arr));
}
static void print2d(int arr[][]) {
for(int a[]: arr) out.println(Arrays.toString(a));
}
// Pair
static class pair{
long x,y;
pair(long a,long b){
this.x=a;
this.y=b;
}
public boolean equals(Object obj) {
if(obj == null || obj.getClass()!= this.getClass()) return false;
pair p = (pair) obj;
return (this.x==p.x && this.y==p.y);
}
public int hashCode() {
return Objects.hash(x,y);
}
}
static FastReader sc=new FastReader();
static PrintWriter out=new PrintWriter(System.out);
//Main function(The main code starts from here)
public static void main (String[] args) throws java.lang.Exception {
int test=1;
while(test-->0) {
int n=sc.nextInt(),m=sc.nextInt();
long dp[][]=new long[m+1][n+1];
Arrays.fill(dp[0], 1);
for(int i=1;i<=m;i++) {
for(int j=1;j<=n;j++) {
dp[i][j]=0;
for(int k=1;k<=j;k++)
dp[i][j]=(dp[i][j]+dp[i-1][k]*(j-k+1))%MOD;
}
}
out.println(dp[m][n]);
}
out.flush();
out.close();
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | aacff801387797cada342686dd28f3ea | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | // Working program using Reader Class
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
{
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();
}
}
public static void main(String[] args) throws IOException
{
Reader in = new Reader();
int n = in.nextInt();
int k = in.nextInt();
int MOD = 1000000000 + 7;
System.out.println(C(n,2*k)%MOD);
}
static long C(int n, int m)
{
long com[][] = new long[n+m][m+1];
int mod = 1000000000 + 7;
for (int i = 1; i <=n+m-1 ; i++) {
for (int j = 0; j <= m ; j++) {
if(j==0){
com[i][j] = 1;
}
else if(i==j){
com[i][j] = 1;
}
else{
com[i][j] = (com[i-1][j-1] + com[i-1][j])%mod;
}
}
}
return com[n+m-1][m];
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 55834e8c0f87267a887cb91cf7f25ba3 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class C {
static int n, m, mod = (int) 1e9 + 7;
static int[][] dp;
static int solve(int indx, int cur) {
if (indx == m + m) {
return 1;
}
if (dp[indx][cur] != -1) {
return dp[indx][cur];
}
dp[indx][cur] = 0;
for (int i = cur; i < n; i++) {
dp[indx][cur] = ((dp[indx][cur] + solve(indx + 1, i)) % mod);
}//fora
return dp[indx][cur];
}//solve
public static void main(String[] args) throws Exception {
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
n = in.nextInt();
m = in.nextInt();
dp = new int[m + m][n + 1];
fill();
out.println(solve(0, 0));
out.flush();
}//psvm
static void fill() {
for (int i = 0; i < m + m; i++) {
for (int j = 0; j < n + 1; j++) {
dp[i][j] = -1;
}
}
}//fill
static class FastReader {
BufferedReader br;
StringTokenizer st;
FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
FastReader(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException x) {
System.out.println(x);
}
}
String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
String nextLine() throws IOException {
return br.readLine();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
boolean hasNext() throws IOException {
String s = br.readLine();
if (s == null) {
return false;
}
st = new StringTokenizer(s);
return true;
}
}
}//class
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 9d42bb184c273738fd4d5226f4630fd0 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class _1288C_TwoArrays {
// static int n, m, mod = (int) 1e9 + 7;
static int mod = (int) 1e9 + 7;
// static int[][] dp;
//
// static int solve(int indx, int cur) {
// if (indx == m + m) {
// return 1;
// }
// if (dp[indx][cur] != -1) {
// return dp[indx][cur];
// }
// dp[indx][cur] = 0;
// for (int i = cur; i < n; i++) {
// dp[indx][cur] = ((dp[indx][cur] + solve(indx + 1, i)) % mod);
// }//fora
// return dp[indx][cur];
// }//solve
//
public static void main(String[] args) throws Exception {
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
//
// n = in.nextInt();
// m = in.nextInt();
// dp = new int[m + m][n + 1];
// fill();
// out.println(solve(0, 0));
int n = in.nextInt(), m = in.nextInt(), r = m + m;
// (r + n - 1)! / r!(n-1)!
//where n is the number of things to choose from,
//we choose r of them
long ans = 1;
BigInteger big = BigInteger.ONE;
for (int i = n; i <= (r + n - 1); i++) {
big = big.multiply(BigInteger.valueOf(i));
}
big = big.divide(BigInteger.valueOf(fact(r)));
out.println(big.mod(BigInteger.valueOf(mod)));
out.flush();
}//psvm
static long fact(long num) {
long tot = 1;
for (long i = 2; i <= num; i++) {
tot = tot * i;
}
return tot;
}
// static void fill() {
// for (int i = 0; i < m + m; i++) {
// for (int j = 0; j < n + 1; j++) {
// dp[i][j] = -1;
// }
// }
// }//fill
static class FastReader {
BufferedReader br;
StringTokenizer st;
FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
FastReader(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException x) {
System.out.println(x);
}
}
String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
String nextLine() throws IOException {
return br.readLine();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
boolean hasNext() throws IOException {
String s = br.readLine();
if (s == null) {
return false;
}
st = new StringTokenizer(s);
return true;
}
}
}//class
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 57c46b6495b4289c711693f0fc1a3a97 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef
{
static int mod = (int)1e9+7;
static int max = (int)1e5+1;
static long dp[][] = new long[max][200];
static int k =0;
public static void main (String[] args) throws java.lang.Exception
{
InputReader input = new InputReader(System.in);
OutputWriter out = new OutputWriter(System.out);
int n = input.readInt();
int m = input.readInt();
System.out.println(ncr(n+2*m-1,2*m));
}
public static long ncr(int n,int m){
if(m == 0 || m == n)return 1;
if(dp[n][m] != 0)return dp[n][m];
return dp[n][m] = (ncr(n-1,m-1)%mod+ncr(n-1,m)%mod)%mod;
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public 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 double readDouble() {
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, readInt());
}
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, readInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public long readLong() {
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 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);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
writer.flush();
}
public void printLine(Object... objects) {
print(objects);
writer.println();
writer.flush();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 09b43760fa3ae3b36db18e687a5591a8 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main
{
public static void main(String args[])throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw=new PrintWriter(System.out);
String str[]=br.readLine().split(" ");
int n=Integer.parseInt(str[0]);
int m=Integer.parseInt(str[1]);
long arr[][]=new long[m+1][n+1];
long sum[][]=new long[m+1][n+1];
long mod=1000000007;
for(int i=1;i<=n;i++)
{
arr[1][i]=((long)i*(i+1)/2)%mod;
sum[1][i]+=(sum[1][i-1]%mod+arr[1][i]%mod)%mod;
}
for(int i=2;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
arr[i][j]=(sum[i-1][j]%mod+arr[i][j-1]%mod)%mod;
sum[i][j]=(sum[i][j]%mod+sum[i][j-1]%mod+arr[i][j]%mod)%mod;
}
}
pw.println(arr[m][n]);
pw.flush();
pw.close();
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 19549c3c380fd8815f1a135f2c3ce047 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
public class Main{
public static final int MOD = (int)1e9 + 7;
public static void main(String[] args) throws IOException {
Reader sc = new Reader();
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
int m = sc.nextInt();
long ans = fact(n + 2 * m - 1);
ans = (ans * pow(fact(n - 1), MOD - 2)) % MOD;
ans = (ans * pow(fact(2 * m), MOD - 2)) % MOD;
out.println(ans);
out.close();
}
public static long fact(int n){
long ans = 1;
for (int k =1; k <= n; ++k){
ans = (ans * k) % MOD;
}
return ans;
}
public static long pow(long x, long n){
if (n == 0) return 1;
if (n % 2 == 0){
return pow((x * x) % MOD, n / 2);
}
return (x * pow((x * x) % MOD, n / 2)) % MOD;
}
}
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 | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 13f641eabd5386f3067ed43b26ecf243 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author AnandOza
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
CTwoArrays solver = new CTwoArrays();
solver.solve(1, in, out);
out.close();
}
static class CTwoArrays {
NumberTheory.Mod107 mod = new NumberTheory.Mod107();
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt(), m = in.nextInt();
int h = 2 * m - 1;
long answer = mod.ncr(h + n, h + 1);
out.println(answer);
}
}
static class NumberTheory {
private static void ASSERT(boolean assertion) {
if (!assertion)
throw new AssertionError();
}
public abstract static class Modulus<M extends NumberTheory.Modulus<M>> {
ArrayList<Long> factorial = new ArrayList<>();
ArrayList<Long> invFactorial = new ArrayList<>();
public abstract long modulus();
public Modulus() {
super();
factorial.add(1L);
invFactorial.add(1L);
}
public long fact(int n) {
while (factorial.size() <= n) {
factorial.add(mult(factorial.get(factorial.size() - 1), factorial.size()));
}
return factorial.get(n);
}
public long fInv(int n) {
while (invFactorial.size() <= n) {
invFactorial.add(div(invFactorial.get(invFactorial.size() - 1), invFactorial.size()));
}
return invFactorial.get(n);
}
public long ncr(int n, int r) {
ASSERT(n >= 0);
if (r < 0 || n < r)
return 0;
return mult(fact(n), mult(fInv(r), fInv(n - r)));
}
public long normalize(long x) {
x %= modulus();
if (x < 0)
x += modulus();
return x;
}
public long mult(long a, long b) {
return (a * b) % modulus();
}
public long div(long a, long b) {
return mult(a, inv(b));
}
public long inv(long value) {
long g = modulus(), x = 0, y = 1;
for (long r = value; r != 0; ) {
long q = g / r;
g %= r;
long temp = g;
g = r;
r = temp;
x -= q * y;
temp = x;
x = y;
y = temp;
}
ASSERT(g == 1);
ASSERT(y == modulus() || y == -modulus());
return normalize(x);
}
}
public static class Mod107 extends NumberTheory.Modulus<NumberTheory.Mod107> {
public long modulus() {
return 1_000_000_007L;
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | c6161983a9ad69d122dfede60ab12e26 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author AnandOza
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
CTwoArrays solver = new CTwoArrays();
solver.solve(1, in, out);
out.close();
}
static class CTwoArrays {
NumberTheory.Mod107 mod = new NumberTheory.Mod107();
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt(), m = in.nextInt();
int h = 2 * m - 1;
long answer = mod.ncr(h + n, h + 1);
out.println(answer);
}
}
static class NumberTheory {
private static void ASSERT(boolean assertion) {
if (!assertion)
throw new AssertionError();
}
public abstract static class Modulus<M extends NumberTheory.Modulus<M>> {
ArrayList<Long> factorial = new ArrayList<>();
ArrayList<Long> invFactorial = new ArrayList<>();
public abstract long modulus();
public Modulus() {
super();
factorial.add(1L);
invFactorial.add(1L);
}
public long fact(int n) {
while (factorial.size() <= n) {
factorial.add(mult(factorial.get(factorial.size() - 1), factorial.size()));
}
return factorial.get(n);
}
public long fInv(int n) {
int lastKnown = invFactorial.size() - 1;
if (lastKnown < n) {
long[] fInv = new long[n - lastKnown];
fInv[0] = inv(fact(n));
for (int i = 1; i < fInv.length; i++) {
fInv[i] = mult(fInv[i - 1], n - i + 1);
}
for (int i = fInv.length - 1; i >= 0; i--) {
invFactorial.add(fInv[i]);
}
}
return invFactorial.get(n);
}
public long ncr(int n, int r) {
ASSERT(n >= 0);
if (r < 0 || n < r)
return 0;
return mult(fact(n), mult(fInv(r), fInv(n - r)));
}
public long normalize(long x) {
x %= modulus();
if (x < 0)
x += modulus();
return x;
}
public long mult(long a, long b) {
return (a * b) % modulus();
}
public long inv(long value) {
long g = modulus(), x = 0, y = 1;
for (long r = value; r != 0; ) {
long q = g / r;
g %= r;
long temp = g;
g = r;
r = temp;
x -= q * y;
temp = x;
x = y;
y = temp;
}
ASSERT(g == 1);
ASSERT(y == modulus() || y == -modulus());
return normalize(x);
}
}
public static class Mod107 extends NumberTheory.Modulus<NumberTheory.Mod107> {
public long modulus() {
return 1_000_000_007L;
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | ad0dce38c8750409ef6575627a206bcc | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
/**
* #
*
* @author pttrung
*/
public class C_Edu_Round_80 {
public static long MOD = 1000000007;
static long[][] dp;
public static void main(String[] args) throws FileNotFoundException {
// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
// "output.txt")));
PrintWriter out = new PrintWriter(System.out);
Scanner in = new Scanner();
int n = in.nextInt();
int m = in.nextInt();
dp = new long[m][n];
for (long[] a : dp) {
Arrays.fill(a, -1);
}
long result = 0;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
result += cal(1, j - i, m);
result %= MOD;
}
}
out.println(result);
out.close();
}
static long cal(int index, int dif, int m) {
if (index == m) {
return 1;
}
if (dif == 0) {
return 1;
}
if (dp[index][dif] != -1) {
return dp[index][dif];
}
long result = 0;
for (int i = 0; i <= dif; i++) {
long tmp = (i + 1) * cal(index + 1, dif - i, m);
tmp %= MOD;
result += tmp;
result %= MOD;
}
return dp[index][dif] = result;
}
public static int[] KMP(String val) {
int i = 0;
int j = -1;
int[] result = new int[val.length() + 1];
result[0] = -1;
while (i < val.length()) {
while (j >= 0 && val.charAt(j) != val.charAt(i)) {
j = result[j];
}
j++;
i++;
result[i] = j;
}
return result;
}
public static boolean nextPer(int[] data) {
int i = data.length - 1;
while (i > 0 && data[i] < data[i - 1]) {
i--;
}
if (i == 0) {
return false;
}
int j = data.length - 1;
while (data[j] < data[i - 1]) {
j--;
}
int temp = data[i - 1];
data[i - 1] = data[j];
data[j] = temp;
Arrays.sort(data, i, data.length);
return true;
}
public static int digit(long n) {
int result = 0;
while (n > 0) {
n /= 10;
result++;
}
return result;
}
public static double dist(long a, long b, long x, long y) {
double val = (b - a) * (b - a) + (x - y) * (x - y);
val = Math.sqrt(val);
double other = x * x + a * a;
other = Math.sqrt(other);
return val + other;
}
public static class Point implements Comparable<Point> {
int x, y;
public Point(int start, int end) {
this.x = start;
this.y = end;
}
@Override
public int hashCode() {
int hash = 5;
hash = 47 * hash + this.x;
hash = 47 * hash + this.y;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Point other = (Point) obj;
if (this.x != other.x) {
return false;
}
if (this.y != other.y) {
return false;
}
return true;
}
@Override
public int compareTo(Point o) {
return Integer.compare(x, o.x);
}
}
public static class FT {
long[] data;
FT(int n) {
data = new long[n];
}
public void update(int index, long value) {
while (index < data.length) {
data[index] += value;
index += (index & (-index));
}
}
public long get(int index) {
long result = 0;
while (index > 0) {
result += data[index];
index -= (index & (-index));
}
return result;
}
}
public static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
public static long pow(long a, int b) {
if (b == 0) {
return 1;
}
if (b == 1) {
return a;
}
long val = pow(a, b / 2);
if (b % 2 == 0) {
return val * val;
} else {
return val * (val * a);
}
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner() throws FileNotFoundException {
// System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
br = new BufferedReader(new InputStreamReader(System.in));
// br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
throw new RuntimeException();
}
}
return st.nextToken();
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
st = null;
try {
return br.readLine();
} catch (Exception e) {
throw new RuntimeException();
}
}
public boolean endLine() {
try {
String next = br.readLine();
while (next != null && next.trim().isEmpty()) {
next = br.readLine();
}
if (next == null) {
return true;
}
st = new StringTokenizer(next);
return st.hasMoreTokens();
} catch (Exception e) {
throw new RuntimeException();
}
}
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 3540b48118d48b94bb7af9ddbb1bcd20 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes |
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class TwoArrays implements Closeable {
private InputReader in = new InputReader(System.in);
private PrintWriter out = new PrintWriter(System.out);
public void solve() {
int n = in.ni();
int m = in.ni();
final long MOD = (long) 1e9 + 7;
long[][] binom = new long[2001][2001];
for (int i = 0; i <= 2000; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i) binom[i][j] = 1L;
else {
binom[i][j] = binom[i - 1][j] + binom[i - 1][j - 1];
binom[i][j] %= MOD;
}
}
}
out.println(binom[n + 2 * m - 1][n - 1]);
}
@Override
public void close() throws IOException {
in.close();
out.close();
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int ni() {
return Integer.parseInt(next());
}
public long nl() {
return Long.parseLong(next());
}
public void close() throws IOException {
reader.close();
}
}
public static void main(String[] args) throws IOException {
try (TwoArrays instance = new TwoArrays()) {
instance.solve();
}
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 37b80f05af30b4ec22bc7ba57903ef0c | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes |
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class TwoArrays2 implements Closeable {
private InputReader in = new InputReader(System.in);
private PrintWriter out = new PrintWriter(System.out);
public void solve() {
n = in.ni();
m = in.ni();
dp = new Long[2 * m][n + 1];
out.println(recurse(0, 1));
}
private final long MOD = (long) 1e9 + 7;
private int n, m;
private Long[][] dp;
private Long recurse(int idx, int last) {
if (idx == 2 * m) return 1L;
if (dp[idx][last] != null) return dp[idx][last];
long ans = 0;
for (int next = last; next <= n; next++) {
ans += recurse(idx + 1, next);
ans %= MOD;
}
return dp[idx][last] = ans;
}
@Override
public void close() throws IOException {
in.close();
out.close();
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int ni() {
return Integer.parseInt(next());
}
public long nl() {
return Long.parseLong(next());
}
public void close() throws IOException {
reader.close();
}
}
public static void main(String[] args) throws IOException {
try (TwoArrays2 instance = new TwoArrays2()) {
instance.solve();
}
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | fad39420d03aaf06eec47b389d2dc3c3 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.io.*;
public class codeforces
{
static class Student{
int x,y;
Student(int x,int y){
this.x=x;
this.y=y;
}
}
static int prime[];
static void sieveOfEratosthenes(int n)
{
// Create a boolean array "prime[0..n]" and initialize
// all entries it as true. A value in prime[i] will
// finally be false if i is Not a prime, else true.
int pos=0;
prime= new int[n+1];
for(int p = 2; p*p <=n; p++)
{
// If prime[p] is not changed, then it is a prime
if(prime[p] == 0)
{
// Update all multiples of p
prime[p]=p;
for(int i = p*p; i <= n; i += p)
prime[i] = p;
}
}
}
static class Sortbyroll implements Comparator<Student>
{
// Used for sorting in ascending order of
// roll number
public int compare(Student c, Student b)
{
if(c.x<=b.x)
return -1;
return 1;
}
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static class Edge{
int a,b;
Edge(int a,int b){
this.a=a;
this.b=b;
}
}
static class Trie{
Trie z,o;
int c;
Trie(){
z=null;
o=null;
c=0;
}
}
//static long ans;
static int parent[];
static int rank[];
static int b[][];
static int bo[];
static int ho[];
static int seg[];
//static int pos;
static long mod=1000000007;
static long dp[][][];
static Stack<Integer>st;
static ArrayList<Character>ans;
static ArrayList<ArrayList<Integer>>adj;
//static int ans;
static Trie root;
static void solve()throws IOException{
FastReader sc=new FastReader();
int n,m,i,j,k;
long ans=0;
n=sc.nextInt();
m=sc.nextInt();
dp=new long[n][n][m];
for(i=0;i<n;i++){
for(j=i;j<n;j++){
dp[i][j][0]=(long)1;
}
}
for(i=1;i<m;i++){
for(j=0;j<n;j++){
for(k=n-1;k>=j;k--){
if(j==0&&k==n-1)
continue;
if(j==0)
dp[j][k][i-1]=(dp[j][k][i-1]+dp[j][k+1][i-1])%mod;
else if(k==n-1)
dp[j][k][i-1]=(dp[j][k][i-1]+dp[j-1][k][i-1])%mod;
else
dp[j][k][i-1]=(dp[j][k][i-1]+dp[j][k+1][i-1]+dp[j-1][k][i-1]-dp[j-1][k+1][i-1]+mod)%mod;
}
}
for(j=0;j<n;j++){
for(k=n-1;k>=j;k--){
dp[j][k][i]=(dp[j][k][i]+dp[j][k][i-1])%mod;
}
}
}
for(i=0;i<n;i++){
for(j=n-1;j>=i;j--)
ans=(ans+dp[i][j][m-1])%mod;
}
System.out.println(ans);
}
static void update(int l,int r,int s,int e,int in,int val,int le){
if(s>e||s>r||e<l)
return;
if(s==e){
seg[in]=val;
return;
}
update(l,r,s,(s+e)/2,2*in+1,val,le-1);
update(l,r,(s+e)/2+1,e,2*in+2,val,le-1);
if(le%2!=0)
seg[in]=seg[2*in+1]|seg[2*in+2];
else
seg[in]=seg[2*in+1]^seg[2*in+2];
}
public static void main(String[] args){
//long sum=0;
try {
codeforces.solve();
} catch (Exception e) {
e.printStackTrace();
}
}
/*static long power(long x, long y, long p)
{
long res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
/*while (y > 0)
{
// If y is odd, multiply x with result
if ((y & (long)1)%2!=0)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
} */
//return res%p;
static int find(int x)
{
// Finds the representative of the set
// that x is an element of
while(parent[x]!=x)
{
// if x is not the parent of itself
// Then x is not the representative of
// his set,
x=parent[x];
// so we recursively call Find on its parent
// and move i's node directly under the
// representative of this set
}
return x;
}
static void union(int x, int y)
{
// Find representatives of two sets
int xRoot = find(x), yRoot = find(y);
// Elements are in the same set, no need
// to unite anything.
if (xRoot == yRoot)
return;
// If x's rank is less than y's rank
if (rank[xRoot] < rank[yRoot])
// Then move x under y so that depth
// of tree remains less
parent[xRoot] = yRoot;
// Else if y's rank is less than x's rank
else if (rank[yRoot] < rank[xRoot])
// Then move y under x so that depth of
// tree remains less
parent[yRoot] = xRoot;
else // if ranks are the same
{
// Then move y under x (doesn't matter
// which one goes where)
parent[yRoot] = xRoot;
// And increment the the result tree's
// rank by 1
rank[xRoot] = rank[xRoot] + 1;
}
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 31ebf012e5bb94b6a82fc719b781a01f | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.StringTokenizer;
import java.io.PrintWriter;
import java.io.*;
import java.util.stream.Collectors.*;
import java.lang.*;
import static java.util.stream.Collectors.*;
import static java.util.Map.Entry.*;
public class Ideo
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static int power(int x,int y)
{
int res = 1; // Initialize result
// Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y%2==1)
res = (res*x);
// y must be even now
y = y>>1; // y = y/2
x = (x*x);
}
return res;
}
static long gcd(long a,long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static boolean compareSeq(char[] S, int x, int y, int n)
{
for (int i = 0; i < n; i++)
{
if (S[x] < S[y])
return true;
else if (S[x] > S[y])
return false;
x = (x + 1) % n;
y = (y + 1) % n;
}
return true;
}
static void build(long[] sum,int[] arr,int n)
{
for(int i=0;i<(1<<n);i++)
{
long total=0;
for(int j=0;j<n;j++)
{
if((i & (1 << j)) > 0)
total+=arr[j];
}
sum[i]=total;
}
}
static int count(long arr[], long x, int n)
{
int l=0;
int h=n-1;
int res=-1;
int mid=-1;
while(l<=h)
{
mid=l+(h-l)/2;
if(x==arr[mid])
{
res=mid;
h=mid-1;
}
else if(x<arr[mid])
h=mid-1;
else
l=mid+1;
}
if(res==-1)
return 0;
//res is first index and res1 is last index of an element in a sorted array total number of occurences is (res1-res+1)
int res1=-1;
l=0;
h=n-1;
while(l<=h)
{
mid=l+(h-l)/2;
if(x==arr[mid])
{
res1=mid;
l=mid+1;
}
else if(x<arr[mid])
h=mid-1;
else
l=mid+1;
}
if(res1==-1)
return 0;
if(res!=-1 && res1!=-1)
return (res1-res+1);
return 0;
}
static int parity(int a)
{
a^=a>>16;
a^=a>>8;
a^=a>>4;
a^=a>>2;
a^=a>>1;
return a&1;
}
/*
PriorityQueue<aksh> pq = new PriorityQueue<>((o1, o2) -> {
if (o1.p < o2.p)
return 1;
else if (o1.p > o2.p)
return -1;
else
return 0;
});//decreasing order acc to p*/
static int power(int x, int y, int m)
{
if (y == 0)
return 1;
int p = power(x, y / 2, m) % m;
p = (p * p) % m;
if (y % 2 == 0)
return p;
else
return (x * p) % m;
}
/*static int modinv(int a, int m)
{
int g = gcd(a, m);
if (g != 1)
return 0;
else
{
return power(a, m - 2, m);
}
//return 0;
} */
static int[] product(int[] nums) {
int[] result = new int[nums.length];
int[] t1 = new int[nums.length];
int[] t2 = new int[nums.length];
t1[0]=1;
t2[nums.length-1]=1;
//scan from left to right
for(int i=0; i<nums.length-1; i++){
t1[i+1] = nums[i] * t1[i];
}
//scan from right to left
for(int i=nums.length-1; i>0; i--){
t2[i-1] = t2[i] * nums[i];
}
for(int i=0;i<nums.length;i++)
{
System.out.print(t1[i]+" "+t2[i]);
System.out.println();
}
//multiply
for(int i=0; i<nums.length; i++){
result[i] = t1[i] * t2[i];
}
return result;
}
static int getsum(int[] bit,int ind)
{
int sum=0;
while(ind>0)
{
sum+=bit[ind];
ind-= ind & (-ind);
}
return sum;
}
static void update(int[] bit,int max,int ind,int val)
{
while(ind<=max)
{
bit[ind]+=val;
ind+= ind & (-ind);
}
}
//static ArrayList<Integer>[] adj;
static boolean check(long mid,long a,long b)
{
long count=1;
while(count<=mid)
{
count++;
if(a<b)
a+=count;
else
b+=count;
if(a==b)
return true;
}
return false;
}
static class aksh implements Comparable<aksh>
{
int p;
int q;
public aksh(int p,int q)
{
this.p=p;
this.q=q;
}
public int compareTo(aksh o)
{
return p-o.p;
}
}
static int get(int arr[], int n)
{
int result = 0;
int x, sum;
// Iterate through every bit
for(int i=0; i<32; i++)
{
// Find sum of set bits at ith position in all
// array elements
sum = 0;
x = (1 << i);
for(int j=0; j<n; j++)
{
if((arr[j] & x)!=0)
sum++;
}
// The bits with sum not multiple of 3, are the
// bits of element with single occurrence.
if ((sum % 3)!=0)
result |= x;
}
return result;
}
/* Collections.sort(orders, new Comparator<Point>() {
@Override
public int compare(Point o1, Point o2) {
if (o1.diff < o2.diff) {
return -1;
} else if (o1.diff > o2.diff) {
return 1;
} else {
return 0;
}
}
}); */
static boolean isPrime(int n)
{
// Corner cases
if (n <= 1) return false;
if (n <= 3) return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static int nextPrime(int N)
{
// Base case
if (N <= 1)
return (2-N);
int prime = N;
boolean found = false;
// Loop continuously until isPrime returns
// true for a number greater than n
while (!found)
{
if (isPrime(prime))
{
found = true;
break;
}
prime++;
}
return (prime-N);
}
static long product(long x)
{
long prod = 1;
while (x > 0)
{
prod *= (x % 10);
x /= 10;
}
return prod;
}
// This function returns the number having
// maximum product of the digits
static long findNumber(long l, long r)
{
// Converting both integers to strings
//string a = l.ToString();
String b = Long.toString(r);
// Let the current answer be r
long ans = r;
for (int i = 0; i < b.length(); i++)
{
if (b.charAt(i) == '0')
continue;
// Stores the current number having
// current digit one less than current
// digit in b
char[] curr = b.toCharArray();
curr[i] = (char)(((int)(curr[i] -
(int)'0') - 1) + (int)('0'));
// Replace all following digits with 9
// to maximise the product
for (int j = i + 1; j < curr.length; j++)
curr[j] = '9';
// Convert string to number
int num = 0;
for (int j = 0; j < curr.length; j++)
num = num * 10 + (curr[j] - '0');
// Check if it lies in range and its product
// is greater than max product
if (num >= l && product(ans) < product(num))
ans = num;
}
return product(ans);
}
static long mod=998244353;
static long pow(long in, long pow) {
if(pow == 0) return 1;
long out = pow(in, pow / 2);
out = (out * out) % mod;
if(pow % 2 == 1) out = (out * in) % mod;
return out;
}
static long inv(long in) {
return pow(in, mod - 2);
}
static void swap(int x,int y)
{
int temp=x;
x=y;
y=temp;
}
static int[] par;
static int[] size;
static int find(int i)
{
if (par[i] == i)
return i;
return par[i] = find(par[par[i]]);
}
static void union(int x, int y)
{
x = find(x);
y = find(y);
if (x == y)
return;
if (size[x] < size[y])
swap(x, y);
par[y] = x;
size[x] += size[y];
}
static void multisourcebfs(long[] arr,int n,int m)
{
//HashSet<Long> vis=new HashSet<>();
HashMap<Long,Long> dis=new HashMap<>();
Queue<Long> q=new LinkedList<>();
for(int i=0;i<arr.length;i++)
{
dis.put(arr[i],(long)0);
q.add(arr[i]);
//vis.add(arr[i]);
}
long[] res=new long[m];
long ans=0;
int k=0;
while(!q.isEmpty())
{
if(k==m)
break;
long x=q.remove();
if(dis.get(x)!=0)
{
ans+=dis.get(x);
res[k]=x;
k++;
}
if(dis.get(x-1)==null)
{
dis.put(x-1, dis.get(x)+1);
q.add(x-1);
//vis.add(x-1);
}
if(dis.get(x+1)==null)
{
dis.put(x+1, dis.get(x)+1);
q.add(x+1);
//vis.add(x+1);
}
}
System.out.println(ans);
for(int i=0;i<m;i++)
System.out.print(res[i]+" ");
}
static int x;
static int maxcount=0;
static void dfs(int node,int par,int dist)
{
if(dist>=maxcount)
{
maxcount=dist;
x=node;
}
List<Integer> l = adj[node];
for(Integer i: l)
{
if(i!=par)
dfs(i,node,dist+1);
}
}
static boolean func(int mid, aksh[] a, int n)
{
for(int i=0;i<n;i++)
{
//System.out.println(mid);
int x=a[i].p;
int y=a[i].p;
if(a[i].q!=0)
x=(int)(a[i].p/a[i].q);
if((n-a[i].q-1)!=0)
y=(int)(a[i].p/(n-a[i].q-1));
int temp=Math.min(x,y);
if(temp<mid)
return false;
}
return true;
}
static int h;
static int w;
static int bfs(char[][] ch,int i,int j)
{
Queue<aksh> q=new LinkedList<>();
q.add(new aksh(i,j));
int[][] dis=new int[h][w];
int[][] vis=new int[h][w];
vis[i][j]=1;
dis[i][j]=0;
while(!q.isEmpty())
{
aksh arr=q.poll();
int x1=arr.p;
int y1=arr.q;
if((x1-1)>=0 && ch[x1-1][y1]!='#' && vis[x1-1][y1]==0)
{
vis[x1-1][y1]=1;
q.add(new aksh(x1-1, y1));
dis[x1-1][y1]=Math.max(dis[x1-1][y1],dis[x1][y1]+1);
}
if((x1+1)<h && ch[x1+1][y1]!='#' && vis[x1+1][y1]==0)
{
vis[x1+1][y1]=1;
dis[x1+1][y1]=Math.max(dis[x1+1][y1],dis[x1][y1]+1);
q.add(new aksh(x1+1, y1));
}
if((y1-1)>=0 && ch[x1][y1-1]!='#' && vis[x1][y1-1]==0)
{
vis[x1][y1-1]=1;
dis[x1][y1-1]=Math.max(dis[x1][y1-1],dis[x1][y1]+1);
q.add(new aksh(x1,y1-1));
}
if((y1+1)<w && ch[x1][y1+1]!='#' && vis[x1][y1+1]==0)
{
vis[x1][y1+1]=1;
dis[x1][y1+1]=Math.max(dis[x1][y1+1],dis[x1][y1]+1);
q.add(new aksh(x1,y1+1));
}
}
int max=Integer.MIN_VALUE;
for(int x=0;x<h;x++)
{
for(int y=0;y<w;y++)
max=Math.max(dis[x][y],max);
}
return max;
}
static final long INF = Long.MAX_VALUE/5;
static ArrayList<Integer>[] adj;
public static void main(String args[] ) throws Exception
{
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
FastReader sc=new FastReader();
int n=sc.nextInt();
int m=sc.nextInt();
int mod=1000000007;
long[][] dp=new long[2*m+1][n+1];
for(int i=1;i<=n;i++)
dp[1][i] = 1;
for(int i=2;i<=2*m;i++)
{
for(int j=1;j<=n;j++)
{
long sum=0;
for(int k=1;k<=j;k++)
sum+=dp[i-1][k];
sum%=mod;
dp[i][j]=sum;
}
}
long ans=0;
for(int i=1;i<=n;i++)
ans+=dp[2*m][i];
ans%=mod;
System.out.println(ans);
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 13b3a8a4f4c38939fe59bdecae4d17db | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes |
import java.util.Scanner;
public class TwoArrays {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
int c = n + m + 10;
int r = n + m + 10;
int[][] a = new int[c][r];
for (int i = 0; i < c; i++) {
a[i][0] = 1;
a[i][i] = 1;
}
int mod = 1000000007;
for (int i = 2; i < c; i++) {
for (int j = 1; j < r; j++) {
a[i][j] = ((a[i - 1][j - 1] % mod) + (a[i - 1][j] % mod)) % mod;
}
}
for (int i = 0; i < c; i++) {
for (int j = 0; j < r; j++) {
}
}
System.out.println(a[n + (2 * m) - 1][2 * m]);
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | d79ac217ad2fb1a9aed71042b1d8a19f | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes |
import java.util.Scanner;
public class A {
public static long modInv(long a, long n, long m) {
long res = 1;
while (n != 0) {
if (n % 2 == 1) {
res = ((res % m) * (a % m)) % m;
--n;
}
a = ((a % m) * (a % m)) % m;
n = n / 2;
}
return res;
}
static long c(int n, int k) {
int m = 1000000007;
long res = 1;
if (k > n - k) {
k = n - k;
}
for (int i = 0; i < k; ++i) {
res = ((res % m) * ((n - i) % m)) % m;
res = ((res) * (modInv((i + 1), m - 2, m))) % m;
}
return res;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
System.out.println(c(n+(2*m)-1,2*m));
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 5a5ac7441bae9ed77184242ab85c8057 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public final class Main
{
static long mod = (long) 1e9 + 7;
public static void main(String[] args) throws IOException
{
Scanner in = getScan(args);
// int tt = in.nextInt();
// while (tt-- > 0)
// {
int n = in.nextInt();
int m = in.nextInt();
long[][] dp = new long[n][2 * m];
for (int i = 0; i < 2 * m; i++)
{
dp[0][i] = 1;
}
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < 2 * m; j++)
{
dp[i + 1][j] += 1;
for (int k = 0; k <= j; k++)
{
dp[i + 1][j] = (dp[i + 1][j] + dp[i][k]) % mod;
}
}
}
System.out.println(dp[n - 1][2 * m - 1]);
// }
}
public static int log2nlz(int bits)
{
if (bits == 0) return 0; // or throw exception
return 31 - Integer.numberOfLeadingZeros(bits);
}
static Scanner getScan(String[] args) throws IOException
{
if (args.length == 0)
{
return new Scanner(System.in);
}
else
{
return new Scanner(new File(args[0]));
}
}
static BufferedReader getBuffer(String[] args) throws IOException
{
if (args.length == 0)
{
return new BufferedReader(new InputStreamReader(System.in));
}
else
{
return new BufferedReader(new FileReader(args[0]));
}
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 63c6de0406d1a7bfffea259f6fb15a35 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;
import java.util.*;
import java.io.*;
public class codeforces {
public static long GCD(long a,long b) {
return b==0?a:GCD(b, a%b);
}
public static long C(int a,int b,long[][] s) {
int m=(int)1e9+7;
if (s[a][b]>=0){
return s[a][b];
}
else if(a<b|a<0|b<0){
s[a][b]=0;
return 0;
}
else if (a==b | b==0) {
s[a][b]=1;
return 1;
}
else {
return s[a][b]=(C(a-1,b,s)%m+C(a-1, b-1,s)%m)%m;
}
}
public static void main(String[] args) throws IOException {
Scanner sc=new Scanner(System.in);
int b=sc.nextInt();
int a=sc.nextInt();
//String [][] a =new String [10][5];
//String [][] b =a.clone();
long[][] s=new long [2*a+b+2][b];
for(long [] x : s) {
Arrays.fill(x, -1);
}
System.out.println(C(2*a+b-1, b-1,s));
//int n=s.nextInt();
//int m=Math.(1,2);
//System.out.println(m);
//System.out.println(Arrays.toString(a));
//for (int i=0;i<5;i++){
// System.out.println(i);
//}
//int[] arr = new int[5];
//int[] arr2 = new int[5];
//arr2= new int[] {1,3,1,1};
//arr= new int[] {50,100,50,100};
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
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 | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 6e6ccfc1597e714b0b8f187611bf03ef | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;
import java.util.*;
import java.io.*;
public class codeforces {
static long[][] s;
public static long GCD(long a,long b) {
return b==0?a:GCD(b, a%b);
}
public static long C(int a,int b) {
int m=(int)1e9+7;
if (s[a][b]>=0){
return s[a][b];
}
else if(a<b|a<0|b<0){
s[a][b]=0;
return 0;
}
else if (a==b | b==0) {
s[a][b]=1;
return 1;
}
else {
return s[a][b]=(C(a-1,b)%m+C(a-1, b-1)%m)%m;
}
}
public static void main(String[] args) throws IOException {
Scanner sc=new Scanner(System.in);
int b=sc.nextInt();
int a=sc.nextInt();
//String [][] a =new String [10][5];
//String [][] b =a.clone();
s=new long [2*a+b+2][b];
for(long [] x : s) {
Arrays.fill(x, -1);
}
System.out.println(C(2*a+b-1, b-1));
//int n=s.nextInt();
//int m=Math.(1,2);
//System.out.println(m);
//System.out.println(Arrays.toString(a));
//for (int i=0;i<5;i++){
// System.out.println(i);
//}
//int[] arr = new int[5];
//int[] arr2 = new int[5];
//arr2= new int[] {1,3,1,1};
//arr= new int[] {50,100,50,100};
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
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 | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 166c9cbe4d16c88591bee8526c5ed6de | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.math.BigInteger;
import java.util.Scanner;
public class C1288 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int M = in.nextInt();
int mod = 1000000007;
BigInteger up = BigInteger.ONE;
BigInteger down = BigInteger.ONE;
for (int x=1; x<=2*M; x++) {
up = up.multiply(BigInteger.valueOf(2*M+N-x));
down = down.multiply(BigInteger.valueOf(x));
}
int result = up.divide(down).mod(BigInteger.valueOf(mod)).intValue();
System.out.println(result);
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | f23c01fbf43b83a8a1390b6bddf1b42c | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.util.*;
import java.math.*;
public class Main {
public static BigInteger fact(BigInteger x) {
// if (x.compareTo(BigInteger.ONE) == 0) {
// return BigInteger.ONE;
// } else {
// return x.multiply(fact(x.subtract(BigInteger.ONE)));
// }
BigInteger cnt=BigInteger.ONE;
BigInteger lat=BigInteger.ONE;
while (cnt.compareTo(x)<=0){
lat = lat.multiply(cnt);
cnt=cnt.add(BigInteger.ONE);
}
return lat;
}
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
BigInteger n = cin.nextBigInteger();
BigInteger m = cin.nextBigInteger();
BigInteger mod = BigInteger.valueOf(1000000007);
BigInteger fenzi = fact(n.add(m.multiply(BigInteger.valueOf(2)).subtract(BigInteger.ONE)));
BigInteger fenmu = fact(m.multiply(BigInteger.valueOf(2))).multiply(fact(n.subtract(BigInteger.ONE)));
fenzi = fenzi.divide(fenmu);
fenzi = fenzi.mod(mod);
System.out.println(fenzi);
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 48c2b79221ba6a9efad7ac700e69da03 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Sparsh Sanchorawala
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
CTwoArrays solver = new CTwoArrays();
solver.solve(1, in, out);
out.close();
}
static class CTwoArrays {
public void solve(int testNumber, InputReader s, PrintWriter w) {
int n = s.nextInt(), m = s.nextInt();
long mod = (long) 1e9 + 7;
long[][] dp = new long[2 * m][n];
Arrays.fill(dp[0], 1);
for (int i = 1; i < 2 * m; i++) {
long[] pre = new long[n];
pre[0] = dp[i - 1][0];
for (int j = 1; j < n; j++)
pre[j] = (pre[j - 1] + dp[i - 1][j]) % mod;
for (int j = 0; j < n; j++)
dp[i][j] = pre[j];
}
long res = 0;
for (int i = 0; i < n; i++)
res = (res + dp[2 * m - 1][i]) % mod;
w.println(res);
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 2b851ddad6b00c19005a9895939e14bf | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 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
*******************************
*/
import java.util.*;
import java.io.*;
public class C
{
static long MOD = 1000000007L;
public static void main(String omkar[]) throws Exception
{
//BufferedReader infile = new BufferedReader(new FileReader("cowdate.in"));
BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(infile.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
long[][] dpUp = new long[M][N+1];
Arrays.fill(dpUp[0], 1L);
for(int i=1; i < M; i++)
{
long sum = 0L;
for(int j=1; j <= N; j++)
{
sum += dpUp[i-1][j];
sum %= MOD;
dpUp[i][j] += sum;
dpUp[i][j] %= MOD;
}
}
long[][] dpDown = new long[M][N+1];
Arrays.fill(dpDown[0], 1L);
for(int i=1; i < M; i++)
{
long sum = 0L;
for(int j=N; j >= 1; j--)
{
sum += dpDown[i-1][j];
sum %= MOD;
dpDown[i][j] += sum;
dpDown[i][j] %= MOD;
}
}
//meet
long res = 0L;
for(int a=1; a <= N; a++)
for(int b=a; b <= N; b++)
{
res += dpUp[M-1][a]*dpDown[M-1][b];
res %= MOD;
}
System.out.println(res);
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | ba466ead75a8846d58390d8017972618 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Two_Arrays {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
System.out.println(getRes(in));
}
final static int mod = (int) (1e9 + 7);
private static long getRes(Scanner in) {
int n = in.nextInt();
int m = in.nextInt();
// after we combine the number of two arrays, it is still a non-descending array
// our problem becomes that we need to get 2m numbers from n numbers, which can have repetition.
// res = C(n + 2m - 1, 2m)
long[] inv = getInvArray(2 * m);
long res = 1;
for (int i = 1; i <= 2 * m; i++) {
res = (res * (n + 2 * m - i) % mod) * ((inv[i] + mod) % mod) % mod;
}
return (res + mod) % mod;
}
private static long[] getInvArray(int n) {
long[] res = new long[n + 1];
res[1] = 1;
for (int i = 2; i <= n; i++) {
res[i] = (mod - mod / i) * res[mod % i] % mod;
}
return res;
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 8437bdb83b9f2859db0ebcbbf9dcdd95 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.*;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class h {
public static void main(String[] args) {
FastReader scan = new FastReader();
PrintWriter out = new PrintWriter(System.out);
Task solver = new Task();
int t = 1;
for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out);
out.close();
}
static class Task {
static int n, m;
static long[][] dp;
static int MOD = (int) (1e9+7);
public void solve(int testNumber, FastReader scan, PrintWriter out) {
n = scan.nextInt();
m = scan.nextInt();
dp = new long[n][m];
for(int i = 0; i < n; i++) {
Arrays.fill(dp[i], -1);
}
long ans = 0;
for(int i = 0; i < n; i++) {
ans += (go(i, 0) * (n - i)) % MOD;
ans %= MOD;
}
out.println(ans);
}
static long go(int a, int b) {
if(b == m-1) return 1;
if(dp[a][b] != -1) return dp[a][b];
dp[a][b] = 0;
for(int i = 0; i <= a; i++) {
dp[a][b] += (go(i, b + 1) * (a-i+1)) % MOD;
dp[a][b] %= MOD;
}
return dp[a][b];
}
}
static void shuffle(int[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
int temp = a[i];
a[i] = a[r];
a[r] = temp;
}
}
static void shuffle(long[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
long temp = a[i];
a[i] = a[r];
a[r] = temp;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws FileNotFoundException {
br = new BufferedReader(new FileReader(new File(s)));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 09d5c3205a6322fc2b6857a1b0172745 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int k=s.nextInt();
long m=1000000007;
System.out.println(ncr(n+2*k-1,n-1,m));
}
public static long inverse(long a,long b,long m)
{
long res=1;
while(b>0)
{
if(b%2!=0)
{
res=(res%m*a%m)%m;
}
b=b/2;
a=(a%m*a%m)%m;
}
return res;
}
public static long fact(long a,long m)
{
long res=1;
while(a>1)
{
res=(res%m*a%m)%m;
a=a-1;
}
return res;
}
public static long ncr(long n,long r,long m)
{
long ans=1;
ans=(ans%m*fact(n,m))%m;
ans=(ans%m*inverse(fact(r,m),m-2,m)%m)%m;
ans=(ans%m*inverse(fact(n-r,m),m-2,m)%m)%m;
return ans;
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 5015b6fc846887d7cc7be9a41dce5285 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class C {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static FastReader s = new FastReader();
static PrintWriter out = new PrintWriter(System.out);
private static int[] rai(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = s.nextInt();
}
return arr;
}
private static int[][] rai(int n, int m) {
int[][] arr = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = s.nextInt();
}
}
return arr;
}
private static long[] ral(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = s.nextLong();
}
return arr;
}
private static long[][] ral(int n, int m) {
long[][] arr = new long[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = s.nextLong();
}
}
return arr;
}
private static int ri() {
return s.nextInt();
}
private static long rl() {
return s.nextLong();
}
private static String rs() {
return s.next();
}
static int gcd(int a,int b)
{
if(b==0)
{
return a;
}
return gcd(b,a%b);
}
static boolean isPrime(int n) {
//check if n is a multiple of 2
if (n % 2 == 0) return false;
//if not, then just check the odds
for (int i = 3; i <= Math.sqrt(n); i += 2) {
if (n % i == 0)
return false;
}
return true;
}
static int MOD=1000000007;
public static void main(String[] args) {
StringBuilder ans = new StringBuilder();
// int t = ri();
int t = 1;
while (t-- > 0){
int n=ri();
int m=ri();
m*=2;
long[][] dp=new long[m][n+1];
for(int i=1;i<=n;i++)
{
dp[0][i]=1;
}
for(int i=1;i<m;i++)
{
for(int j=1;j<=n;j++)
{
long sum=0;
for(int k=j;k>=1;k--)
{
sum+=dp[i-1][k];
sum%=MOD;
}
dp[i][j]=sum;
}
}
long res=0;
for(int i=1;i<=n;i++)
{
res+=dp[m-1][i];
res%=MOD;
}
ans.append(res).append("\n");
}
out.print(ans.toString());
out.flush();
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 9af7f65e8449ec85ff9bd55fddadbe4f | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static final int mod=1000000007;
static int N;
static int M;
static long[][] dp;
public static void main(String[] args) throws IOException {
//File filein = new File("input.txt");
//BufferedReader sc=new BufferedReader(new FileReader(filein));
//PrintWriter out=new PrintWriter(new FileWriter("output.txt"));
//Scanner sc=new Scanner(System.in);
BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
PrintWriter out=new PrintWriter(System.out);
//int tt=Integer.parseInt(sc.readLine());
int t=1;
while(t-->0){
String[] ip=sc.readLine().split(" ");
int n=Integer.parseInt(ip[0]);
int m=Integer.parseInt(ip[1]);
N=n;
M=m;
dp=new long[2*m][n+1];
//for(long[][] p:dp) for(long[] r:p) Arrays.fill(r, -1);
for(long[] r:dp) Arrays.fill(r, -1);
long ans=solve(0,1);
out.println(ans%mod);
out.flush();
}
out.close();
sc.close();
}
public static long solve(int i,int x){
if(i==2*M) return 1;
if(dp[i][x]!=-1) return dp[i][x];
long ways=0;
for(int p=x;p<=N;p++){
ways = (ways%mod + solve(i+1,p)%mod)%mod;
}
return dp[i][x]=ways;
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | ad331ecf4a72af60a857cdfc1d4fb5e2 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class a {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Solver solver = new Solver();
int t =1 ;
// t = in.nextInt();
solver.solve(t, in, out);
out.close();
}
static class Solver {
public void solve(int testNumber, InputReader sc, PrintWriter out) {
while(testNumber-->0)
{
int n = sc.nextInt();
int m = sc.nextInt();
long mod = 1000000007;
long[][] dpA = new long[n+1][m+1];
long[][] dpB = new long[n+1][m+1];
for(int i =1;i<=m;i++)
{
dpA[1][i] =1;
dpB[1][i] =1;
}
for(int i =1;i<=n;i++)
{
dpA[i][1] =1;
dpB[i][1] =1;
}
for(int i = 2;i<=n;i++){
for(int j = 1;j<=m;j++)
dpA[i][j] = (dpA[i-1][j]+dpA[i][j-1])%mod;
}
long ans = 0;
for(int valueAtB = n;valueAtB>=1;valueAtB--){
// int i = n-i+1;
long sum = 0;
for(int i =1;i<=valueAtB;i++)
sum = (sum+dpA[i][m])%mod;
ans = (ans + (sum*dpA[n-valueAtB+1][m])%mod)%mod;
}
out.println(ans);
}
}
private static int solve(String in){
int ans = 0;
int cnt = 0;
int[] preSum = new int[in.length()];
int[] postSum = new int[in.length()];
for(int i=0;i<in.length();i++)
{
if(i==0)
preSum[i]=in.charAt(i)=='('?1:-1;
else
{
preSum[i] = preSum[i-1] + (in.charAt(i)=='('?1:-1);
}
}
// for(int x : preSum)
// {
// System.out.print(x +" ");
// }
// System.out.println(" -> " + in );
int postCnt = 0;
int firstOpenInx = -1;
for(int i = in.length()-1;i>=0;i--)
{
if(in.charAt(i) == '(')
postCnt++;
else
postCnt--;
int preCnt = i>0?preSum[i-1]:0;
if(postCnt+preCnt == 0)
{
System.out.println(i + " -> " + preCnt + " " + postCnt);
firstOpenInx = i;
}
}
if(firstOpenInx == -1)
return 0;
for(int i=firstOpenInx;i<in.length();i++)
{
System.out.println(in + " " + i + " -> " + firstOpenInx);
if(in.charAt(i) == ')')
cnt--;
else
cnt++;
if(cnt==0)
ans++;
}
for(int i=0;i<firstOpenInx;i++)
{
System.out.println(in + " " + i + " -> " + firstOpenInx);
if(in.charAt(i) == ')')
cnt--;
else
cnt++;
if(cnt==0)
ans++;
}
return ans++;
}
}
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;
}
private 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);
}
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | bb08d295220596975b512b59f9a90836 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigInteger;
import static java.lang.Math.*;
public class Main
{
static final int mod = (int)1e9+7;
public static void main(String[] args) throws Exception
{
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int test = 1;
while(test-- > 0)
{
int n = in.nextInt();
int m = in.nextInt();
long[] dp = new long[n + 1];
Arrays.fill(dp, 1);
for(int i = 1; i < m + m; i++) {
long prefix = 0;
for(int j = 1; j <= n; j++) {
prefix = (prefix + dp[j]) % mod;
dp[j] = prefix;
}
}
long ans = 0;
for(int i = 1; i <= n; i++) {
ans = (ans + dp[i]) % mod;
}
out.println(ans);
}
out.flush();
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() throws IOException
{
if(st == null || !st.hasMoreElements())
{
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();
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | e13b5ff68c5612764647f48062f44775 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Jaynil
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
CTwoArrays solver = new CTwoArrays();
solver.solve(1, in, out);
out.close();
}
static class CTwoArrays {
public void solve(int testNumber, InputReader in, PrintWriter out) {
long n = in.nextLong();
long m = in.nextLong();
long n2mfact = 1;
long m2fact = 1;
long fact = 1;
long mod = 1000000007;
for (int i = 1; i <= n + 2 * m - 1; i++) {
n2mfact *= i;
n2mfact %= mod;
}
for (int i = 1; i <= 2 * m; i++) {
m2fact *= i;
m2fact %= mod;
}
for (int i = 1; i <= n - 1; i++) {
fact *= i;
fact %= mod;
}
long den = fact * m2fact;
den %= mod;
out.println((n2mfact * Maths.power(den, mod - 2, mod)) % mod);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public long nextLong() {
return Long.parseLong(next());
}
}
static class Maths {
static long power(long x, long y, long p) {
long res = 1;
x = x % p;
while (y > 0) {
if ((y & 1) == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 24a98b3a446602e63ef4fef54bbb6005 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | // No sorceries shall prevail. //
import java.util.*;
import java.io.*;
public class InVoker {
static long mod = 1000000007;
public static void main(String args[]) {
Scanner inp=new Scanner(System.in);
PrintWriter out=new PrintWriter(System.out);
int n=inp.nextInt();
int m=inp.nextInt();
long ways[][]=new long[n][2*m+1];
for(int i=0;i<n;i++) {
ways[i][0]=1;
}
for(int j=0;j<=2*m;j++) {
ways[0][j]=1;
}
for(int i=1;i<n;i++) {
for(int j=1;j<=2*m;j++) {
ways[i][j]=(ways[i-1][j]%mod + ways[i][j-1]%mod)%mod;
}
}
out.println(ways[n-1][2*m]);
out.close();
inp.close();
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 95b46c5303623b907b6140364630a2b3 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class TwoArrays1288C {
public static void main(String[] args) {
FastReader fr = new FastReader();
int n = fr.nextInt();
int m = fr.nextInt();
int[][] a = new int[n+2][2*(m+1)];
for(int i=1; i <= 2*m; i++) {
a[1][i] = 1;
}
for(int i=1; i <= n; i++) {
a[i][1] = i;
}
for(int i=2; i <= n+1; i++) {
for(int j=2; j <= 2*m+1; j++) {
a[i][j]=(a[i][j-1] + a[i-1][j]) % 1000000007;
}
}
System.out.println(a[n][2*m]);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | b14ca4571ee155edfc0084c5c81cdd02 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 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 > {
long x;
long y;
pair(long i, long j) {
x = i;
y = j;
}
public int compareTo(pair p) {
if (this.x != p.x) {
return Long.compare(this.x,p.x);
} else {
return Long.compare(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 + 9;
long biginf = (long)1e17 + 7 ;
long mod = (int)1e9 + 7;
void solve() throws Exception {
init();
long n=nl(),m=nl();
pn(nCr(n+2*m -1,2*m));
}
int N = (int)1e5+5;
long[] fact = new long[N+1];
long[] ifact = new long[N+1];
void init(){
fact[0] =1 ;
ifact[0] = 1 ;
for(int i=1;i<=N;++i){
fact[i] = (fact[i-1] * i )%mod ;
ifact[i] = pow(fact[i],mod-2) ;
}
}
long nCr (long n,long r){
long ans =1 ;
if(r>n || r< 0) return 0L ;
ans = (ans*fact[(int)n])%mod ;
ans= (ans*ifact[(int)(n-r)])%mod ;
ans= (ans*ifact[(int)r])%mod ;
return 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 | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 1888b55e34193fa36a5789d3a019da79 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes |
import java.io.*;
public class c1288 {
public static void main(String[] args)throws IOException {
BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
int mod = 1000000007;
String[] s1 = inp.readLine().split(" ");
int n = Integer.parseInt(s1[0]);
int size = Integer.parseInt(s1[1]);
int[][] dp = new int[n+1][size*2];
size*=2;
for(int i=0;i<size;i++){
dp[0][i] = 1;
}
for(int i=1;i<=n;i++){
dp[i][0] = i+1;
}
for(int i=1;i<size;i++){
for(int j=1;j<=n;j++){
dp[j][i] = dp[j-1][i]+dp[j][i-1];
dp[j][i]%=mod;
}
}
//print(dp);
System.out.println(dp[n-1][size-1]);
}
static void print(int[][] bin){
for(int i=0;i<bin.length;i++){
for(int j=0;j<bin[0].length;j++) {
System.out.print(bin[i][j] + " ");
}
System.out.println();
}
System.out.println();
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | e40ac29a7a9e4a37c2dcd69920815d3b | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.util.*;
public class Abc {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
long sumA[][] = new long[n][2 * m];
for(int j = 2 * m - 1; j >= 0; j --) {
for(int i = 0; i < n; i++) {
if(j == 2 * m - 1) {
sumA[i][j] = 1;
} else {
sumA[i][j] = sumA[i][j + 1];
}
}
for(int i = n - 2; i >= 0; i --) {
sumA[i][j] += sumA[i + 1][j];
sumA[i][j] %= mod;
}
}
//print(sumA);
System.out.println(sumA[0][0]);
}
public static void print(long ar[][]) {
for(int i = 1; i < ar.length; i++) {
System.out.println(Arrays.toString(ar[i]));
}
}
long sum = 0;
static long mod = 1000000007;
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | 566d74d92b857573e2250921ef3e07f6 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | // Magic. Do not touch.
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
static class FastReader
{
private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;}
public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
public String next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
public double d() throws IOException {return Double.parseDouble(next()) ;}
public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i();}}
public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}}
public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } }
}
public static void main(String[] args) throws IOException {
FastReader fr=new FastReader();
PrintWriter pw=new PrintWriter(System.out);
/*
inputCopy
2 2
outputCopy
5
inputCopy
10 1
outputCopy
55
inputCopy
723 9
outputCopy
157557417
*/
int t=1;
for(int ti=0;ti<t;++ti) {
int n=fr.i();
int m=fr.i();
//Its (2m+n-1)! / ((n-1)!*(2m)!)
long mod=(long)(1e9+7);
long num1=1;
for(int i=2*m+n-1;i>=1;--i,num1%=mod)
num1*=i;
long divisor=1;
for(int i=n-1;i>=1;--i,divisor%=mod)
divisor*=i;
for(int i=2*m;i>=1;--i,divisor%=mod)
divisor*=i;
BigInteger bigDiv=new BigInteger(divisor+"");
BigInteger modInv=bigDiv.modInverse(new BigInteger(mod+""));
long num2=modInv.longValue();
pw.println((num1*num2)%mod);
}
pw.flush();
pw.close();
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | ad42077a29d2c50362f77a2239f72f96 | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.lang.*;
import java.util.*;
import java.io.*;
public class Main {
void solve() {
int n=ni(),m=ni();
int dp[][][]=new int[2][n+1][n+1];
for(int k1=1;k1<=n;k1++) for(int k2=k1;k2<=n;k2++) dp[1][k1][k2]=1;
int dp2[][]=new int[n+1][n+1];
int dp3[][]=new int[n+1][n+1];
for(int k1=0;k1<=n;k1++){
for(int k2=n;k2>=0;k2--){
dp2[k1][k2]=dp[1][k1][k2];
if(k2+1<=n) dp2[k1][k2]=add(dp2[k1][k2],dp2[k1][k2+1]);
}
}
for(int k1=0;k1<=n;k1++){
for(int k2=0;k2<=n;k2++){
dp3[k1][k2]=dp2[k1][k2];
if(k1-1>=0) dp3[k1][k2]=add(dp3[k1][k2],dp3[k1-1][k2]);
}
}
for(int i=2;i<=m;i++){
for(int j1=1;j1<=n;j1++){
for(int j2=j1;j2<=n;j2++){
dp[i%2][j1][j2]=dp3[j1][j2];
}
}
for(int k1=0;k1<=n;k1++){
for(int k2=n;k2>=0;k2--){
dp2[k1][k2]=dp[i%2][k1][k2];
if(k2+1<=n) dp2[k1][k2]=add(dp2[k1][k2],dp2[k1][k2+1]);
}
}
for(int k1=0;k1<=n;k1++){
for(int k2=0;k2<=n;k2++){
dp3[k1][k2]=dp2[k1][k2];
if(k1-1>=0) dp3[k1][k2]=add(dp3[k1][k2],dp3[k1-1][k2]);
}
}
}
int ans=0;
for(int k1=1;k1<=n;k1++) for(int k2=k1;k2<=n;k2++) ans=add(ans,dp[m%2][k1][k2]);
pw.println(ans);
}
int add(long a,long b){
a+=b;
if(a>=M) a-=M;
return (int)a;
}
long M =(long)1e9+7;
InputStream is;
PrintWriter pw;
String INPUT = "";
void run() throws Exception {
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
pw = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
pw.flush();
if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms");
}
public static void main(String[] args) throws Exception {
new Main().run();
}
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
private double nd() {
return Double.parseDouble(ns());
}
private char nc() {
return (char) skip();
}
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m) {
char[][] map = new char[n][];
for (int i = 0; i < n; i++) map[i] = ns(m);
return map;
}
private int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = ni();
return a;
}
private int ni() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
private long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) {
if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
}
} | Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | f171fb6ca495cb5b086d07a2abd31c8f | train_004.jsonl | 1579012500 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a$$$ is sorted in non-descending order; array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class UnshuffeledDeck {
public static void main(String[] args) {
FastReader input=new FastReader();
PrintWriter out=new PrintWriter(System.out);
int n=input.nextInt();
int m=input.nextInt();
BigInteger a=new BigInteger(String.valueOf(n+2*m-1));
a=fac(a);
BigInteger b=new BigInteger(String.valueOf(2*m));
b=fac(b);
BigInteger c=new BigInteger(String.valueOf(n-1));
c=fac(c);
BigInteger ans=new BigInteger("1");
ans=ans.multiply(a);
ans=ans.divide(b);
ans=ans.divide(c);
ans=ans.mod(new BigInteger("1000000007"));
out.println(ans.toString());
out.close();
}
public static BigInteger fac(BigInteger b)
{
if(b.toString().equals("0"))
{
return new BigInteger("1");
}
else
{
BigInteger b1=b;
b1=b1.subtract(new BigInteger("1"));
return b.multiply(fac(b1));
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["2 2", "10 1", "723 9"] | 1 second | ["5", "55", "157557417"] | NoteIn the first test there are $$$5$$$ suitable arrays: $$$a = [1, 1], b = [2, 2]$$$; $$$a = [1, 2], b = [2, 2]$$$; $$$a = [2, 2], b = [2, 2]$$$; $$$a = [1, 1], b = [2, 1]$$$; $$$a = [1, 1], b = [1, 1]$$$. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 82293f824c5afbf9dbbb47eac421af33 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$). | 1,600 | Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$. | standard output | |
PASSED | e434ed6b5961b19ae3ed47c93f4debc8 | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.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.io.PrintStream;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Mehvix
*/
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);
P_1335D solver = new P_1335D();
solver.solve(1, in, out);
out.close();
}
static class P_1335D {
public void solve(int testNumber, Scanner fin, PrintWriter fout) {
int t = fin.nextInt();
while (t-- > 0) {
for (int i = 0; i < 9; i++) {
String input = fin.next();
System.out.println(input.replace('2', '3'));
}
}
}
}
}
| Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | f3a6af4be0a7b331c92dd73405d9299f | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class antiSudoku {
public static void main(String []args){
Scanner scn= new Scanner(System.in);
int t= scn.nextInt();
while(t>0){
for(int i=0;i<9;i++){
String s=scn.next();
for(int j=0;j<9;j++){
if(s.charAt(j)=='9')
s=s.substring(0,j)+'8'+s.substring(j+1);
}
System.out.println(s);
}
t--;
}
}
} | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | 30e8508ed8d383f304c1719bf099a67f | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class antiSudoku {
public static void main(String []args){
Scanner scn= new Scanner(System.in);
int t= scn.nextInt();
while(t>0){
for(int i=0;i<9;i++){
String s=scn.next();
for(int j=0;j<9;j++){
if(s.charAt(j)=='2')
s=s.substring(0,j)+'1'+s.substring(j+1);
}
System.out.println(s);
}
t--;
}
}
} | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | f1866a38d38fe379c27a12297e9397bf | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | // import java.util.ArrayList;
// import java.util.*;
// public class boardPath {
// public static void main(String[] args) {
// ArrayList<String> result = getBoard(0, 10);
// System.out.println(result);
// }
// public static ArrayList<String> getBoard(int start, int end) {
// if (start == end) {
// ArrayList<String> aa = new ArrayList<>();
// aa.add("\n");
// return aa;
// }
// if (start > end) {
// ArrayList<String> aa = new ArrayList<>();
// return aa;
// }
// ArrayList<String> mr = new ArrayList<>();
// for (int dice = 1; dice < 7; dice++) {
// ArrayList<String> rr = getBoard(start + dice, end);
// for (String ss : rr) {
// mr.add(dice + ss);
// }
// }
// return mr;
// }
// }
import java.util.*;
import java.io.*;
public class boardPath {
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 t = new FastReader();
PrintWriter o = new PrintWriter(System.out);
int tt = t.nextInt();
int[] sudoku = new int[9];
while (tt-- > 0) {
for (int i = 0; i < 9; i++) {
String s = t.next();
for (int j = 0; j < 9; j++) {
sudoku[j] = Integer.parseInt(s.charAt(j) + "");
if (sudoku[j] == 2)
sudoku[j] = 1;
o.print(sudoku[j]);
}
o.println();
}
}
o.flush();
o.close();
}
} | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | 5f9d458c56b72032b3bc9a447875c390 | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
import java.lang.Math;
import java.lang.*;
import java.math.BigInteger;
public class Main{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int t;
t=in.nextInt();
in.nextLine();
for(int i=0;i<t;i++)
{
char arr[][]=new char[9][9];
String s;
for(int j=0;j<9;j++)
{
s=in.nextLine();
arr[j]=s.toCharArray();
}
//System.out.println(arr[0]);
arr[0][0]=arr[0][1];
arr[1][3]=arr[1][4];
arr[2][6]=arr[2][7];
arr[3][1]=arr[3][2];
arr[4][4]=arr[4][5];
arr[5][7]=arr[5][8];
arr[6][2]=arr[6][3];
arr[7][5]=arr[7][6];
arr[8][8]=arr[8][7];
for(int j=0;j<9;j++)
{
System.out.println(arr[j]);
}
}
}
}
/*
00
13
26
31
44
57
62
75
88
*/ | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | 7fd5728cc14987b1edf8b081d36e1c2e | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class D {
public static void main(String[] args) throws IOException {
FastReader in = new FastReader();
BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
for (int t = in.nextInt(); t > 0; t--) {
int n = 9;
int m = 3;
int a[][] = new int[n][n];
for (int i = 0; i < n; i++) {
char[] ar = in.next().toCharArray();
for (int j = 0; j < n; j++) {
a[i][j] = ar[j] - 48;
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
a[m * j + i][m * i + j] = (a[m * j + i][m * i + j] + 1);
if (a[m * j + i][m * i + j] == 10) {
a[m * j + i][m * i + j] = 1;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
log.write(a[i][j]+"");
}
log.write("\n");
}
}
log.flush();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | b2c5240bbbcb01ab3494986ecf2d1c0b | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner in=new Scanner(System.in);
int t=in.nextInt();
while(t--!=0)
{
int a[][]=new int[9][9];
int b[][]=new int[9][9];
for(int i=0;i<9;i++)
{
long v=in.nextLong();
for(int j=0;j<9;j++)
{
a[i][j]=(int)v/(int)Math.pow(10,8-j);
v=v%(int)Math.pow(10,8-j);
if(a[i][j]==1)
b[i][j]=2;
else
b[i][j]=a[i][j];
}
}
for(int i=0;i<9;i++)
{
long s=0;
for(int j=0;j<9;j++)
{
s=s+(int)Math.pow(10,8-j)*b[i][j];
}
System.out.println(s);
}
}
}
} | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | f71541a4c0f0c4d7541eb1ff9f328c45 | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner in=new Scanner(System.in);
int t=in.nextInt();
while(t--!=0)
{
int a[][]=new int[9][9];
int b[][]=new int[9][9];
for(int i=0;i<9;i++)
{
long v=in.nextLong();
for(int j=0;j<9;j++)
{
a[i][j]=(int)v/(int)Math.pow(10,8-j);
v=v%(int)Math.pow(10,8-j);
if((i==0 && j==0) || (i==1 && j==3) || (i==2 && j==6) || (i==3 && j==1) || (i==4 && j==4) || (i==5 && j==7) || (i==6 && j==2) || (i==7 && j==5) || (i==8 && j==8))
{
if(a[i][j]+1<=9)
b[i][j]=a[i][j]+1;
else
b[i][j]=a[i][j]-1;
}
else
b[i][j]=a[i][j];
}
}
for(int i=0;i<9;i++)
{
long s=0;
for(int j=0;j<9;j++)
{
s=s+(int)Math.pow(10,8-j)*b[i][j];
}
System.out.println(s);
}
}
}
}
| Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | b4a63243c45f6d69d037eba6f67bceaa | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class cf634div3D {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int j=1;j<=t;j++)
{for(int i=1;i<=9;i++)
{String s=sc.next();
s=s.replace('2','1');
System.out.println(s);}}
sc.close();
}
} | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | e4686b6dc7a7b4a242e2792dc087bd84 | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
import java.io.*;
public class codeforces{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
OutputStream outputStream = System.out;
int t=Integer.parseInt(br.readLine().trim());
StringBuilder aans=new StringBuilder();
while(t-->0)
{
Integer arr[][]=new Integer[9][9];
for(int i=0;i<9;i++) {
String tok=br.readLine();
for(int j=0;j<9;j++) {
arr[i][j]=(int)(tok.charAt(j)-48);
}
}
arr[0][0]=arr[1][0];
arr[3][1]=arr[4][1];
arr[6][2]=arr[7][2];
arr[1][3]=arr[0][3];
arr[4][4]=arr[3][4];
arr[7][5]=arr[6][5];
arr[2][6]=arr[1][6];
arr[5][7]=arr[4][7];
arr[8][8]=arr[7][8];
StringBuilder ans=new StringBuilder();
for(int i=0;i<9;i++) {
for(int j=0;j<9;j++) {
ans.append(arr[i][j]);
}
ans.append("\n");
}
System.out.println(ans);
}
}
} | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | 992bd7485316e804e439a5f8a8c14b38 | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.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 Cf131 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 Cf131(),"Main",1<<27).start();
}
static class Pair{
int nod;
int ucn;
Pair(int nod,int ucn){
this.nod=nod;
this.ucn=ucn;
}
public static Comparator<Pair> wcompr = new Comparator<Pair>(){
public int compare(Pair e1,Pair e2){
//reverse order
if (e1.ucn < e2.ucn)
return 1;
else if (e1.ucn > e2.ucn)
return -1;
return 0;
}
};
}
public static int gcd(int a,int b){
if(b==0)return a;
else return gcd(b,a%b);
}
public void run()
{
InputReader sc = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int t= sc.nextInt();
while(t-->0){
Integer[][] a = new Integer[9][9];
Integer[][] ind = {
{0, 1, 2, 9, 10,11,18,19,20},
{3, 4, 5, 12,13,14,21,22,23},
{6, 7, 8, 15,16,17,24,25,26},
{27,28,29,36,37,38,45,46,47},
{30,31,32,39,40,41,48,49,50},
{33,34,35,42,43,44,51,52,53},
{54,55,56,63,64,65,72,73,74},
{57,58,59,66,67,68,75,76,77},
{60,61,62,69,70,71,78,79,80}
};
Integer[][] b = {
{0,2},
{3,2},
{6,2},{0,5},{3,5},{6,5},{0,8},{3,8},{6,8}
};
//HashMap<Integer> hm = new HashMap<Integer,Integer>();
for(int i=0;i<9;i++){
String s = sc.next();
for(int j=0;j<9;j++){
a[i][j] = (int)(s.charAt(j)-48);
}
}
//w.println("x");
int v = -3;
for(int i=0;i<9;i++){
v= (v+3)%9;
int j=v+(i/3);
if(a[i][j]==1)
a[i][j] = 2;
else a[i][j] = 1;
// for(int j=0;j<9;j+=3){
// int z = ind[i][j];
// int x = z/9;
// int y = z%9;
// int r = b[i][0]+2;
// int u = b[i][1]-2;
// if((i%3)==(j%3)){
// // if(x==b[i][1]){
// // a[x-1][y] = (i+1);
// // }
// // else if(x==u){
// // a[x+1][y] = (i+1);
// // }
// // else{
// if(y==b[i][0]){
// a[x][y+1] = a[i][j];
// }
// else if(y==r){
// a[x][y-1] = a[i][j];
// }
// else{
// a[x][y-1] = a[i][j];
// }
// // }
}
for(int i=0;i<9;i++){
for(int x=0;x<9;x++){
w.print(a[i][x]);
//if((x+1)%3==0)w.print(" ");
}
w.println();
//if((i+1)%3==0)w.println();
}
//w.print("x");
}
w.flush();
w.close();
}
} | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | 3811db2db53a2ec54c6b08da7bf5f944 | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class Antisudoku
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while(t-->0)
{
int c =0;
for(int i=0;i<9;i++)
{
String s = in.next();
if(i==3)
c=1;
else if(i==6)
c=2;
int x = Integer.parseInt(s.substring(c,c+1));
x=(x+1)%9+1;
System.out.println(s.substring(0,c)+x+s.substring(c+1));
c+=3;
}
/*for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
System.out.print(arr[i][j]+" ");
System.out.println();
}*/
/*
0 0
1 3
2 6
3 1
4 4
5 7
6 2
7 5
8 8
*/
//System.out.println();
//System.out.println();
}
}
} | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | 282f180dbf1c19f280ecc86a976ceff4 | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | // Working program with FastReader
import java.io.*;
import java.security.spec.RSAOtherPrimeInfo;
import java.util.*;
public class codeforces_1335D
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static void solve(FastReader ob){
char arr[][]= new char[10][10];
for (int i = 1; i <=9 ; i++) {
String s=ob.next();
char c[]=s.toCharArray();
for (int j = 0; j <9 ; j++) {
arr[i][j+1]=c[j];
}
}
int k1=4,k2=7,k3=1;
boolean flag=true;
for (int i = 1; i <10 ; i++) {
if(i%3!=0){
arr[k1][i]=arr[1][i];
k1++;
i++;
arr[k2][i]=arr[1][i];
i++;
k2++;
}
if(i%3==0){
if(i!=9){
arr[k3+1][i]=arr[k3][i];
k3++;
}
else{
arr[1][i]=arr[3][9];
}
}
}
for (int i = 1; i <=9 ; i++) {
String ans =new String(arr[i]);
System.out.println(ans.trim());
}
}
public static void main(String[] args)
{
FastReader ob=new FastReader();
int t=ob.nextInt();
for (int i = 0; i < t; i++) {
solve(ob);
}
}
}
| Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | 7fb82fb3321644cd48663c7c072537f3 | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class CodeJamProb3
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int j=0;j<t;j++)
{
String s;
StringBuilder sb = new StringBuilder("");
for(int i=0;i<9;i++)
{
s = sc.next();
for(int k=0;k<9;k++)
{
if(s.charAt(k)=='1')
{
sb.append('2');
}
else
{
sb.append(s.charAt(k));
}
}
sb.append("\n");
}
System.out.println(sb);
}
}
} | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | 0b9fadf4606e030fcfef77caa5cb5bc4 | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class AntiSuduko {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
s.nextLine();
while(t -- > 0) {
char[][] arr = new char[9][9];
for(int i = 0; i < 9; i++) {
arr[i] = s.nextLine().toCharArray();
for(int j = 0; j < 9; j ++) {
if(arr[i][j] == '1') {
arr[i][j] = '2';
}
}
System.out.println(arr[i]);
}
}
}
} | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | 91ea7abdeff76bb33f30965f505462db | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.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) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Unstoppable solver = new Unstoppable();
int t=in.nextInt();
while(t-->0)
solver.solve(in, out);
out.close();
}
static class Unstoppable {
public void solve(InputReader in, PrintWriter out) {
char ch[][]=new char[9][9];
for(int i=0;i<9;i++){
ch[i]=in.next().toCharArray();
}
ch[0][0]=ch[0][1]; ch[1][3]=ch[1][4]; ch[2][6]=ch[2][7]; ch[3][1]=ch[3][2]; ch[4][4]=ch[4][5]; ch[5][7]=ch[5][8]; ch[6][2]=ch[6][1]; ch[7][5]=ch[7][4]; ch[8][8]=ch[8][7];
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
out.print(ch[i][j]+"");
}out.println("");
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public long nextLong(){
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | 31e504693ad60f1d9eb540f2ee3b1c4c | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
import java.io.*;
public class Anti_Sudoku {
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) {
// TODO Auto-generated method stub
FastReader t = new FastReader();
PrintWriter o = new PrintWriter(System.out);
int test = t.nextInt();
int[][] a = new int[9][9];
while (test-- > 0) {
for (int i = 0; i < 9; ++i) {
String s = t.next();
for (int j = 0; j < 9; ++j)
a[i][j] = Integer.parseInt(s.charAt(j) + "");
}
int p = 0;
// for (int i = 0; i < 9; ++i) {
// for (int j = 0; j < 9; ++j) {
// int x = p / 3;
// int y = p % 3;
//
// if (i == x && y == j) {
// a[i][j] = a[i][j] == 9 ? 1 : a[i][j] + 1;
// p++;
// }
// }
// }
p = a[0][0];
a[0][0] = p == 9 ? 1 : p + 1;
p = a[1][3];
a[1][3] = p == 9 ? 1 : p + 1;
p = a[2][6];
a[2][6] = p == 9 ? 1 : p + 1;
p = a[3][1];
a[3][1] = p == 9 ? 1 : p + 1;
p = a[4][4];
a[4][4] = p == 9 ? 1 : p + 1;
p = a[5][7];
a[5][7] = p == 9 ? 1 : p + 1;
p = a[6][2];
a[6][2] = p == 9 ? 1 : p + 1;
p = a[7][5];
a[7][5] = p == 9 ? 1 : p + 1;
p = a[8][8];
a[8][8] = p == 9 ? 1 : p + 1;
for (int i = 0; i < 9; ++i) {
for (int j = 0; j < 9; ++j)
o.print(a[i][j]);
o.println();
}
}
o.flush();
o.close();
}
} | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | 10327ea23ea9a9025e2f8601ba10ad25 | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class test {
public static void main(String[] args) {
Scanner t = new Scanner(System.in);
int test = t.nextInt();
while (test-- > 0) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 9; ++i) {
String s = t.next();
for (int j = 0; j < 9; ++j) {
if (s.charAt(j) == '1')
sb.append('2');
else
sb.append(s.charAt(j));
}
sb.append("\n");
}
System.out.println(sb);
}
}
} | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | a5d6ac7eb3cde154e0064797509ab558 | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class test {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int test = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
while (test-- > 0) {
int a[][] = new int[9][9];
for (int i = 0; i < 9; i++) {
String s = br.readLine();
for (int j = 0; j < 9; j++) {
a[i][j] = Integer.parseInt(s.charAt(j) + "");
if (a[i][j] == 1)
sb.append(2);
else
sb.append(a[i][j]);
}
sb.append("\n");
}
}
System.out.println(sb);
}
} | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | 77e8bba2d501062bd609cae44646f1d0 | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class test {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int test = Integer.parseInt(new StringTokenizer(br.readLine()).nextToken());
StringBuilder st = new StringBuilder();
while (test-- > 0) {
int[] sudoku = new int[9];
for (int i = 0; i < 9; i++) {
String s = new StringTokenizer(br.readLine()).nextToken();
for (int j = 0; j < 9; j++) {
sudoku[j] = Integer.parseInt(s.charAt(j) + "");
if (sudoku[j] == 2)
sudoku[j] = 1;
st.append(sudoku[j]);
}
st.append("\n");
}
}
out.print(st);
out.flush();
out.close();
}
} | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | 04154fb6dc82965aa5d0013244437f08 | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
import java.lang.*;
public class HelloWorld{
public static void main(String []args){
Scanner in = new Scanner(System.in);
int t=in.nextInt();
in.nextLine();
while(t>0)
{
String[] s = new String[9];
for(int i=0;i<9;i++)
{
s[i]=in.nextLine();
}
int cnt=0;
for(int i=0;i<9;i=i+3)
{
int cnt1=0;
for(int k=i,j=cnt;cnt1<3;k++,j=j+3,cnt1++)
{
if(s[k].charAt(j)=='1')
{
s[k]=s[k].substring(0,j)+"2"+s[k].substring(j+1,s[k].length());
}
else
{
s[k]=s[k].substring(0,j)+"1"+s[k].substring(j+1,s[k].length());
}
}
cnt++;
}
for(int i=0;i<9;i++)
{
System.out.println(s[i]);
}
t--;
}
}
} | Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output | |
PASSED | 2855f9e01190c8fb6b2651129c513872 | train_004.jsonl | 1586788500 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main (String[] args) {
FastScanner scanner = new FastScanner();
int t = scanner.nextInt();
while (t-- > 0) {
for (int i = 0; i < 9; i++) {
String s = scanner.nextLine();
StringBuilder sbr = new StringBuilder(s);
for (int j = 0; j < sbr.length(); j++) {
if (sbr.charAt(j) == '9') sbr.replace(j, j + 1, "1");
}
System.out.println(sbr.toString());
}
}
}
}
class FastScanner {
public BufferedReader reader;
public StringTokenizer tokenizer;
public FastScanner() {
reader = new BufferedReader(new InputStreamReader(System.in), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
try {
return reader.readLine();
} catch(IOException e) {
throw new RuntimeException(e);
}
}
}
| Java | ["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"] | 2 seconds | ["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation"
] | 0e21f1c48c8c0463b2ffa7275eddc633 | 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. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle. | 1,300 | For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.