exec_outcome
stringclasses 1
value | code_uid
stringlengths 32
32
| file_name
stringclasses 111
values | prob_desc_created_at
stringlengths 10
10
| prob_desc_description
stringlengths 63
3.8k
| prob_desc_memory_limit
stringclasses 18
values | source_code
stringlengths 117
65.5k
| lang_cluster
stringclasses 1
value | prob_desc_sample_inputs
stringlengths 2
802
| prob_desc_time_limit
stringclasses 27
values | prob_desc_sample_outputs
stringlengths 2
796
| prob_desc_notes
stringlengths 4
3k
β | lang
stringclasses 5
values | prob_desc_input_from
stringclasses 3
values | tags
sequencelengths 0
11
| src_uid
stringlengths 32
32
| prob_desc_input_spec
stringlengths 28
2.37k
β | difficulty
int64 -1
3.5k
β | prob_desc_output_spec
stringlengths 17
1.47k
β | prob_desc_output_to
stringclasses 3
values | hidden_unit_tests
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 864367890b7084c47f5fdac7732913e6 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes |
import java.io.*;
import java.util.*;
public class C315B {
void solution() throws Exception {
int n = in.nextInt(), m = in.nextInt(), y = 0;
long[] f = new long[n];
for (int i = 0; i < n; i++) {
f[i] = in.nextInt();
}
for (int i = 0; i < m; i++) {
int t = in.nextInt();
if (t == 1) {
int v = in.nextInt() - 1;
int x = in.nextInt();
f[v] = x - y;
} else if (t == 2) {
y += in.nextInt();
} else {
int q = in.nextInt() - 1;
out.println(f[q] + y);
}
}
}
public static void main(String[] args) throws Exception {
new C315B().run();
}
Scanner in;
PrintWriter out;
void run() throws Exception {
in = new Scanner(new InputStreamReader(System.in));
out = new PrintWriter(new OutputStreamWriter(System.out));
solution();
out.flush();
}
class Scanner {
final BufferedReader br;
StringTokenizer st;
Scanner(InputStreamReader stream) {
br = new BufferedReader(stream);
}
String next() throws Exception {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
Integer nextInt() throws Exception {
return Integer.parseInt(next());
}
Long nextLong() throws Exception {
return Long.parseLong(next());
}
Double nextDouble() throws Exception {
return Double.parseDouble(next());
}
}
}
| Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | 470e05859132598ffb64f4aa8a4a1883 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class B315 {
public static void main (String args[]){
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
int m = in.nextInt();
int a[] = new int [n];
int up = 0;
for(int i = 0 ; i < n ; i++){
a[i] =in.nextInt();
}
for(int i = 0 ; i < m ; i++){
int tmp = in.nextInt();
if(tmp==1){
int ind = in.nextInt()-1;
int inc = in.nextInt();
a[ind] = inc - up;
}
else if(tmp==2){
up+=in.nextInt();
}
else if(tmp==3) {
int ind = in.nextInt()-1;
out.println(a[ind]+up);
}
}
out.close();
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public FastScanner(InputStream f) {
br = new BufferedReader(new InputStreamReader(f));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
boolean hasMoreTokens() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return false;
st = new StringTokenizer(s);
}
return true;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
} | Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | d7ebbafa4b2b638fe3ce36d0ea3f39b2 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes |
import java.io.*;
import java.util.*;
/**
*
* @coder Altynbek Nurgaziyev
*/
public class C315B {
void solution() throws Exception {
int n = in.nextInt(), m = in.nextInt(), y = 0;
long[] f = new long[n];
for (int i = 0; i < n; i++) {
f[i] = in.nextInt();
}
for (int i = 0; i < m; i++) {
int t = in.nextInt();
if (t == 1) {
int v = in.nextInt() - 1;
int x = in.nextInt();
f[v] = x - y;
} else if (t == 2) {
y += in.nextInt();
} else {
int q = in.nextInt() - 1;
out.println(f[q] + y);
}
}
}
public static void main(String[] args) throws Exception {
new C315B().run();
}
Scanner in;
PrintWriter out;
void run() throws Exception {
in = new Scanner(new InputStreamReader(System.in));
out = new PrintWriter(new OutputStreamWriter(System.out));
solution();
out.flush();
}
class Scanner {
final BufferedReader br;
StringTokenizer st;
Scanner(InputStreamReader stream) {
br = new BufferedReader(stream);
}
String next() throws Exception {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
Integer nextInt() throws Exception {
return Integer.parseInt(next());
}
Long nextLong() throws Exception {
return Long.parseLong(next());
}
Double nextDouble() throws Exception {
return Double.parseDouble(next());
}
}
}
| Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | 61fc6fc222c5ca69dc50bcd5cec31a09 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | import java.io.*;
import java.util.*;
public class SerejaAndArray {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(f.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
long[] a = new long[n];
st = new StringTokenizer(f.readLine());
for (int i = 0; i < n; i++)
a[i] = Long.parseLong(st.nextToken());
long add = 0;
for (int i = 0; i < m; i++)
{
st = new StringTokenizer(f.readLine());
int t = Integer.parseInt(st.nextToken());
if (t == 1)
{
int v = Integer.parseInt(st.nextToken());
long x = Long.parseLong(st.nextToken());
a[v-1] = x-add;
}
if (t == 2)
add += Long.parseLong(st.nextToken());
if (t == 3)
System.out.println(a[Integer.parseInt(st.nextToken())-1]+add);
}
}
} | Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | 78a3b58cd5ce9a58fc39df92494db5d3 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
public class SerejaAndArray {
public static void main(String []args) throws IOException
{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
PrintWriter res=new PrintWriter(new OutputStreamWriter(System.out));
StringTokenizer st=new StringTokenizer(bf.readLine()," ");
int n=Integer.parseInt(st.nextToken());
int m=Integer.parseInt(st.nextToken());
int []nros=new int [n+1];
ArrayList<Integer>ys=new ArrayList<Integer>();
int []nrosy=new int [n+1];
int pos=0;
st=new StringTokenizer(bf.readLine()," ");
for(int j=1;j<n+1;j++) nros[j]=Integer.parseInt(st.nextToken());
int t,v,x,y,q;
for(int j=0;j<m;j++)
{
st=new StringTokenizer(bf.readLine()," ");
t=Integer.parseInt(st.nextToken());
if(t==1)
{
v=Integer.parseInt(st.nextToken());
x=Integer.parseInt(st.nextToken());
nros[v]=x;
nrosy[v]=pos;
}
else
{
if(t==2)
{
y=Integer.parseInt(st.nextToken());
if(pos==0)ys.add(y);
else ys.add(ys.get(pos-1)+y);
pos++;
}
else
{
q=Integer.parseInt(st.nextToken());
int a=0;
if(ys.size()>0)a=ys.get(ys.size()-1);
if(nrosy[q]==0) res.println(nros[q]+a);
else
{
int b=a;
if(nrosy[q]<ys.size()) b=ys.get(nrosy[q]-1);
res.println(nros[q]+(a-b));
}
}
}
}
res.flush();
}
} | Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | 13ebe8219d5b58c196f3c861686bde46 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | /*
* To change this template, choose Tools | Templates and open the template in
* the editor.
*/
import java.io.*;
import java.util.*;
public class Task extends ASolver {
int[] a;
int n;
int m;
int y = 0;
StringBuilder result;
public static void main(String[] args) throws IOException {
Task task = new Task();
task.init();
task.readData();
task.solve();
task.writeData(task.result.toString());
}
@Override
public void init() {
super.init();
result = new StringBuilder();
}
@Override
public boolean readData() {
try {
n = nextInt();
m = nextInt();
a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
} catch (Exception ex) {
System.out.println(ex.getCause());
System.out.println(ex.getMessage());
return false;
}
return true;
}
public void solve() throws IOException {
for (int i = 0; i < m; i++) {
int t = nextInt();
switch (t) {
case 1:
operation1(nextInt(), nextInt());
break;
case 2:
operation2(nextInt());
break;
case 3:
operation3(nextInt());
break;
default:
throw new IllegalStateException();
}
}
}
public void operation1(int v, int x) {
a[v-1] = x - y;
}
public void operation2(int yi) {
y+= yi;
}
public void operation3(int q) {
result.append(a[q-1] + y).append("\n");
}
}
abstract class ASolver {
protected StringTokenizer tokens;
protected BufferedReader input;
protected PrintWriter output;
public void init() {
input = new BufferedReader(new InputStreamReader(System.in));
}
public abstract boolean readData();
public void writeData(String result) {
System.out.println(result);
}
public void writeData(int result) {
System.out.println(result);
}
public void writeData(long result) {
System.out.println(result);
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String next() throws IOException {
while (tokens == null || !tokens.hasMoreTokens()) {
tokens = new StringTokenizer(input.readLine());
}
return tokens.nextToken();
}
public String nextPoints() throws IOException {
while (tokens == null || !tokens.hasMoreTokens()) {
tokens = new StringTokenizer(input.readLine(), "\n");
}
return tokens.nextToken();
}
public long infinityImitator(long a, long b) {
if (a == Long.MIN_VALUE) {
return Long.MIN_VALUE;
} else {
return a + b;
}
}
public int infinityImitator(int a, int b) {
if (a == Integer.MIN_VALUE) {
return Integer.MIN_VALUE;
} else {
return a + b;
}
}
/*
* public long max(long... a) { long result = Long.MIN_VALUE; for (int i =
* 0; i < a.length; i++) { result = Math.max(result, a[i]); } return result;
* }
*/
public int indexMax(int... a) {
int result = 0;
int index = -1;
int length = a.length;
for (int i = 0; i < length; i++) {
if (a[i] > result) {
result = a[i];
index = i;
}
}
return index;
}
public int indexMax(long... a) {
long result = 0;
int index = -1;
int length = a.length;
for (int i = 0; i < length; i++) {
if (a[i] > result) {
result = a[i];
index = i;
}
}
return index;
}
public int max(int... a) {
int result = Integer.MIN_VALUE;
for (int i = 0; i < a.length; i++) {
result = Math.max(result, a[i]);
}
return result;
}
public long max(long... a) {
long result = Integer.MIN_VALUE;
for (int i = 0; i < a.length; i++) {
result = Math.max(result, a[i]);
}
return result;
}
}
class ArraySorter {
public static int[] sortIntArray(int[] array) {
int length = array.length;
if (length == 1) {
return array;
} else if (length == 2) {
return array[0] < array[1] ? array : new int[]{array[1], array[0]};
} else {
int l1 = length / 2, l2 = length - l1;
int[] array1 = new int[l1];
int[] array2 = new int[l2];
System.arraycopy(array, 0, array1, 0, l1);
System.arraycopy(array, l1, array2, 0, l2);
array1 = sortIntArray(array1);
array2 = sortIntArray(array2);
return splitSortedIntArrays(array1, array2);
}
}
private static int[] splitSortedIntArrays(int[] mas1, int[] mas2) {
int l1 = mas1.length;
int l2 = mas2.length;
int[] result = new int[l1 + l2];
int i1 = 0, i2 = 0, i;
for (i = 0; i1 < l1 && i2 < l2; i++) {
if (mas1[i1] <= mas2[i2]) {
result[i] = mas1[i1++];
} else {
result[i] = mas2[i2++];
}
}
for (int j = i; i1 < l1; j++) {
result[j] = mas1[i1++];
}
for (int j = i; i2 < l2; j++) {
result[j] = mas2[i2++];
}
return result;
}
private static double[] splitSortedDoubleArrays(double[] mas1, double[] mas2) {
int l1 = mas1.length;
int l2 = mas2.length;
double[] result = new double[l1 + l2];
int i1 = 0, i2 = 0;
int i = 0;
for (i = 0; i1 < l1 && i2 < l2; i++) {
if (mas1[i1] <= mas2[i2]) {
result[i] = mas1[i1++];
} else {
result[i] = mas2[i2++];
}
}
for (int j = i; i1 < l1; j++) {
result[j] = mas1[i1++];
}
for (int j = i; i2 < l2; j++) {
result[j] = mas2[i2++];
}
return result;
}
} | Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | 4d7311c6bda479fb87974570522b6102 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | import java.io.*;
public class R187D2PB {
private static final int ASSIGNMENT = 1;
private static final int INCREMENT = 2;
private static final int PRINTING = 3;
private static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
private static int nextInt() throws IOException {
in.nextToken();
return (int)in.nval;
}
public static void main(String[] args) throws IOException {
int n = nextInt();
int m = nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
int totalIncrement = 0;
PrintWriter out = new PrintWriter(System.out);
for (int i = 0; i < m; i++) {
int operation = nextInt();
switch (operation) {
case ASSIGNMENT: {
int index = nextInt() - 1;
int value = nextInt();
a[index] = value - totalIncrement;
break;
}
case INCREMENT: {
totalIncrement += nextInt();
break;
}
case PRINTING: {
int indexToPrint = nextInt() - 1;
out.println(a[indexToPrint] + totalIncrement);
break;
}
}
}
out.flush();
}
}
| Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | f4db0d609a017626e59ad5f24d195c69 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class B {
public static void main(String[] args) throws IOException {
PrintWriter out = new PrintWriter(System.out);
sc = new StringTokenizer(br.readLine());
int n = nxtInt();
int m = nxtInt();
int[] a = nxtIntArr(n);
long[] b = new long[n];
long toadd = 0;
while (m-- > 0) {
int t = nxtInt();
if (t == 1) {
int i = nxtInt() - 1;
a[i] = nxtInt();
b[i] = toadd;
} else if (t == 2) {
toadd += nxtLng();
} else if (t == 3) {
int i = nxtInt() - 1;
out.println(a[i] + toadd - b[i]);
}
}
br.close();
out.close();
}
static BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
static StringTokenizer sc;
static String nxtTok() throws IOException {
while (!sc.hasMoreTokens()) {
String s = br.readLine();
if (s == null)
return null;
sc = new StringTokenizer(s.trim());
}
return sc.nextToken();
}
static int nxtInt() throws IOException {
return Integer.parseInt(nxtTok());
}
static long nxtLng() throws IOException {
return Long.parseLong(nxtTok());
}
static double nxtDbl() throws IOException {
return Double.parseDouble(nxtTok());
}
static int[] nxtIntArr(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nxtInt();
return a;
}
static long[] nxtLngArr(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nxtLng();
return a;
}
static char[] nxtCharArr() throws IOException {
return nxtTok().toCharArray();
}
} | Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | 5f2e908365543e48e476bb2471b8c03c | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes |
import java.io.*;
import java.util.*;
public class Main {
public static void main(String args[]) throws FileNotFoundException, IOException {
Scanner Reader = new Scanner(System.in);
int n = Reader.nextInt();
int m = Reader.nextInt();
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = Reader.nextLong();
}
long e [] = new long[n];
long inc = 0;
StringBuilder br = new StringBuilder();
for (int i = 0; i < m; i++) {
int q = Reader.nextInt();
if(q==1){
int index = Reader.nextInt()-1;
int v= Reader.nextInt();
a[index] =v;
e[index] = inc;
}
else if (q==2){
int v = Reader.nextInt();
inc +=v;
}
else {
int ii = Reader.nextInt()-1;
br.append(a[ii]+inc-e[ii]).append("\n");
}
}
System.out.print(br);
}
}
/* public static long dfs(int i){
long sum=0;
try {
v[i] =true;
sum=p[i];
for (int j = 0; j < g[i].size(); j++) {
if(v[g[i].get(j)]==false){
// sum+=p[g[i].get(j)];
sum+=dfs(g[i].get(j));
}
} }
catch(Exception e ){
System.out.println("DFS Exception");
}
return sum;
}
*/
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public 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 String nextToken() {
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 isWhitespace(c);
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class exam implements Comparable<exam> {
int a, b;
public exam(int a, int b) {
this.a = a;
this.b = b;
}
@Override
public int compareTo(exam o) {
return Integer.compare(this.a, o.a);
}
}
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/**
* call this method to initialize reader for InputStream
*/
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/**
* get next word
*/
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
static public void nextIntArrays(int[]... arrays) throws IOException {
for (int i = 1; i < arrays.length; ++i) {
if (arrays[i].length != arrays[0].length) {
throw new InputMismatchException("Lengths are different");
}
}
for (int i = 0; i < arrays[0].length; ++i) {
for (int[] array : arrays) {
array[i] = nextInt();
}
}
}
}
| Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | 1fda8e1bc2703ddd00b69b88596fc0ae | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes |
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Trung Pham
*/
public class Code1 {
public static void main(String[] args) {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String[] temp = in.readLine().split(" ");
int n = Integer.parseInt(temp[0]);
int m = Integer.parseInt(temp[1]);
int[] val = new int[n];
int add = 0;
temp = in.readLine().split(" ");
for (int i = 0; i < n; i++) {
val[i] = Integer.parseInt(temp[i]);
}
for (int i = 0; i < m; i++) {
temp = in.readLine().split(" ");
int op = Integer.parseInt(temp[0]);
if (op == 1) {
int index = Integer.parseInt(temp[1]) - 1;
int b = Integer.parseInt(temp[2]);
val[index] = b - add;
} else if (op == 2) {
int b = Integer.parseInt(temp[1]);
add += b;
} else {
int index = Integer.parseInt(temp[1]) - 1;
System.out.println(val[index] + add);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
| Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | 2f8b40f3d5ba9ba1837de1fd38fe1e03 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class B315 {
FastScanner in;
PrintWriter out;
public void solve() throws IOException {
int n = in.nextInt();
int m = in.nextInt();
long[] a = new long[n];
long sum = 0;
for (int i = 0; i < n; i++) {
a[i] = in.nextLong();
}
for (int i = 0; i < m; i++) {
int t = in.nextInt();
if (t == 1) {
int v = in.nextInt() - 1;
long x = in.nextLong();
a[v] = x - sum;
} else if (t == 2) {
sum += in.nextLong();
} else {
out.println(a[in.nextInt() - 1] + sum);
}
}
}
public void run() {
try {
InputStream inputStream = System.in;
in = new FastScanner(inputStream);
out = new PrintWriter(System.out);
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
public boolean hasNext() {
while (st == null || !st.hasMoreTokens()) {
try {
String line = br.readLine();
if (line == null) {
return false;
}
st = new StringTokenizer(line);
} catch (IOException e) {
e.printStackTrace();
}
}
if (st != null && st.hasMoreTokens()) {
return true;
}
return false;
}
public String next() {
if (hasNext()) {
return st.nextToken();
}
return null;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
public static void main(String[] args) {
new B315().run();
}
} | Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | c8736807bfdbf8530910abe332719338 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | import java.io.*;
public class problemBcf {
public static void main(String args[]) throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
/* String str = in.readLine();
// int n = Integer.parseInt(str.split(" ")[0]);
int m = Integer.parseInt(str.split(" ")[1]);
String[] str1 = in.readLine().split(" ");
int[] arr = new int[str1.length];
for(int i=0; i<str1.length; i++)
{
// String str1 = in.readLine();
arr[i] = Integer.parseInt(str1[i]);
}
for(int j=0; j<m; j++)
{
// int num1=0,num2=0,num3=0,num4=0;
int h=0;
String[] s = in.readLine().split(" ");
int op = Integer.parseInt(s[0]);
//System.out.println(op);
switch(op)
{
case '1':
{
int num1 = Integer.parseInt(s[1]);
int num2 = Integer.parseInt(s[2]);
arr[num1-1] = num2-h;
break;
}
case '2':
{
int num3 = Integer.parseInt(s[1]);
System.out.println(num3);
h = h+num3;
// System.out.println(arr[0]);
break;
}
case '3':
{
int num4 = Integer.parseInt(s[1]);
System.out.println(arr[num4-1]+h);
}
}
}
}
}*/
int limit = Integer.parseInt(in.readLine().split(" ")[1]);
String[] c = in.readLine().split(" ");
int a[] = new int[c.length];
for (int i = 0; i < c.length; i++) {
a[i] = Integer.parseInt(c[i]);
}
int add = 0;
for(int i = 0; i < limit; i++) {
String[] l1 = in.readLine().split(" ");
switch (l1[0].charAt(0)) {
case '1':
a[Integer.parseInt(l1[1])- 1] = Integer.parseInt(l1[2]) - add;
break;
case '2':
add += Integer.parseInt(l1[1]);
break;
case '3':
System.out.println(a[Integer.parseInt(l1[1]) - 1] + add);
}
}
}
}
| Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | b5b8e083c1f61475fa1635c2c49b7d54 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class SolutionA{
public static void main(String[] args){
new SolutionA().run();
}
int n, m, d1, d2, x, t;
int a[];
int cnt[];
int last[];
void solve(){
try{
n = in.nextInt();
m = in.nextInt();
last = new int[n+1];
cnt = new int[m+2];
a = new int[n+1];
for(int i = 0; i<n; i++)
a[i] = in.nextInt();
int sum = 0;
for(int i = 1; i<= m; i++){
int t = in.nextInt();
if(t == 1){
int l = in.nextInt()-1;
last[l] = i;
a[l] = in.nextInt() - sum;
}
else if(t == 2){
sum += in.nextInt();
}
else {
int x = in.nextInt()-1;
out.println(a[x] + sum);
}
}
}catch(Exception ex){
ex.printStackTrace();
}
}
class Pair implements Comparable<Pair>{
int x, y;
Pair(int x, int y){
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
if(o.x == x) return ((Integer) y).compareTo(o.y);
return ((Integer) x).compareTo(o.x);
}
}
FastScanner in;
PrintWriter out;
void run(){
in = new FastScanner(System.in);
out = new PrintWriter(new OutputStreamWriter(System.out));
solve();
out.close();
}
void runIO(){
try{
in = new FastScanner(new File("expr.in"));
out = new PrintWriter(new FileWriter(new File("expr.out")));
solve();
out.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
class FastScanner{
BufferedReader bf;
StringTokenizer st;
public FastScanner(File f){
try{
bf = new BufferedReader(new FileReader(f));
}
catch(IOException ex){
ex.printStackTrace();
}
}
public FastScanner(InputStream is){
bf = new BufferedReader(new InputStreamReader(is));
}
String next(){
while(st == null || !st.hasMoreTokens()){
try{
st = new StringTokenizer(bf.readLine());
}
catch(IOException ex){
ex.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
float nextFloat(){
return Float.parseFloat(next());
}
String nextLine(){
try{
return bf.readLine();
}
catch(Exception ex){
ex.printStackTrace();
}
return "";
}
long nextLong(){
return Long.parseLong(next());
}
BigInteger nextBigInteger(){
return new BigInteger(next());
}
BigDecimal nextBigDecimal(){
return new BigDecimal(next());
}
int[] nextIntArray(int n){
int a[] = new int[n];
for(int i = 0; i < n; i++)
a[i] = Integer.parseInt(next());
return a;
}
long[] nextLongArray(int n){
long a[] = new long[n];
for(int i = 0; i < n; i++)
a[i] = Long.parseLong(next());
return a;
}
}
} | Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | 269990f275eba11588df7f260932c71f | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class B {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
int n = sc.nextInt();
int m = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
int offset = 0;
for (int i = 0; i < m; i++) {
int t = sc.nextInt();
if (t == 1) {
int v = sc.nextInt() - 1;
a[v] = sc.nextInt() - offset;
}
else if (t == 2) {
int y = sc.nextInt();
offset += y;
}
else if (t == 3) {
int q = sc.nextInt() - 1;
System.out.println(a[q] + offset);
}
}
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
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 | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | c1cbeb060686c9496631475c46a5a823 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class B {
static BufferedReader in;
static StringTokenizer st;
static PrintWriter out;
static String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static void main(String[] args) throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
System.out)));
int n = nextInt();
int m = nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
int[] sum = new int[m + 1];
int[] lastChange = new int[n];
for (int i = 0; i < m; i++) {
int opType = nextInt();
if (opType == 1) {
int v = nextInt() - 1;
int x = nextInt();
a[v] = x;
sum[i + 1] = sum[i];
lastChange[v] = i;
} else if (opType == 2) {
int y = nextInt();
sum[i + 1] = sum[i] + y;
} else {
sum[i + 1] = sum[i];
int q = nextInt() - 1;
int toPrint = a[q] + (sum[i] - sum[lastChange[q]]);
out.println(toPrint);
}
}
out.close();
}
}
| Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | 3edb8cf732b493ee8c510bedce83fe29 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
public static void main(String... args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] temp = br.readLine().split(" ");
int n = Integer.parseInt(temp[0]);
int m = Integer.parseInt(temp[1]);
long[] t = new long[n];
long global = 0;
List<Long> result = new ArrayList<Long>(m);
temp = br.readLine().split(" ");
for (int i=0; i<n; i++) t[i]=Integer.parseInt(temp[i]);
for (int i=0; i<m; i++){
temp = br.readLine().split(" ");
if (temp[0].equals("1")){
int k = Integer.parseInt(temp[1]);
int x = Integer.parseInt(temp[2]);
t[k-1]=x-global;
} else if (temp[0].equals("2")){
int x = Integer.parseInt(temp[1]);
global+=x;
} else if (temp[0].equals("3")){
int k = Integer.parseInt(temp[1]);
result.add(t[k-1]+global);
} else {
throw new IllegalStateException("Something is wrong");
}
}
StringBuilder sb = new StringBuilder();
for (Long x : result){
sb.append(x);
sb.append("\n");
}
System.out.println(sb);
}
} | Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | d3edb18162fecc4d64d1015dbaa08067 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Codeforces {
private static FastScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
in = new FastScanner(inputStream);
out = System.out;
solve();
}
private static void solve() throws IOException {
int n = in.nextInt();
int m = in.nextInt();
long add = 0;
long a[] = new long[n+1];
for (int i = 1; i <= n; i++) {a[i] = in.nextLong();}
int x, y, z;
for (int i = 0; i < m; i++) {
x = in.nextInt();
y = in.nextInt();
if (x == 1) {
z = in.nextInt();
a[y] = z-add;
}
else if (x == 2) {
add += y;
}
else {
out.println(a[y]+add);
}
}
}
private static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
public boolean hasNext() {
while (st == null || !st.hasMoreTokens()) {
try {
String line = br.readLine();
if (line == null) {
return false;
}
st = new StringTokenizer(line);
} catch (IOException e) {
e.printStackTrace();
}
}
if (st != null && st.hasMoreTokens()) {
return true;
}
return false;
}
public String next() {
if (hasNext()) {
return st.nextToken();
}
return null;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
} | Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | ead9220f8a2bebc0342e149d16ff2457 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
public class CR187TaskB implements Runnable {
private BufferedReader reader;
private PrintWriter writer;
private StringTokenizer tokenizer;
public static void main(String[] args) {
new Thread(new CR187TaskB()).start();
}
@Override
public void run() {
try {
reader = new BufferedReader(new InputStreamReader(System.in));
writer = new PrintWriter(System.out);
solve();
reader.close();
writer.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(9875);
}
}
private String next() throws Exception {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
private int nextInt() throws Exception {
return Integer.parseInt(next());
}
private int n;
private int[] a;
private int[] difIdx;
private int difCnt;
private int[] dif;
private int delta;
private void solve() throws Exception {
n = nextInt();
int m = nextInt();
a = new int[n];
difIdx = new int[n];
dif = new int[m + 1];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
difIdx[i] = 0;
}
int idx;
for (int i = 0; i < m; i++) {
int t = nextInt();
switch (t) {
case 1:
idx = nextInt() - 1;
a[idx] = nextInt();
difIdx[idx] = difCnt;
break;
case 2:
delta += nextInt();
difCnt++;
dif[difCnt] = delta;
break;
case 3:
idx = nextInt() - 1;
writer.println(a[idx] + delta - dif[difIdx[idx]]);
break;
}
}
}
}
| Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | fabb8d7a6acf43b3e501f473baf6c955 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | import java.io.*;
import java.util.*;
public class SerejaAndArray{
public static void main(String[] Args)throws Exception{
FastScanner sc = new FastScanner(System.in);
int n = sc.nextInt();
int q = sc.nextInt();
long sum = 0;
long[] vals = new long[n];
for(int k =0;k<n;k++){
vals[k] = sc.nextInt();
}
for(int k =0;k<q;k++){
int tq = sc.nextInt();
if(tq==3){
System.out.println(vals[sc.nextInt()-1] + sum);
}
if(tq==1){
int ind = sc.nextInt()-1;
vals[ind] = sc.nextInt() - sum;
}
if(tq==2){
sum += sc.nextLong();
}
}
}
public static class FastScanner{
BufferedReader br;
StringTokenizer st;
FastScanner(InputStream in)throws Exception{
br = new BufferedReader(new InputStreamReader(in));
st = new StringTokenizer(br.readLine().trim());
}
public String next() throws Exception{
if(!st.hasMoreTokens()){
st = new StringTokenizer(br.readLine().trim());
return next();
}
return st.nextToken();
}
public int nextInt() throws Exception{
return Integer.parseInt(next());
}
public long nextLong() throws Exception{
return Long.parseLong(next());
}
}
}
| Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | 5bba2fdd05d404d64e7e0cab403c4fa4 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class SerejaAndArray {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
int N = sc.nextInt();
int M = sc.nextInt();
long[] arr = new long[N + 1];
for (int i = 1; i <= N; i++) {
arr[i] = sc.nextLong();
}
long off = 0;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < M; i++) {
int T = sc.nextInt();
if (T == 1) {
int V = sc.nextInt();
int X = sc.nextInt();
arr[V] = X - off;
} else if (T == 2) {
int Y = sc.nextInt();
off += Y;
} else if (T == 3) {
int Q = sc.nextInt();
sb.append((arr[Q] + off) + "\n");
}
}
System.out.print(sb.toString());
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
int nextInt() {
return Integer.parseInt(next());
}
int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
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();
}
String nextLine() {
String str = "";
try { str = br.readLine(); }
catch (IOException e) { e.printStackTrace(); }
return str;
}
}
} | Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | 1ee27cd11e7e05bc914f839442b6d546 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | import java.io.*;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder out = new StringBuilder();
String [] sp = br.readLine().split(" ");
int n = Integer.parseInt(sp[0]);
int m = Integer.parseInt(sp[1]);
int [] inp = new int[n];
sp = br.readLine().split(" ");
int y = 0;
for (int i = 0; i < inp.length; i++) {
inp[i] = Integer.parseInt(sp[i]);
}
int [] c = new int[n];
for (int i = 0; i < m; i++) {
sp = br.readLine().split(" ");
int o = Integer.parseInt(sp[0]);
if(o == 1){
int v = Integer.parseInt(sp[1]);
int x = Integer.parseInt(sp[2]);
inp[v-1] = x;
c[v-1] = -y;
}else if(o == 2){
y += Integer.parseInt(sp[1]);
}else{
int x = Integer.parseInt(sp[1])-1;
out.append((y+inp[x] + c[x]) + "\n");
}
}
System.out.print(out);
}
} | Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | 3d649bb250e61a1062821bca42df1b79 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class SerejaAndArray {
public static void main(String... args) throws IOException{
MyScanner sc = new MyScanner();
int n = sc.nextInt();
int m = sc.nextInt();
long add = 0;
int[] tab = new int[n];
long[] bakTab = new long[n];
for (int i=0;i<n; i++){
tab[i] = sc.nextInt();
}
for (int i=0;i<m;i++){
int choice = sc.nextInt();
switch (choice){
case 1:
int vi = sc.nextInt()-1;
int val = sc.nextInt();
tab[vi] = val;
bakTab[vi] = add;
break;
case 2:
int yi = sc.nextInt();
add += yi;
break;
case 3:
int qi = sc.nextInt()-1;
System.out.println(((long)tab[qi])+add-bakTab[qi]);
break;
}
}
}
}
class MyScanner{
BufferedReader br;
StringTokenizer st;
public MyScanner(){
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() throws IOException{
if (st == null || !st.hasMoreTokens()){
String line = br.readLine();
st = new StringTokenizer(line);
}
return st.nextToken();
}
public int nextInt() throws IOException{
String next = next();
return Integer.parseInt(next);
}
} | Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | 23a14285ef566447e75ac7f23a979680 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class SerejaAndArray {
public static void main(String... args) throws IOException{
MyScanner sc = new MyScanner();
int n = sc.nextInt();
int m = sc.nextInt();
long add = 0;
long[] tab = new long[n];
long[] bakTab = new long[n];
for (int i=0;i<n; i++){
tab[i] = sc.nextInt();
}
for (int i=0;i<m;i++){
int choice = sc.nextInt();
switch (choice){
case 1:
int vi = sc.nextInt()-1;
int val = sc.nextInt();
tab[vi] = val;
bakTab[vi] = add;
break;
case 2:
int yi = sc.nextInt();
add += yi;
break;
case 3:
int qi = sc.nextInt()-1;
System.out.println(tab[qi]+add-bakTab[qi]);
break;
}
}
}
}
class MyScanner{
BufferedReader br;
StringTokenizer st;
public MyScanner(){
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() throws IOException{
if (st == null || !st.hasMoreTokens()){
String line = br.readLine();
st = new StringTokenizer(line);
}
return st.nextToken();
}
public int nextInt() throws IOException{
String next = next();
return Integer.parseInt(next);
}
} | Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | f90f48a47c82c27144361c43267474e6 | train_000.jsonl | 1370619000 | Sereja has got an array, consisting of n integers, a1,βa2,β...,βan. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make vi-th array element equal to xi. In other words, perform the assignment aviβ=βxi. Increase each array element by yi. In other words, perform n assignments aiβ=βaiβ+βyi (1ββ€βiββ€βn). Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations. | 256 megabytes | import java.util.*;
import java.io.*;
import java.awt.Point;
import java.math.BigDecimal;
import java.math.BigInteger;
import static java.lang.Math.*;
// Solution is at the bottom of code
public class B implements Runnable{
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
BufferedReader in;
OutputWriter out;
StringTokenizer tok = new StringTokenizer("");
public static void main(String[] args){
new Thread(null, new B(), "", 128 * (1L << 20)).start();
}
/////////////////////////////////////////////////////////////////////
void init() throws FileNotFoundException{
Locale.setDefault(Locale.US);
if (ONLINE_JUDGE){
in = new BufferedReader(new InputStreamReader(System.in));
out = new OutputWriter(System.out);
}else{
in = new BufferedReader(new FileReader("input.txt"));
out = new OutputWriter("output.txt");
}
}
////////////////////////////////////////////////////////////////
long timeBegin, timeEnd;
void time(){
timeEnd = System.currentTimeMillis();
System.err.println("Time = " + (timeEnd - timeBegin));
}
void debug(Object... objects){
if (ONLINE_JUDGE){
for (Object o: objects){
System.err.println(o.toString());
}
}
}
/////////////////////////////////////////////////////////////////////
public void run(){
try{
timeBegin = System.currentTimeMillis();
Locale.setDefault(Locale.US);
init();
solve();
out.close();
time();
}catch (Exception e){
e.printStackTrace(System.err);
System.exit(-1);
}
}
/////////////////////////////////////////////////////////////////////
String delim = " ";
String readString() throws IOException{
while(!tok.hasMoreTokens()){
try{
tok = new StringTokenizer(in.readLine());
}catch (Exception e){
return null;
}
}
return tok.nextToken(delim);
}
String readLine() throws IOException{
return in.readLine();
}
/////////////////////////////////////////////////////////////////
final char NOT_A_SYMBOL = '\0';
char readChar() throws IOException{
int intValue = in.read();
if (intValue == -1){
return NOT_A_SYMBOL;
}
return (char) intValue;
}
char[] readCharArray() throws IOException{
return readLine().toCharArray();
}
/////////////////////////////////////////////////////////////////
int readInt() throws IOException{
return Integer.parseInt(readString());
}
int[] readIntArray(int size) throws IOException{
int[] array = new int[size];
for (int index = 0; index < size; ++index){
array[index] = readInt();
}
return array;
}
///////////////////////////////////////////////////////////////////
long readLong() throws IOException{
return Long.parseLong(readString());
}
long[] readLongArray(int size) throws IOException{
long[] array = new long[size];
for (int index = 0; index < size; ++index){
array[index] = readLong();
}
return array;
}
////////////////////////////////////////////////////////////////////
double readDouble() throws IOException{
return Double.parseDouble(readString());
}
double[] readDoubleArray(int size) throws IOException{
double[] array = new double[size];
for (int index = 0; index < size; ++index){
array[index] = readDouble();
}
return array;
}
////////////////////////////////////////////////////////////////////
BigInteger readBigInteger() throws IOException {
return new BigInteger(readString());
}
BigDecimal readBigDecimal() throws IOException {
return new BigDecimal(readString());
}
/////////////////////////////////////////////////////////////////////
Point readPoint() throws IOException{
int x = readInt();
int y = readInt();
return new Point(x, y);
}
Point[] readPointArray(int size) throws IOException{
Point[] array = new Point[size];
for (int index = 0; index < size; ++index){
array[index] = readPoint();
}
return array;
}
/////////////////////////////////////////////////////////////////////
List<Integer>[] readGraph(int vertexNumber, int edgeNumber)
throws IOException{
@SuppressWarnings("unchecked")
List<Integer>[] graph = new List[vertexNumber];
for (int index = 0; index < vertexNumber; ++index){
graph[index] = new ArrayList<Integer>();
}
while (edgeNumber-- > 0){
int from = readInt() - 1;
int to = readInt() - 1;
graph[from].add(to);
graph[to].add(from);
}
return graph;
}
/////////////////////////////////////////////////////////////////////
static class IntIndexPair {
static Comparator<IntIndexPair> increaseComparator = new Comparator<B.IntIndexPair>() {
@Override
public int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) {
int value1 = indexPair1.value;
int value2 = indexPair2.value;
if (value1 != value2) return value1 - value2;
int index1 = indexPair1.index;
int index2 = indexPair2.index;
return index1 - index2;
}
};
static Comparator<IntIndexPair> decreaseComparator = new Comparator<B.IntIndexPair>() {
@Override
public int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) {
int value1 = indexPair1.value;
int value2 = indexPair2.value;
if (value1 != value2) return -(value1 - value2);
int index1 = indexPair1.index;
int index2 = indexPair2.index;
return index1 - index2;
}
};
int value, index;
public IntIndexPair(int value, int index) {
super();
this.value = value;
this.index = index;
}
}
IntIndexPair[] readIntIndexArray(int size) throws IOException {
IntIndexPair[] array = new IntIndexPair[size];
for (int index = 0; index < size; ++index) {
array[index] = new IntIndexPair(readInt(), index);
}
return array;
}
/////////////////////////////////////////////////////////////////////
static class OutputWriter extends PrintWriter{
final int DEFAULT_PRECISION = 12;
int precision;
String format, formatWithSpace;
{
precision = DEFAULT_PRECISION;
format = createFormat(precision);
formatWithSpace = format + " ";
}
public OutputWriter(OutputStream out) {
super(out);
}
public OutputWriter(String fileName) throws FileNotFoundException {
super(fileName);
}
public int getPrecision() {
return precision;
}
public void setPrecision(int precision) {
precision = max(0, precision);
this.precision = precision;
format = createFormat(precision);
formatWithSpace = format + " ";
}
private String createFormat(int precision){
return "%." + precision + "f";
}
@Override
public void print(double d){
printf(format, d);
}
public void printWithSpace(double d){
printf(formatWithSpace, d);
}
public void printAll(double...d){
for (int i = 0; i < d.length - 1; ++i){
printWithSpace(d[i]);
}
print(d[d.length - 1]);
}
@Override
public void println(double d){
printlnAll(d);
}
public void printlnAll(double... d){
printAll(d);
println();
}
}
/////////////////////////////////////////////////////////////////////
int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int[][] steps8 = {
{-1, 0}, {1, 0}, {0, -1}, {0, 1},
{-1, -1}, {1, 1}, {1, -1}, {-1, 1}
};
boolean check(int index, int lim){
return (0 <= index && index < lim);
}
/////////////////////////////////////////////////////////////////////
boolean checkBit(int mask, int bitNumber){
return (mask & (1 << bitNumber)) != 0;
}
/////////////////////////////////////////////////////////////////////
void solve() throws IOException {
int n = readInt();
int m = readInt();
int[] array = readIntArray(n);
List<Integer> answer = new ArrayList<Integer>();
int[] prefSums = new int[m+1];
int[] lastChanges = new int[n];
Arrays.fill(lastChanges, -1);
for (int i = 0; i < m; ++i) {
prefSums[i+1] = prefSums[i];
int type = readInt();
if (type == 1) {
int index = readInt() - 1;
int value = readInt();
array[index] = value;
lastChanges[index] = i;
}
if (type == 2) {
int addValue = readInt();
prefSums[i+1] += addValue;
}
if (type == 3) {
int index = readInt() - 1;
int value = array[index];
int lastChange = lastChanges[index];
int addValue = prefSums[i+1] - prefSums[lastChange + 1];
value += addValue;
answer.add(value);
}
}
for (int value: answer) {
out.println(value);
}
}
}
| Java | ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9"] | 1 second | ["2\n9\n11\n20\n30\n40\n39"] | null | Java 7 | standard input | [
"implementation"
] | 48f3ff32a11770f3b168d6e15c0df813 | The first line contains integers n, m (1ββ€βn,βmββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1ββ€βtiββ€β3) that represents the operation type. If tiβ=β1, then it is followed by two integers vi and xi, (1ββ€βviββ€βn,β1ββ€βxiββ€β109). If tiβ=β2, then it is followed by integer yi (1ββ€βyiββ€β104). And if tiβ=β3, then it is followed by integer qi (1ββ€βqiββ€βn). | 1,200 | For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input. | standard output | |
PASSED | 48458f373f4c66e96c3752b4fac8cac5 | train_000.jsonl | 1284735600 | There are n students living in the campus. Every morning all students wake up at the same time and go to wash. There are m rooms with wash basins. The i-th of these rooms contains ai wash basins. Every student independently select one the rooms with equal probability and goes to it. After all students selected their rooms, students in each room divide into queues by the number of wash basins so that the size of the largest queue is the least possible. Calculate the expected value of the size of the largest queue among all rooms. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Solve8 {
public static void main(String[] args) throws IOException {
PrintWriter pw = new PrintWriter(System.out);
new Solve8().solve(pw);
pw.flush();
pw.close();
}
public void solve(PrintWriter pw) throws IOException {
FastReader sc = new FastReader();
n = sc.nextInt();
m = sc.nextInt();
a = new int[m];
for (int i = 0; i < m; i++) {
a[i] = sc.nextInt();
}
_4dDP(m, n + 1, 2, n + 1);
pascalTriangle();
double s = 0;
p = Math.pow(m, n);
for (int i = 1; i <= n; i++) {
s += i * dp(0, n, 0, i);
}
pw.println(s);
}
int n, m;
int[] a;
double p;
double[][][][] dp;
public double dp(int i, int s, int f, int q) {
if (i == m) {
return s == 0 && f > 0 ? 1 / p : 0;
}
if (dp[i][s][f][q] != -1) {
return dp[i][s][f][q];
}
double y = 0;
for (int j = 0; s - j >= 0 && j <= a[i] * q; j++) {
int x = (j / a[i] == q ? 1 : 0) + (j / a[i] + 1 == q && j % a[i] > 0 ? 1 : 0);
y += pascalTriangle[s][j] * dp(i + 1, s - j, f | x, q);
}
return dp[i][s][f][q] = y;
}
long[][] pascalTriangle;
public void pascalTriangle() {
final int MAX = (int) 50;
pascalTriangle = new long[MAX + 1][];
for (int i = 0; i <= MAX; i++) {
pascalTriangle[i] = new long[i + 1];
pascalTriangle[i][0] = pascalTriangle[i][i] = 1;
for (int j = 1; j < i; j++) {
pascalTriangle[i][j] = pascalTriangle[i - 1][j - 1] + pascalTriangle[i - 1][j];
}
}
}
public void _4dDP(int n, int m, int k, int v) {
dp = new double[n][m][k][v];
for (double[][][] _3dArr : dp) {
for (double[][] _2dArr : _3dArr) {
for (double[] row : _2dArr) {
Arrays.fill(row, -1);
}
}
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
}
}
public String next() {
if (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
try {
return br.readLine();
} catch (Exception e) {
}
return null;
}
public boolean hasNext() throws IOException {
if (st != null && st.hasMoreTokens()) {
return true;
}
String s = br.readLine();
if (s == null || s.isEmpty()) {
return false;
}
st = new StringTokenizer(s);
return true;
}
}
}
| Java | ["1 1\n2", "2 2\n1 1", "2 3\n1 1 1", "7 5\n1 1 2 3 1"] | 2 seconds | ["1.00000000000000000000", "1.50000000000000000000", "1.33333333333333350000", "2.50216960000000070000"] | null | Java 11 | standard input | [
"dp",
"combinatorics",
"probabilities"
] | c2b3b577c2bcb3a2a8cb48700c637270 | The first line contains two positive integers n and m (1ββ€βn,βmββ€β50) β the amount of students and the amount of rooms. The second line contains m integers a1,βa2,β... ,βam (1ββ€βaiββ€β50). ai means the amount of wash basins in the i-th room. | 2,200 | Output single number: the expected value of the size of the largest queue. Your answer must have an absolute or relative error less than 10β-β9. | standard output | |
PASSED | a8313cf6e9bdac5250c2093bff13e0a4 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main {
public static void main(String[] args) throws Exception {
// your code goes here
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
if(i==j)
System.out.print(m+" ");
else System.out.print(0+" ");
System.out.println();
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 08f5a9735083b2c6562fffe15a879a25 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.io.*;
import java.util.*;
public class practice361a {
public static void main(String[] args) throws Exception {
// BufferedReader f = new BufferedReader(new FileReader (new File("sample.txt")));
// PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("sample.txt")));
// StringTokenizer st = new StringTokenizer(f.readLine());
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
StringTokenizer st = new StringTokenizer(f.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) {
out.print(k + " ");
} else {
out.print(0 + " ");
}
}
out.println();
}
out.close();
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | b770035b105e48827eac8dc859acc033 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int k=in.nextInt();
int arr[][]=new int[n][n];
;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==j)
arr[i][j]=k;
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | e13e65a4e42cf66a6b36dc8afb2b385e | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class oci2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[][] lista = new int[n][n];
for(int i = 0;i < n;i++){
for(int j = 0;j < n;j++){
lista[i][j]= 0;
}
lista[i][i] = k;
}
for(int i = 0;i < n;i++){
for(int j = 0;j < n;j++){
System.out.print(lista[i][j]+" ");
}
System.out.println();
}
}
}
// 1508013582764
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 1da05da89bb12603339d7927a27b16d4 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import org.w3c.dom.css.CSSUnknownRule;
import java.lang.reflect.Array;
import java.util.*;
public class geek {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n=s.nextInt();
int k=s.nextInt();
StringBuffer sb=new StringBuffer();
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j){
sb.append(k+" ");
}else{
sb.append("0 ");
}
}
sb.append("\n");
}
System.out.println(sb);
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | c02dbf3807920b89603f8ccaf078b3a9 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class jeje {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int k = scan.nextInt(); //suma
int[][] table = new int[n][n];
for(int i=0; i<n; i++){
table[i][i] = k;
}
for(int x =0; x<n; x++){
for(int y =0; y<n; y++){
if(table[x][y] != k){
table[x][y] = 0;
}
}
}
for(int s =0; s<n ; s++){
for(int h =0; h<n; h++){
System.out.print(table[s][h] + " ");
}
System.out.println();
}
}
}
// 1508014503168
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | e736de24ba97a326ab0f8353e02fa7f7 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
/**
*
* @author Krolos
*/
public class ALevkoAndTable {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner k=new Scanner(System.in);
int x=k.nextInt();
int y=k.nextInt();
int arr[][]=new int[x][x];
for (int i=0;i<x;i++){
for(int j=0;j<x;j++){
if(i==j){
arr[i][j]=y;
System.out.print(y+" ");
}
else{
arr[i][j]=0;
System.out.print(0+" ");
}
}
System.out.println("");
}
// TODO code application logic here
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 3d746115321854339a242b2bc8c312ca | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes |
import java.io.PrintWriter;
import java.util.Scanner;
public class LevkoAndTable {
static Scanner in = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
public static void main (String args[]){
int n = in.nextInt() , k = in.nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if(i == j)
out.print(k+" ");
else out.print("0 ");
}
out.println();
}
out.flush();
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 5c9216a1ec4a155e2b7e6e9373cf7c61 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Tahsin Rashad
*/
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);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
static class Task {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt();
int k = in.nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (j != n - 1) {
if (i == j) {
out.print(k + " ");
} else {
out.print(0 + " ");
}
} else {
if (i == j) {
out.print(k);
} else {
out.print(0);
}
}
}
out.println();
}
}
}
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 println() {
writer.println();
}
public void close() {
writer.close();
}
public void print(int i) {
writer.print(i);
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | b621a3000d177cf8b48090b74d52ce59 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes |
import java.util.HashMap;
import java.util.Scanner;
public class football {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int k = scn.nextInt();
int[][] mat = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) {
mat[i][j] = k;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(mat[i][j]+" ");
}
System.out.println();
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 980c81ca34914879f73c80116c3197d7 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes |
import java.io.IOException;
import java.util.Scanner;
public class Main{
public static Scanner input = new Scanner(System.in);
public static void main(String[] args)
throws IOException {
// BufferedReader buffer=new BufferedReader(new InputStreamReader(System.in));
// String str;
// while((str=buffer.readLine())!=null){
int n=input.nextInt();
int k=input.nextInt();
for(int i=0;i<n;i++){
for(int ii=0;ii<n;ii++){
if(i==ii){
System.out.print(k+" ");continue;}
System.out.print("0 ");
}
System.out.println();
}
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | e7825f56757d0d3e5192767bd394b063 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), k = sc.nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) {
System.out.print(k + " ");
} else {
System.out.print(0 + " ");
}
}
System.out.println();
}
sc.close();
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | c3f99f98f2f5c698ba916d9c9e3f6c55 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.*;import java.io.*;import java.math.*;
public class Main
{
public static void process()throws IOException
{
int n=ni();
int k=ni();
int[][]A=new int[n][n];
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
A[i][j]=k/n;
for(int i=0;i<n;i++)
{
int c=k%n;
int j=i;
while(c>0)
{
A[i][j%n]++;
c--;
j++;
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
p(A[i][j]+" ");
pn("");
}
}
static AnotherReader sc;
static PrintWriter out;
public static void main(String[]args)throws IOException
{
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
int t=1;
// t=ni();
while(t-->0) {process();}
out.flush();out.close();
}
static void pn(Object o){out.println(o);}
static void p(Object o){out.print(o);}
static void pni(Object o){out.println(o);out.flush();}
static int ni()throws IOException{return sc.nextInt();}
static long nl()throws IOException{return sc.nextLong();}
static double nd()throws IOException{return sc.nextDouble();}
static String nln()throws IOException{return sc.nextLine();}
static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static class AnotherReader{BufferedReader br; StringTokenizer st;
AnotherReader()throws FileNotFoundException{
br=new BufferedReader(new InputStreamReader(System.in));}
AnotherReader(int a)throws FileNotFoundException{
br = new BufferedReader(new FileReader("input.txt"));}
String next()throws IOException{
while (st == null || !st.hasMoreElements()) {try{
st = new StringTokenizer(br.readLine());}
catch (IOException e){ e.printStackTrace(); }}
return st.nextToken(); } int nextInt() throws IOException{
return Integer.parseInt(next());}
long nextLong() throws IOException
{return Long.parseLong(next());}
double nextDouble()throws IOException { return Double.parseDouble(next()); }
String nextLine() throws IOException{ String str = ""; try{
str = br.readLine();} catch (IOException e){
e.printStackTrace();} return str;}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | c5c9c188f2e73354561eddcb9ad1fc47 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int[] a=new int[n];
int[] b=new int[n];
a[0]=k;
for(int i=0;i<n;i++){
for(int l=0;l<n;l++){
b[l]=a[(l+i)%n];
System.out.print(b[l]+" ");
}
System.out.println();
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 9ca8987dffee885b28e1b7fdb760051e | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | /*
@Rohan
Basic Template
key->brahmastra
*/
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import java.lang.Math.*;
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);
Solver solver = new Solver();
solver.solve(1, in, out);
out.close();
}
static class Solver {
public void solve(int testNumber, InputReader sc, PrintWriter out) {
int n = sc.nextInt();
int k = sc.nextInt();
for(int i = 0;i < n; i++){
for(int j = 0; j < n; j++){
if(i == j)
out.print(k+" ");
else
out.print(0+" ");
}
out.println();
}
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.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);
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 9be7da7f0e3bee7bf3f739401e262487 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class J361A {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print((i == j ? k : 0) + " ");
}
System.out.println();
}
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 6309e671f66bcced72359f2cbc8c9aa5 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class J361A {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print((i == j ? k : 0) + " ");
}
System.out.println();
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | badde2694351465133e87612a012d6f9 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class threesixone {
public static void main (String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int table [][] = new int [n][n];
for (int i = 0; i < n; i ++) {
Arrays.fill(table [i], 0);
}
for (int i = 0; i < n; i++) {
table [i][i] = k;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(table [i][j] + " ");
}
System.out.println();
}
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | eac75de2d834165fbe1a4fcc78a991d4 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class LevkoandTable {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
if(i==j)
System.out.print(k+" ");
else
System.out.print("0 ");
}
System.out.println();
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 1dbdd8cbb948576c466efc3e31c17af5 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class CF361A {
public static void main(String[] args) {
FastReader input = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
int n = input.nextInt();
int k = input.nextInt();
int[][] matrix = new int[n+1][n+1];
if(n == k){
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++)
matrix[i][j] = 1;
}
}
else if(n > k){
ArrayList<Integer> list = new ArrayList<>();
int sum = 0;
for(int j = 1;j < n;j++){
matrix[1][j] = 1;
list.add(matrix[1][j]);
sum++;
}
matrix[1][n] = k - sum;
list.add(matrix[1][n]);
for(int i = 2;i <= n;i++){
int col = 1;
for(int j = i-1;j < list.size();j++){
matrix[i][col] = list.get(j);
col++;
}
for(int j = 0;j < (i-1);j++){
matrix[i][col] = list.get(j);
col++;
}
}
}
else if(n < k){
ArrayList<Integer> list = new ArrayList<>();
int sum = 0;
for(int j = 1;j < n;j++){
matrix[1][j] = 1;
list.add(matrix[1][j]);
sum++;
}
matrix[1][n] = k - sum;
list.add(matrix[1][n]);
for(int i = 2;i <= n;i++){
int col = 1;
for(int j = i-1;j < list.size();j++){
matrix[i][col] = list.get(j);
col++;
}
for(int j = 0;j < (i-1);j++){
matrix[i][col] = list.get(j);
col++;
}
}
}
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
pw.print(matrix[i][j] + " ");
}
pw.println();
}
// ****If sorting is required, use ArrayList
pw.flush();
pw.close();
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 51fb6983f9238d199941546bdf7ee7f1 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int k =sc.nextInt();
for (int i = 0; i <n ; i++) {
for (int j = 0; j <n ; j++) {
System.out.print(i==j?k+ " ":0+" ");
}
System.out.println();
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 47b00431709a326fbd0f43627576ca6a | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.io.*;
import java.util.*;
public class CF361A_LevkoAndTable {
private void solve() {
int n = readInt();
int k = readInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j)
out.print(k + " ");
else
out.print(0 + " ");
}
out.println();
}
}
public static void main(String[] args) {
new CF361A_LevkoAndTable().run();
}
private void run() {
try {
init();
solve();
out.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
private void init() throws IOException {
String filename = "";
if (filename.isEmpty()) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
} else {
in = new BufferedReader(new FileReader(filename + ".in"));
out = new PrintWriter(new FileWriter(filename + ".out"));
}
}
private String readString() {
while (!tok.hasMoreTokens()) {
try {
tok = new StringTokenizer(in.readLine());
} catch (Exception e) {
return null;
}
}
return tok.nextToken();
}
private int readInt() {
return Integer.parseInt(readString());
}
private long readLong() {
return Long.parseLong(readString());
}
private double readDouble() {
return Double.parseDouble(readString());
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 6d1341a61dd7b68af3cb12dc4756fead | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.io.*;
import java.util.*;
public class Table
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n, k;
n = Integer.parseInt(st.nextToken());
k = Integer.parseInt(st.nextToken());
int count = 0;
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
if(j == count) System.out.print(j < n-1? (k + " "): k);
else System.out.print(j < n-1? (0 + " "): 0);
}
System.out.println();
count++;
}
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 0f4506631f76afd824d536cdd01a8ae6 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class Levko_and_Table {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int k=in.nextInt();
int arr[][]=new int[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(j==i)arr[i][j]=k;
else arr[i][j]=0;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(arr[i][j]+" ");
}
System.out.println();;
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 5b8cad932837b6f84bc025c964f0f6d8 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.io.IOException;
import java.util.Scanner;
public class Solutions {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int p = k / n;
int r = k - p * (n-1);
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(i == j)
System.out.print(r+ " ");
else
System.out.print(p + " ");
}
System.out.println("");
}
sc.close();
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | e558eeedea2e1c7a594836a062e07b4b | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes |
import java.util.Scanner;
public class LevkoAndTable {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int n = sc.nextInt(), k = sc.nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if(i == j)
sb.append(k);
else
sb.append(0);
if(j != n - 1)
sb.append(" ");
}
sb.append("\n");
}
System.out.print(sb);
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | caf950c4ef2a575817b37a4b9edc64f9 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class solve {
public static void main(String args[]){
Scanner sc= new Scanner(System.in);
int n = sc.nextInt();
int arr[][] = new int[n][n];
int k =sc.nextInt();
int y= k ;
int t= 0 ;
for(int i = 0 ; i<n ; i ++)
{
for(int j=0 ;j<n;j++)
if(i==j)arr[i][j]=k;
}
for(int i =0 ; i<n ;i++){
for(int j= 0; j <arr[i].length ; j++)
System.out.print(arr[i][j]+" ");
System.out.println("");
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 1b02ed661f5526f9d2dc21475bc8dc19 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i == j){
System.out.print(k+" ");
}else{
System.out.print("0 ");
}
}
System.out.println();
}
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 542880d159fbf7dfc85b5e53e03a2856 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
import java.util.*;
import java.math.*;
public
class Solution{
public static void main(String[] args) throws Exception {
FastScanner cin = new FastScanner(System.in);
StringBuffer ans = new StringBuffer();
int n = cin.nextInt();
int k = cin.nextInt();
int arr[][] = new int[n][n];
for(int i=0;i<n;i++)
{
arr[i][i] = k;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
static class FastScanner {
private BufferedReader reader = null;
private StringTokenizer tokenizer = null;
public FastScanner(InputStream in) {
reader = new BufferedReader(new InputStreamReader(in));
tokenizer = null;
}
public String next() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public String nextLine() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken("\n");
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 69a7418f3ca8449af3e25c390b6ce20c | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class LevkoAndTable {
public static void main(String[] args) {
// TODO code application logic here
Scanner in = new Scanner(System.in);
int s,c;
c = in.nextInt();
s = in.nextInt();
int[][] dim = new int[c][c];
int co = 0;
if ((s - c + 1) >= 0) {
for (int i = 0; i < c; i++) {
for (int j = 0; j < c; j++) {
if (j == co && i == co) {
dim[i][j] = s - c + 1;
co = co + 1;
}else{
dim[i][j] = 1;
}
}
}
}else{
for (int i = 0; i < c; i++) {
for (int j = 0; j < c; j++) {
if (j == co && i == co) {
dim[i][j] = s;
co = co + 1;
}else{
dim[i][j] = 0;
}
}
}
}
for (int i = 0; i < c; i++) {
for (int j = 0; j < c; j++) {
System.out.print(dim[i][j]+" ");
if (j == (c - 1)) {
System.out.println("");
}
}
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 413a72be4aff5668929fb3675244a35c | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class JavaApplication1
{
public static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
int n,k;
n = in.nextInt();
k = in.nextInt();
int a[][] = new int[n][n];
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
if(i==j) a[i][j]=k;
else a[i][j]=0;
}
}
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 348c6fa9c20cf3d1ea40c15fc26beeaa | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class table {
public static void main(String[] args) {
Scanner scanner = new Scanner (System.in);
int n = scanner.nextInt();
int k = scanner.nextInt();
int x = k/n,m=k%n;
int [][] a;a=new int [n][n];
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
a[i][j]=x;
}
}
for (int j=0;j<n;j++) {
a[j][j]+=m;
}
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
System.out.print(a[i][j] + " ");
}
System.out.println("");
}
scanner.close();
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 3228cbdea0beaddce272c175a75c7ad1 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | //package round210;
import java.util.Scanner;
public class Table {
public static void main(String[] args) {
Scanner leer=new Scanner(System.in);
int n= leer.nextInt();
int k=leer.nextInt();
int mat[][]=new int[n][n];
int res[]=new int[n];
int suma=0;
int auxk=k;
for (int i = 0; i < res.length; i++) {
if(suma<auxk){
if(k<2)
res[i]=1;
else{
res[i]=k/2;
k-=k/2;
}
suma+=res[i];
}
else
res[i]=0;
}
while (suma<auxk) {
res[0]+=1;
suma++;
}
for (int i = 0; i < mat.length; i++) {
for (int j = 0; j < mat[0].length; j++) {
mat[i][j]=res[j];
System.out.print(mat[i][j]+" ");
}
int aux=res[0];
for (int j = 0; j < res.length-1; j++) {
res[j]=res[j+1];
}
res[res.length-1]=aux;
System.out.println();
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 6895887ea7e8ff8d0534a8d514550c48 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author a.bogdanov
*/
public class LevkoTable {
public static void main(String[] args) throws IOException {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(System.in));
String[] str = reader.readLine().split(" ");
int n = Integer.parseInt(str[0]);
int k = Integer.parseInt(str[1]);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j) System.out.print(k + " ");
else System.out.print("0 ");
}
System.out.println();
}
} finally {
if (reader != null) {
reader.close();
}
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | b0070ac73d2e68d079c0d037062356f5 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.io.*;
import java.util.*;
public class LevkoAndTable
{
public static void main(String[] args) throws IOException
{
Scanner input = new Scanner(System.in);
//Scanner input = new Scanner(new File("Sample Input.txt"));
StringBuilder output = new StringBuilder();
int rep;
int n = input.nextInt();
int k = input.nextInt();
if ( n > k)
{
rep = k;
}
else
{
rep = (k - n) + 1;
}
int[][] array = new int[n][n];
if ( n <= k)
Arrays.fill(array[0], 1);
else
Arrays.fill(array[0], 0);
array[0][0]=rep;
int temp;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
output.append(array[i][j]).append(" ");
}
output.append("\n");
if ( i+1 < n)
{
array[i+1] = array[i];
temp = array[i+1][i+1];
array[i+1][i+1] = array[i+1][i];
array[i+1][i] = temp;
}
}
System.out.print(output);
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 4911d073bc40942ae2ad5068603d89b4 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class T361A {
public void solve(int n, int k) {
StringBuffer[] ans = new StringBuffer[n];
for (int i = 0; i < n; i ++) {
ans[i] = new StringBuffer("");
for (int j = 0; j < n; j ++) {
if (i == j) {
ans[i].append(k + " ");
} else {
ans[i].append(0 + " ");
}
}
}
for (int i = 0; i < n; i ++) {
System.out.println(ans[i].toString().trim());
}
}
public static void main(String[] args) {
FastScanner in = new FastScanner();
new T361A().solve(in.nextInt(), in.nextInt());
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | d6fd25ddc8161bf811ce57114ba72d4d | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Brackets {
/**
* @param args
*/
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
int count = 0;
while (console.hasNext()) {
int n = console.nextInt();
int k = console.nextInt();
int fill = k -n +1;
for(int i=0;i< n;i++)
{
for (int j = 0; j < n; j++) {
if(i==j)
{
System.out.print(fill+ " ");
}
else
{
System.out.print(1+ " ");
}
}
System.out.println();
}
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 75ceb927e7d7d5a32c747a3b77785070 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes |
import java.io.PrintStream;
import java.util.Scanner;
/**
* Created with IntelliJ IDEA.
* User: ekrylov
* Date: 11/10/13
* Time: 8:59 PM
* To change this template use File | Settings | File Templates.
*/
public class A {
public static void main(String[] arg) {
new A().solve();
}
private void solve() {
Scanner in = new Scanner(System.in);
PrintStream out = System.out;
int n = in.nextInt();
int k = in.nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) {
out.print(k + " ");
} else {
out.print("0 ");
}
}
out.println();
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 562f0d60ce4a0e02598d9ef8dbec3fc1 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | /*
http://codeforces.com/problemset/problem/361/A
Levko and table
*/
import java.util.*;
import java.io.*;
public class Main {
static BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
// sum (the sum of numbers in each row and each column)
static int N;
// dimension (number of tables on each column and row)
static int K;
public static void main(String[] args){
getInput();
printOutput();
}
// get input
// set N and K
static void getInput(){
Scanner in = new Scanner(System.in);
N = in.nextInt();
K = in.nextInt();
}
// print result
static void printOutput(){
for (int r = 0; r < N; r++){
for (int c = 0; c < N; c++){
if (r == c){
System.out.print(K);
} else {
System.out.print(0);
}
if (c + 1 < N){
System.out.print(" ");
}
}
System.out.println("");
}
}
static String getLine(){
try {
return reader.readLine();
} catch (Exception e){
}
return null;
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | c527a3a93f4b9664e9e74adabf7dd472 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.*;
public class test{
public static void main(String args[]){
Scanner cin=new Scanner (System.in);
while (cin.hasNextInt()){
int n=cin.nextInt();
int k=cin.nextInt();
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){
if (i==j){System.out.print(k+" ");
}else{
System.out.print(0+" ");
}
}
System.out.println();
}
}
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 471d0bb1753dc2b201b03f2924398be6 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class LevkoandTable {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// while (scanner.hasNext()) {
int n = scanner.nextInt();
int k = scanner.nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if(i == j)
if(j != n-1)
System.out.print(k + " ");
else
System.out.print(k);
else
if(j!=n-1)
System.out.print(0 + " ");
else
System.out.print(0 );
}
if(i != n-1)
System.out.println();
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 49de7729b68223424742947dccecc2d0 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class Main{
public static void main (String[] args){
Scanner numeros=new Scanner(System.in);
int a=numeros.nextInt();
int b=numeros.nextInt();
int num1;
int num2;
int ver=0;
if(b%2==0)
{
num1=b/2;
num2=b/2;
}
else
{
num1=b/2;
num2=(b/2)+1;
}
String jaja=b+"";
String colocar=num1+""+" "+num2+"";
String colocarRes=num2+""+" "+num1+"";
String fila="";
String rellenador="";
String cero="0";
int t=0;
int i=0;
int u=a-2;
if(a==1)
{
System.out.println(b);
}
else if(a%2==0)
{
while(i<a/2)
{
for(int e=0;e<t;e++)
{
fila=fila+"0"+" ";
}
for(int o=0;o<u;o++)
{
rellenador=rellenador+"0"+" ";
}
System.out.print(fila+colocar+" "+rellenador);
System.out.println("");
System.out.print(fila+colocarRes+" "+rellenador);
System.out.println("");
fila="";
rellenador="";
u=u-2;
t=t+2;
i++;
}
}
else if(a%2!=0)
{
while(i<a/2)
{
for(int e=0;e<t;e++)
{
fila=fila+cero+" ";
}
for(int o=0;o<u;o++)
{
rellenador=rellenador+"0"+" ";
}
System.out.print(fila+colocar+" "+rellenador);
System.out.println("");
System.out.print(fila+colocarRes+" "+rellenador);
System.out.println("");
rellenador="";
u=u-2;
if(i+1==a/2)
{
System.out.print(fila+"0 0"+" "+jaja);
}
fila="";
t=t+2;
i++;
}
}
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 7e5477649c9af3535bb814e62495b76c | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class LevkoTable {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
int n = input.nextInt(), K = input.nextInt();
int q = K / n, r = K % n;
int[] row = new int[n]; Arrays.fill(row, q);
for(int i=0;i<r;i++)
row[i]++;
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
System.out.print(row[(i+j)%n]);
System.out.print(j+1==n ? "\n" : " ");
}
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 7696c207166672153b43c9fd07232f7d | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class Main{
// public static void Print(Object... O) {
// System.out.println(Arrays.deepToString(O).replaceAll("],", "]\n"));
// }
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int[][] table = new int[n][n];
int[] rd = new int[n];
int cou = 1;
for (int i = 0; i < rd.length; i++) {
if (i != rd.length - 1) {
if (cou < k) {
k = k - cou;
rd[i] = cou;
cou++;
} else {
rd[i] = 0;
}
} else {
rd[i] = k;
}
}
// Print(rd);
cou = 0;
for (int i = 0; i < n; i++) {
cou = i;
for (int j = 0; j < n; j++) {
if (cou == n) {
cou = 0;
}
table[i][j] = rd[cou];
cou++;
}
}
for (int i = 0; i < table.length; i++) {
for (int j = 0; j < table.length; j++) {
System.out.print(table[i][j] + " ");
}
System.out.println("");
}
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 6442b4e0ffc82795b638b5aa4132d4f7 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class LevkoandTable {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
int k = reader.nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if(i == j) {
System.out.print(k);
} else {
System.out.print('0');
}
if(j < n - 1) {
System.out.print(' ');
} else {
System.out.println();
}
}
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | ef28a19815c1b01c94482a8cf7da7ca2 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
/*
br = new BufferedReader(new FileReader("input.txt"));
pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
*/
public class Main {
private static BufferedReader br;
private static StringTokenizer st;
private static PrintWriter pw;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
//int qq = 1;
int qq = Integer.MAX_VALUE;
//int qq = readInt();
for(int casenum = 1; casenum <= qq; casenum++) {
int n = readInt();
int k = readInt();
for(int i = 0; i < n; i++) {
StringBuilder sb = new StringBuilder();
for(int j = 0; j < n; j++) {
if(i == j) {
sb.append(k + " ");
}
else {
sb.append("0 ");
}
}
pw.println(sb.toString().trim());
}
}
pw.close();
}
private static void exitImmediately() {
pw.close();
System.exit(0);
}
private static long readLong() throws IOException {
return Long.parseLong(nextToken());
}
private static double readDouble() throws IOException {
return Double.parseDouble(nextToken());
}
private static int readInt() throws IOException {
return Integer.parseInt(nextToken());
}
private static String nextToken() throws IOException {
while(st == null || !st.hasMoreTokens()) {
if(!br.ready()) {
exitImmediately();
}
st = new StringTokenizer(br.readLine().trim());
}
return st.nextToken();
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 8fd8a7ef6a05cea424a432dfb20efe3c | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[][] mat = new int[n][n];
int diag = k;
for (int i = 0; i < n; i++) {
for (int j = 0 ; j < n; j++) {
if (i == j)
System.out.print(k);
else System.out.print("0");
if (j < n - 1) System.out.print(" ");
}
System.out.println();
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | bb9470948c8592635ee011dc61d8f429 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class p1_210 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) {
if (j != n - 1)
System.out.print(k + " ");
else
System.out.print(k);
} else {
if (j != n - 1)
System.out.print(0 + " ");
else
System.out.print(0);
}
}
System.out.println();
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 386dcd6d2260a3d8c6f829624a32c17b | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.StringTokenizer;
/**
*
* @author baha
*/
public class Main {
static Scanner in;
static Output out;
public static void main(String[] args) throws Exception {
boolean isFile = false;
String filenameIn = null;
String filenameOut = null;
if (isFile) {
in = new Scanner(filenameIn);
out = new Output(new File(filenameOut));
} else {
in = new Scanner();
out = new Output(System.out);
}
int n = in.nextInt();
int k = in.nextInt();
int position = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (j == position) {
System.out.print(k + " ");
} else {
System.out.print(0 + " ");
}
}
System.out.println("");
position++;
}
}
private static class Scanner {
StringTokenizer st = null;
BufferedReader in;
public Scanner() {
in = new BufferedReader(new InputStreamReader(System.in));
}
public Scanner(String fileName) throws FileNotFoundException {
in = new BufferedReader(new FileReader(fileName));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
public String nextLine() throws IOException {
return in.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
}
private static class Output extends PrintStream {
public Output(OutputStream out) {
super(out);
}
public Output(File file) throws FileNotFoundException {
super(file);
}
}
private static void create(String... files) {
for (String file : files) {
if (!new File(file).exists()) {
try {
new File(file).createNewFile();
} catch (IOException ex) {
ex.printStackTrace();
}
};
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | b592a0c7515667835ded926db2b652fa | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main implements Runnable {
private void solve() throws IOException {
int n = nextInt();
int k = nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) {
out.print(k + " ");
} else {
out.print(0 + " ");
}
}
out.println();
}
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
String next() throws IOException {
while (!st.hasMoreTokens()) {
String line = in.readLine();
if (line == null)
return null;
eat(line);
}
return st.nextToken();
}
public static void main(String[] args) {
new Thread(null, new Main(), "Main", 1 << 28).start();
}
private BufferedReader in;
private PrintWriter out;
private StringTokenizer st;
@Override
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
eat("");
solve();
in.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(566);
}
}
private void eat(String s) {
st = new StringTokenizer(s);
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 7c97896fef9a417abe18c10191597e35 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class Table {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(j == i)
System.out.print(k + " ");
else System.out.print(0 + " ");
}
System.out.println();
}
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 42e95e1064d53e239126b11a5e309775 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import static java.lang.Math.*;
import java.math.BigDecimal;
import java.util.Locale;
/**
*
* @author ΡΠ°Π½Ρ
*/
public class Timus {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
A jk =new A();
}
}
class A{
Scanner in = new Scanner(System.in);
PrintWriter out= new PrintWriter(System.out);
int n=in.nextInt();
int k=in.nextInt();
public A(){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j){
out.print(k+" ");
}
else{
out.print(0+" ");
}
}
out.println();
}
out.flush();
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | f2df5b340507583e52c8403ccd99cbc4 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.Scanner;
public class LevkTable {
Scanner in =new Scanner(System.in);
public static void main(String args[]){
new LevkTable().go();
}
public void go(){
int n=in.nextInt();
int k=in.nextInt();
int common = k/n;
int last = common + k%n;
for(int i=0;i<n;i++){
int index =n-1-i;
for(int j=0;j<n;j++){
char end = j==n-1?'\n': ' ';
if(j!=index)
System.out.print(common+""+ end);
else
System.out.print(last+""+end);
}
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 08b1b37f16ae570e40920f34679d581b | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | //package a;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String... args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
short n = scanner.nextShort();
short k = scanner.nextShort();
printTable(n, k);
}
scanner.close();
}
private static void printTable(final short n, final short k) {
short[] sumands = splitToSummands(n, k);
for (int i = 0; i < n; i++) {
printlnSumands(sumands);
rotateSumands(sumands);
}
}
private static void printlnSumands(short[] summands) {
String prefix = "";
for (int i = 0; i < summands.length; i++) {
System.out.print(prefix);
System.out.print(summands[i]);
prefix = " ";
}
System.out.println();
}
private static void rotateSumands(short[] summands) {
short buffer = summands[0];
int n = summands.length;
for (int i = 0; i < n - 1; i++) {
summands[i] = summands[i + 1];
}
summands[Math.max(0, n - 1)] = buffer;
}
private static short[] splitToSummands(final short n, final short k) {
short[] result = new short[n];
if (n >= k) {
Arrays.fill(result, 0, k, (short) 1);
} else {
final short factor = (short) Math.ceil(k / (double) n);
int i = 0;
short remainder = k;
for (; i < n && remainder > 0; i++) {
result[i] = factor;
remainder -= factor;
}
if (remainder <= 0) {
result[i - 1] += remainder;
}
}
return result;
}
private static <T> void println(T v) {
System.out.println(v);
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 090b953cf9aaf38e3698e51af773ec91 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
* Created by 875k on 12/27/13.
*/
public class CF210B {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tok = new StringTokenizer(br.readLine());
int n = Integer.parseInt(tok.nextToken());
int k = Integer.parseInt(tok.nextToken());
int[][] arr = new int[n][n];
for(int i = 0; i < n; i++) {
int sum = 0;
for(int j = 0; j < i; j++) {
sum += arr[i][j];
}
int[] nums = generate(k - sum, n - i);
for(int j = i; j < n; j++) {
arr[i][j] = nums[j - i];
}
for(int j = i; j < n; j++) {
arr[j][i] = nums[j - i];
}
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
public static int[] generate(int k, int m) {
int[] ans = new int[m];
int div = k / m;
for(int i = 0; i < m; i++) {
ans[i] = div;
}
int mod = k % m;
for(int i = 0; i < mod; i++) {
ans[i]++;
}
return ans;
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | bb9ccc7c626ca2407cdea1d92e7c488a | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class A {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
String[] arS = br.readLine().split(" ");
int n = Integer.parseInt(arS[0]);
int k = Integer.parseInt(arS[1]);
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i==j)
pw.print( k + " ");
else
pw.print("0 ");
}
pw.println();
}
pw.flush();
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | b7dff1f80a92f196144e1c1f9d72c80b | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.io.*;
import java.util.*;
public class A210 {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
for (int i = 0; i < n; i++) {
StringBuilder sb = new StringBuilder();
for (int j = 0; j < n; j++) {
if (j > 0) sb.append(" ");
if (i == j) sb.append(k);
else sb.append(0);
}
System.out.println(sb);
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 170d80b600d4f9c0c94a579e90fea276 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.*;
public class aa {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int n = input.nextInt(), k = input.nextInt();
for(int i = 0; i<n; i++)
{
for(int j = 0; j<n; j++)
{
System.out.print((i==j ? k : 0) + " ");
}
System.out.println();
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 805ca46fb27eda3c6521e7e2ca8af94b | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.StringTokenizer;
public class ProblemA {
InputReader in;
PrintWriter out;
private void runIO() throws IOException {
// in = new InputReader(new File("file.in"));
// out = new PrintWriter(new File("file.out"));
in = new InputReader(System.in);
out = new PrintWriter(System.out);
}
private void closeIO() {
out.close();
}
class InputReader {
BufferedReader bf;
StringTokenizer st;
InputReader(File f) throws FileNotFoundException {
bf = new BufferedReader(new FileReader(f));
}
InputReader(InputStream s) {
bf = new BufferedReader(new InputStreamReader(s));
}
private String next() throws IOException {
while (st == null || !st.hasMoreElements()) {
String s;
try {
s = bf.readLine();
} catch (IOException e) {
return null;
}
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
private int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(next());
}
private long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(next());
}
private double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(next());
}
}
public static void main(String[] S) throws IOException {
// long startTime = System.currentTimeMillis();
Locale.setDefault(Locale.US);
new ProblemA().run();
// System.out.println("Time used: "+(System.currentTimeMillis()-startTime)+" ms.");
}
private void run() throws IOException {
runIO();
solve();
closeIO();
}
private void solve() throws IOException {
int N = in.nextInt();
int K = in.nextInt();
for (int i = 0;i<N;i++){
for (int j = 0;j<N;j++){
if (j==i) out.print(K+" ");
else out.print(0+" ");
}
out.println();
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | b231e9d441ab86e4bfd2c7f3c37b27be | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes | import java.util.*;
public class MainClass {public static void main(String[] args) throws Exception {
//codeforces 361A
Scanner input=new Scanner(System.in);
int n=1;
n=input.nextInt();
int k=input.nextInt();
int[][] arr = new int[n][n];
for( int i= 0; i<n; i++){
for(int j =0; j<n; j++){
if(i==j)
arr[i][j]=k;
else
arr[i][j]=0;
}
}
for(int l = 0; l<n; l++){
for(int h =0; h<n; h++){
System.out.print(arr[l][h]);
if(h!=(n-1))
System.out.print(" ");
}
System.out.print("\n");
}
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 3c0df22a973ab3f21e1e65c38451db44 | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 256 megabytes |
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author geek_guY
*/
public class NewClass9 {
public static void main(String args[]) throws IOException, Exception {
inputx41 in = new inputx41(System.in);
int N = in.nextInt();
int K = in.nextInt();
for(int x=0;x<N;x++)
{
for(int y=0;y<N;y++)
{
if(x==y)
{
if(y==N)
System.out.print(K);
else
System.out.print(K+" ");
}
else
{
if(y==N)
System.out.print(0);
else
System.out.print(0+" ");
}
}
System.out.println("");
}
}
}
class inputx41 {
final private int BUFFER_SIZE = 1 << 17;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public inputx41(InputStream in) {
din = new DataInputStream(in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String nextString() throws Exception {
StringBuffer sb = new StringBuffer("");
byte c = read();
while (c <= ' ') {
c = read();
}
do {
sb.append((char) c);
c = read();
} while (c > ' ');
return sb.toString();
}
public char nextChar() throws Exception {
byte c = read();
while (c <= ' ') {
c = read();
}
return (char) c;
}
public int nextInt() throws Exception {
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = c == '-';
if (neg) {
c = read();
}
do {
ret = ret * 10 + c - '0';
c = read();
} while (c > ' ');
if (neg) {
return -ret;
}
return ret;
}
public long nextLong() throws Exception {
long ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = c == '-';
if (neg) {
c = read();
}
do {
ret = ret * 10 + c - '0';
c = read();
} while (c > ' ');
if (neg) {
return -ret;
}
return ret;
}
private void fillBuffer() throws Exception {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) {
buffer[0] = -1;
}
}
private byte read() throws Exception {
if (bufferPointer == bytesRead) {
fillBuffer();
}
return buffer[bufferPointer++];
}
}
| Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | 6db5916cfca1d32249cb698f8d5e46eb | train_000.jsonl | 1384102800 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | 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.*;
public class A implements Runnable {
private void solve() throws IOException {
int n = nextInt();
int k = nextInt();
int rem = k - (n - 1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) System.out.print(rem + " ");
else System.out.print(1 + " ");
}
System.out.println();
}
}
public static void main(String[] args) {
new A().run();
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter writer;
public void run() {
try {
reader = new BufferedReader(new BufferedReader(
new InputStreamReader(System.in)));
writer = new PrintWriter(System.out);
tokenizer = null;
solve();
reader.close();
writer.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
BigInteger nextBigInteger() throws IOException {
return new BigInteger(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
void p(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
void pl(Object... objects) {
p(objects);
writer.println();
}
int cc;
void pf() {
writer.printf("Case #%d: ", ++cc);
}
} | Java | ["2 4", "4 7"] | 1 second | ["1 3\n3 1", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2"] | NoteIn the first sample the sum in the first row is 1β+β3β=β4, in the second row β 3β+β1β=β4, in the first column β 1β+β3β=β4 and in the second column β 3β+β1β=β4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | Java 6 | standard input | [
"constructive algorithms",
"implementation"
] | e80088bee9c0df6adf280f8ffbeaa4a9 | The single line contains two integers, n and k (1ββ€βnββ€β100, 1ββ€βkββ€β1000). | 800 | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. | standard output | |
PASSED | e821b2ae04c37121e0ea3fa376d5b8b4 | train_000.jsonl | 1426610700 | Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.Help him do this! | 256 megabytes | /**
* Created by Anna on 18.03.2015.
*/
/**
* Created by Anna on 08.03.2014.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;
public class TaskB {
StringTokenizer st;
BufferedReader in;
PrintWriter out;
public static void main(String[] args) throws NumberFormatException,
IOException {
TaskB solver = new TaskB();
solver.open();
solver.solve();
solver.close();
}
public void open() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
//in = new BufferedReader(new FileReader("input.txt"));
//out = new PrintWriter(new FileWriter("output.txt"));
}
public String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String line = in.readLine();
if (line == null)
return null;
st = new StringTokenizer(line);
}
return st.nextToken();
}
public int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(nextToken());
}
public long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(nextToken());
}
public double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(nextToken());
}
boolean hasMoreTokens() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String line = in.readLine();
if (line == null)
return false;
st = new StringTokenizer(line);
}
return true;
}
public void solve() throws NumberFormatException, IOException {
int n = nextInt();
char[] first = nextToken().toCharArray();
char[] second = nextToken().toCharArray();
int answ = 0;
int[][] pairs = new int[26][26];
for (int i = 0; i < 26; i++) {
for (int j = 0; j < 26; j++) {
pairs[i][j] = -1;
}
}
for (int i = 0; i < n; i++) {
if (first[i] == second[i]) continue;
answ++;
pairs[first[i] - 'a'][second[i] - 'a'] = i;
}
for (int i = 0; i < 26; i++) {
for (int j = 0; j < 26; j++) {
if (pairs[i][j] >= 0 && pairs[j][i] >= 0) {
out.println(answ - 2);
out.println((pairs[i][j] + 1) + " " + (pairs[j][i] + 1));
return;
}
}
}
for (int i = 0; i < 26; i++) {
for (int j = 0; j < 26; j++) {
if (pairs[i][j] >= 0) {
for (int k = 0; k < 26; k++) {
if (pairs[j][k] >= 0) {
out.println(answ - 1);
out.println((pairs[i][j] + 1) + " " + (pairs[j][k] + 1));
return;
}
}
}
}
}
out.println(answ);
out.println("-1 -1");
}
public void close() {
out.flush();
out.close();
}
} | Java | ["9\npergament\npermanent", "6\nwookie\ncookie", "4\npetr\negor", "6\ndouble\nbundle"] | 2 seconds | ["1\n4 6", "1\n-1 -1", "2\n1 2", "2\n4 1"] | NoteIn the second test it is acceptable to print iβ=β2, jβ=β3. | Java 7 | standard input | [
"greedy"
] | 2fa543c8b8f9dc500c36cf719800a6b0 | The first line contains integer n (1ββ€βnββ€β200β000) β the length of strings S and T. The second line contains string S. The third line contains string T. Each of the lines only contains lowercase Latin letters. | 1,500 | In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S. In the second line, either print the indexes i and j (1ββ€βi,βjββ€βn, iββ βj), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters. If there are multiple possible answers, print any of them. | standard output | |
PASSED | 9e43f69141a553ce4089fcc28df85b26 | train_000.jsonl | 1426610700 | Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.Help him do this! | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.StringTokenizer;
public class B {
/**
* @param args
*/
public static void main(String[] args)throws Exception{
in();
String s=str();
String t=str();
int d=0;
HashMap<Character,HashMap<Character,Integer>>s1=new HashMap<>();
LinkedList<pair>l=new LinkedList<>();
for (int i=0;i<s.length();i++){
if (s.charAt(i)!=t.charAt(i)){
d++;
HashMap<Character, Integer>m1=s1.get(s.charAt(i));
if (m1==null){
m1=new HashMap<>();
m1.put(t.charAt(i), i);
s1.put(s.charAt(i),m1);
}
else m1.put(t.charAt(i),i);
l.addLast(new pair(t.charAt(i),i));
}
}
int df=0;
int ll=0;
int rr=0;
for (pair pr : l){
if (s1.containsKey(pr.c)){
HashMap<Character, Integer>m1=s1.get(pr.c);
if (m1.containsKey(s.charAt(pr.p))){
int p1=m1.get(s.charAt(pr.p));
int p2=pr.p;
System.out.println(d-2);
System.out.println(p2+1+" "+(p1+1));
return;
}
else{
int p1=0;
for (Map.Entry<Character,Integer>tt:m1.entrySet()){
p1=tt.getValue();
break;
}
ll=pr.p;
rr=p1;
df=1;
}
}
}
if (df==1){
System.out.println(d-1);
System.out.println(ll+1+" "+(rr+1));
}
else
System.out.println(d+"\n"+-1+" "+-1);
}
static BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static int in() throws IOException{
if (st==null || !st.hasMoreTokens()){
st=new StringTokenizer(buf.readLine());
}
return Integer.parseInt(st.nextToken());
}
static long ll() throws IOException{
if (st==null || !st.hasMoreTokens()){
st=new StringTokenizer(buf.readLine());
}
return Long.parseLong(st.nextToken());
}
static String str() throws IOException{
if (st==null || !st.hasMoreTokens()){
st=new StringTokenizer(buf.readLine());
}
return (st.nextToken());
}
static double dub() throws IOException{
if (st==null || !st.hasMoreTokens()){
st=new StringTokenizer(buf.readLine());
}
return Double.parseDouble(st.nextToken());
}
}
class pair{
char c;
int p;
pair(char c,int p){
this.c=c;
this.p=p;
}
@Override
public boolean equals(Object arg0) {
return ((pair)arg0).c==c;
}
public int hashCode() {
return c;
}
}
| Java | ["9\npergament\npermanent", "6\nwookie\ncookie", "4\npetr\negor", "6\ndouble\nbundle"] | 2 seconds | ["1\n4 6", "1\n-1 -1", "2\n1 2", "2\n4 1"] | NoteIn the second test it is acceptable to print iβ=β2, jβ=β3. | Java 7 | standard input | [
"greedy"
] | 2fa543c8b8f9dc500c36cf719800a6b0 | The first line contains integer n (1ββ€βnββ€β200β000) β the length of strings S and T. The second line contains string S. The third line contains string T. Each of the lines only contains lowercase Latin letters. | 1,500 | In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S. In the second line, either print the indexes i and j (1ββ€βi,βjββ€βn, iββ βj), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters. If there are multiple possible answers, print any of them. | standard output | |
PASSED | e52582a082779aa8ea5ddd37d82a56f7 | train_000.jsonl | 1426610700 | Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.Help him do this! | 256 megabytes | import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.StringTokenizer;
public class Main {
void solve() throws IOException {
io.next();
char[] s = io.next().toCharArray();
char[] t = io.next().toCharArray();
int[][] pos = new int[30][30];
for (int i = 0; i < pos.length; i++) {
Arrays.fill(pos[i], -1);
}
for(int i = 0; i < s.length; i++) {
s[i] -= 'a';
t[i] -= 'a';
}
int dist = 0;
for (int i = 0; i < s.length; i++) {
if (s[i] != t[i]) {
dist++;
pos[s[i]][t[i]] = i;
}
}
for (int i = 0; i < s.length; i++) {
if (s[i] != t[i]) {
if (pos[t[i]][s[i]] != -1) {
dist -= 2;
io.println(dist);
io.println((i + 1) + " " + (pos[t[i]][s[i]] + 1));
return;
}
}
}
for (int i = 0; i < s.length; i++) {
if (s[i] != t[i]) {
for (int j = 0; j <= 26; j++) {
if (pos[t[i]][j] != -1) {
dist -= 1;
io.println(dist);
io.println((i + 1) + " " + (pos[t[i]][j] + 1));
return;
}
}
}
}
io.println(dist);
io.println("-1 -1");
}
// ~~~~~~~~~~~~~~~~~~~~~~~ //
public static void main(String[] args) throws IOException {
io = new MyIO(null);
long timeBegin = System.currentTimeMillis();
new Main().solve();
long timeEnd = System.currentTimeMillis();
System.err.println(timeEnd - timeBegin + " millis");
io.close();
}
static class Geom {
static final double EPS = 1e-6;
static int sign(double d) {
if (Math.abs(d) <= EPS) {
return 0;
}
if (d > 0) {
return 1;
} else {
return -1;
}
}
static class Point {
double x;
double y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public Point add(Vector n) {
return new Point(x + n.x, y + n.y);
}
public Point() {
x = 0;
y = 0;
}
@Override
public String toString() {
return "(" + x + ", " + y + ")";
}
double distanceTo(Point b) {
return Math.sqrt(squareDistanceTo(b));
}
double squareDistanceTo(Point b) {
return (x - b.x) * (x - b.x) + (y - b.y) * (y - b.y);
}
}
static class Vector extends Point {
public Vector(Point a, Point b) {
x = b.x - a.x;
y = b.y - a.y;
}
public Vector() {
super();
}
public Vector(double x, double y) {
this.x = x;
this.y = y;
}
public Vector(Point a) {
x = a.x;
y = a.y;
}
@Override
public String toString() {
return "{" + x + ", " + y + "}";
}
public double length() {
return new Point(0, 0).distanceTo(new Point(x, y));
}
public Vector getNormalized() {
double len = length();
return new Vector(x / len, y / len);
}
public double crossProduct(Vector b) {
Vector a = this;
return a.x * b.y - a.y * b.x;
}
public double dotProduct(Vector b) {
Vector a = this;
return a.x * b.x + a.y * b.y;
}
}
static class Line {
double a;
double b;
double c;
public Line(Point i, Point j) {
a = i.y - j.y;
b = j.x - i.x;
c = -a * i.x - b * i.y;
}
public boolean contains(Point p) {
return sign(a * p.x + b * p.y + c) == 0;
}
public Vector getNormal() {
return new Vector(a, b).getNormalized();
}
public Line(double a, double b, double c) {
this.a = a;
this.b = b;
this.c = c;
}
double getX(double y) {
return (b * y + c) / -a;
}
double getY(double x) {
return (a * x + c) / -b;
}
Point intersect(Line l) {
double z = a * l.b - l.a * b;
if (sign(z) == 0) {
return null;
}
double x = ((b * l.c) - (l.b * c)) / z;
double y = ((c * l.a) - (l.c * a)) / z;
return new Point(x, y);
}
}
static class Polygon {
ArrayList<Point> points;
public Polygon() {
points = new ArrayList<Point>();
}
public Polygon(Collection<Point> col) {
points = new ArrayList<Point>(col);
}
double area() {
double ans = 0;
for (int i = 0; i < points.size(); i++) {
Vector a = new Vector(points.get(i));
Vector b;
if (i == points.size() - 1) {
b = new Vector(points.get(0));
} else {
b = new Vector(points.get(i + 1));
}
ans += a.crossProduct(b);
}
return Math.abs(ans / 2);
}
boolean contains(Point p) {
int sign = Integer.MIN_VALUE;
for (int i = 0; i < points.size(); i++) {
Point a = points.get(i);
Point b;
if (i == points.size() - 1) {
b = points.get(0);
} else {
b = points.get(i + 1);
}
Vector ab = new Vector(a, b);
Vector cp = new Vector(a, p);
if (sign == Integer.MIN_VALUE) {
sign = sign(ab.crossProduct(cp));
} else {
if (sign != sign(ab.crossProduct(cp))) {
return false;
}
}
}
return false;
}
}
}
static MyIO io;
static class MyIO {
BufferedReader in;
PrintWriter out;
static final String myIn = "input.txt";
static final String myOut = "output.txt";
MyIO(String problemName) throws FileNotFoundException {
if (new File(myIn).exists()) {
in = new BufferedReader(new FileReader(new File(myIn)));
out = new PrintWriter(new File(myOut));
return;
} else {
if (problemName == null) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
} else {
in = new BufferedReader(new FileReader(new File(problemName
+ ".in")));
out = new PrintWriter(new File(problemName + ".out"));
}
}
}
void println(int i) {
out.println(i);
}
void println(Object s) {
out.println(s);
}
void println(long l) {
out.println(l);
}
void print(Object s) {
out.print(s.toString());
}
void print(char c) {
out.print(c);
}
void println() {
out.println();
}
StringTokenizer tkn = new StringTokenizer("");
void prepareTokenizer() throws IOException {
while (!tkn.hasMoreTokens()) {
tkn = new StringTokenizer(nextLine());
}
}
String nextLine() throws IOException {
return in.readLine();
}
String next() throws IOException {
prepareTokenizer();
return tkn.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
void close() throws IOException {
in.close();
out.close();
}
}
} | Java | ["9\npergament\npermanent", "6\nwookie\ncookie", "4\npetr\negor", "6\ndouble\nbundle"] | 2 seconds | ["1\n4 6", "1\n-1 -1", "2\n1 2", "2\n4 1"] | NoteIn the second test it is acceptable to print iβ=β2, jβ=β3. | Java 7 | standard input | [
"greedy"
] | 2fa543c8b8f9dc500c36cf719800a6b0 | The first line contains integer n (1ββ€βnββ€β200β000) β the length of strings S and T. The second line contains string S. The third line contains string T. Each of the lines only contains lowercase Latin letters. | 1,500 | In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S. In the second line, either print the indexes i and j (1ββ€βi,βjββ€βn, iββ βj), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters. If there are multiple possible answers, print any of them. | standard output | |
PASSED | 92a206c8f40ee3c1f0b27dcf45f314a7 | train_000.jsonl | 1426610700 | Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.Help him do this! | 256 megabytes | import java.io.*;
import java.util.*;
public class Program {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
static final int Mod = 1000000007;
static final double inf = 10000000000.0;
void solve() throws IOException {
int n = nextInt(), error = 0;
String a, b;
a = nextString();
b = nextString();
int[][] dp = new int[26][26];
int idp[] = new int[26];
for(int i = 0; i < 26; i++)
Arrays.fill(dp[i], -1);
Arrays.fill(idp, -1);
for(int i = 0; i < n; i++)
if (a.charAt(i) != b.charAt(i))
{
error++;
dp[a.charAt(i)-'a'][b.charAt(i)-'a'] = i+1;
idp[a.charAt(i)-'a'] = i+1;
}
boolean p = false;
int x, y;
x = y = -1;
for(int i = 0; i < 26 && !p; i++)
for(int j = i+1; j < 26; j++)
if (dp[i][j] != -1 && dp[j][i] != -1)
{
x = dp[i][j];
y = dp[j][i];
p = true;
error-=2;
break;
}
if (!p)
{
for(int i = 0; i < 26 && !p; i++)
for(int j = 0; j < 26; j++)
if (dp[i][j] != -1 && idp[j] != -1)
{
x = dp[i][j];
y = idp[j];
p = true;
error--;
break;
}
}
out.println(error);
out.println(x + " " + y);
}
Program() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
public static void main(String[] args) throws IOException {
new Program();
}
String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return null;
}
}
return st.nextToken();
}
String nextString() {
try {
return br.readLine();
} catch (IOException e) {
eof = true;
return null;
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
} | Java | ["9\npergament\npermanent", "6\nwookie\ncookie", "4\npetr\negor", "6\ndouble\nbundle"] | 2 seconds | ["1\n4 6", "1\n-1 -1", "2\n1 2", "2\n4 1"] | NoteIn the second test it is acceptable to print iβ=β2, jβ=β3. | Java 7 | standard input | [
"greedy"
] | 2fa543c8b8f9dc500c36cf719800a6b0 | The first line contains integer n (1ββ€βnββ€β200β000) β the length of strings S and T. The second line contains string S. The third line contains string T. Each of the lines only contains lowercase Latin letters. | 1,500 | In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S. In the second line, either print the indexes i and j (1ββ€βi,βjββ€βn, iββ βj), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters. If there are multiple possible answers, print any of them. | standard output | |
PASSED | 9d0c05412b69ac645b8fb71e3138152e | train_000.jsonl | 1426610700 | Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.Help him do this! | 256 megabytes | import java.io.*;
import java.util.*;
public class I {
public static void main(String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
String s = br.readLine();String t = br.readLine();
int[] ar = new int[26];
Arrays.fill(ar, -1);
TreeMap<String, Integer> mp = new TreeMap<String, Integer>();
int c = 0;
for(int i=0; i<s.length(); i++){
char a = s.charAt(i); char b = t.charAt(i);
if(a != b){
c++; mp.put(a+(b+""), i);
ar[b - 'a'] = i;
}
}
for(int i=0; i<s.length(); i++){
char a = s.charAt(i), b = t.charAt(i);
if(a != b){
if(mp.containsKey(b+(a+""))){
int index = mp.get(b+(a+""));
System.out.println(c-2);
System.out.println((Math.min(index, i)+1) + " " + (Math.max(index, i) + 1));
return;
}
}
}
for(int i=0; i<s.length(); i++){
char a = s.charAt(i), b = t.charAt(i);
if(a != b && ar[a - 'a'] > -1){
System.out.println(c-1);
System.out.println((Math.min(i, ar[a-'a'])+1)+" " + (Math.max(i, ar[a-'a'])+1));
return;
}
}
System.out.println(c);
System.out.println("-1 -1");
}
} | Java | ["9\npergament\npermanent", "6\nwookie\ncookie", "4\npetr\negor", "6\ndouble\nbundle"] | 2 seconds | ["1\n4 6", "1\n-1 -1", "2\n1 2", "2\n4 1"] | NoteIn the second test it is acceptable to print iβ=β2, jβ=β3. | Java 7 | standard input | [
"greedy"
] | 2fa543c8b8f9dc500c36cf719800a6b0 | The first line contains integer n (1ββ€βnββ€β200β000) β the length of strings S and T. The second line contains string S. The third line contains string T. Each of the lines only contains lowercase Latin letters. | 1,500 | In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S. In the second line, either print the indexes i and j (1ββ€βi,βjββ€βn, iββ βj), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters. If there are multiple possible answers, print any of them. | standard output | |
PASSED | fe48f7fd6793a0d5df02df9a370763e6 | train_000.jsonl | 1426610700 | Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.Help him do this! | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class TB {
public static void main(String[] args) {
FastScanner in=new FastScanner();
int i,j,k,n=in.nextInt();
char[] s=in.nextToken().toCharArray();
char[] t=in.nextToken().toCharArray();
int distance=0;
int[][] g=new int[26][26];
for(i=0;i<26;i++)
Arrays.fill(g[i],-1);
for(i=0;i<n;i++){
if(s[i]!=t[i]){
distance++;
g[s[i]-'a'][t[i]-'a']=i+1;
}
}
int[] ans={-1,-1};
if(distance==0&&distance==1){
System.out.println(distance);
System.out.println(ans[0]+" "+ans[1]);
}else{
boolean f=false;
for(i=0;i<26&&!f;i++){
for(j=0;j<26&&!f;j++){
if(i!=j&&g[i][j]>-1){
for(k=0;k<26&&!f;k++){
if(j!=k&&g[j][k]>-1){
ans[0]=g[i][j];
ans[1]=g[j][k];
if(i==k){
f=true;
break;
}
}
}
}
}
}
if(f){
distance-=2;
}else{
if(ans[0]>-1&&ans[1]>-1){
distance--;
}
}
System.out.println(distance);
System.out.println(ans[0]+" "+ans[1]);
}
}
static class FastScanner{
BufferedReader br;
StringTokenizer st;
public FastScanner(){br=new BufferedReader(new InputStreamReader(System.in));}
String nextToken(){
while(st==null||!st.hasMoreElements())
try{st=new StringTokenizer(br.readLine());}catch(Exception e){}
return st.nextToken();
}
int nextInt(){return Integer.parseInt(nextToken());}
long nextLong(){return Long.parseLong(nextToken());}
double nextDouble(){return Double.parseDouble(nextToken());}
}
}
| Java | ["9\npergament\npermanent", "6\nwookie\ncookie", "4\npetr\negor", "6\ndouble\nbundle"] | 2 seconds | ["1\n4 6", "1\n-1 -1", "2\n1 2", "2\n4 1"] | NoteIn the second test it is acceptable to print iβ=β2, jβ=β3. | Java 7 | standard input | [
"greedy"
] | 2fa543c8b8f9dc500c36cf719800a6b0 | The first line contains integer n (1ββ€βnββ€β200β000) β the length of strings S and T. The second line contains string S. The third line contains string T. Each of the lines only contains lowercase Latin letters. | 1,500 | In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S. In the second line, either print the indexes i and j (1ββ€βi,βjββ€βn, iββ βj), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters. If there are multiple possible answers, print any of them. | standard output | |
PASSED | b6cbfcafdac8e408d6c39f9d00bdb75a | train_000.jsonl | 1426610700 | Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.Help him do this! | 256 megabytes | /* package whatever; // 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 Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String s = sc.next();
String t = sc.next();
ArrayList<Integer> bad = new ArrayList<Integer>();
for(int i = 0;i<n;i++){
if(s.charAt(i)!=t.charAt(i)){
bad.add(i);
}
}
if(bad.size()==0){
System.out.println(0);
System.out.println(-1 + " " + -1);
}
if(bad.size()==1){
System.out.println(1);
System.out.println(-1 + " " + -1);
}
if(bad.size()>1){
int index[][] = new int[26][26];
int a[][] = new int[26][26];
for(int i = 0;i<26;i++){
for(int j = 0;j<26;j++){
a[i][j]=0;
index[i][j]=0;
}
}
for(int i :bad){
int x = (int)s.charAt(i)-(int)'a';
int y = (int)t.charAt(i)-(int)'a';
a[x][y]=1;
index[x][y]=i;
}
/* for(int i = 0;i<26;i++){
for(int j = 0;j<26;j++){
System.out.print(a[i][j]);
}
System.out.println();
}*/
boolean swap = false;
int asdf = -1;
int bsdf = -1;
for(int i = 0;i<26;i++){
for(int j = 0;j<26;j++){
if(a[i][j]==1&&a[j][i]==1){
asdf = index[i][j];
bsdf = index[j][i];
swap=true;
/* System.out.println("+++++ " + i + " " + j);*/
break;
}
}
}
if(swap){
System.out.println(bad.size()-2);
System.out.println((asdf+1) + " " + (bsdf+1));
}
else{
swap = false;
int ww = -1;
int xx = -1;
int yy = -1;
for(int i = 0;i<26;i++){
for(int j = 0;j<26;j++){
for(int k = 0;k<26;k++){
if(a[i][j]==1&&a[k][i]==1){
swap = true;
ww=i;
xx=j;
yy=k;
}
}
}
}
if(swap){
System.out.println(bad.size()-1);
System.out.println((index[ww][xx]+1) + " " + (index[yy][ww]+1));
}
else{
System.out.println(bad.size());
System.out.println(-1 + " " + -1);
}
}
}
}
} | Java | ["9\npergament\npermanent", "6\nwookie\ncookie", "4\npetr\negor", "6\ndouble\nbundle"] | 2 seconds | ["1\n4 6", "1\n-1 -1", "2\n1 2", "2\n4 1"] | NoteIn the second test it is acceptable to print iβ=β2, jβ=β3. | Java 7 | standard input | [
"greedy"
] | 2fa543c8b8f9dc500c36cf719800a6b0 | The first line contains integer n (1ββ€βnββ€β200β000) β the length of strings S and T. The second line contains string S. The third line contains string T. Each of the lines only contains lowercase Latin letters. | 1,500 | In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S. In the second line, either print the indexes i and j (1ββ€βi,βjββ€βn, iββ βj), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters. If there are multiple possible answers, print any of them. | standard output | |
PASSED | 5d8657ea175d4e3da619e1855ccf6eda | train_000.jsonl | 1426610700 | Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.Help him do this! | 256 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
public class MainB {
MyScanner sc = new MyScanner();
Scanner sc2 = new Scanner(System.in);
long start = System.currentTimeMillis();
long fin = System.currentTimeMillis();
final int MOD = 1000000007;
int[] dx = { 1, 0, 0, -1 };
int[] dy = { 0, 1, -1, 0 };
void run() {
int n = sc.nextInt();
String s = sc.next();
String t = sc.next();
HashMap<Character, HashSet<Character>> set1 = new HashMap<Character, HashSet<Character>>();
HashMap<Character, HashSet<Character>> set2 = new HashMap<Character, HashSet<Character>>();
for (int i = 0; i < n; i++) {
if (s.charAt(i) != t.charAt(i)) {
if (!set1.containsKey(s.charAt(i))) {
HashSet<Character> set = new HashSet<Character>();
set.add(t.charAt(i));
set1.put(s.charAt(i), set);
set1.get(s.charAt(i)).add(t.charAt(i));
} else {
set1.get(s.charAt(i)).add(t.charAt(i));
}
if (!set2.containsKey(s.charAt(i))) {
HashSet<Character> set = new HashSet<Character>();
set.add(t.charAt(i));
set2.put(s.charAt(i), set);
set2.get(s.charAt(i)).add(t.charAt(i));
} else {
set2.get(s.charAt(i)).add(t.charAt(i));
}
}
}
for (Character key : set1.keySet()) {
HashSet<Character> set = set1.get(key);
for (Character from : set) {
if (set2.containsKey(from)) {
HashSet<Character> setf = set2.get(from);
if (setf.contains(key)) {
char a = key;
char b = from;
int ansa = 0;
int ansb = 0;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (s.charAt(i) != t.charAt(i)) {
cnt++;
}
if (s.charAt(i) == a && t.charAt(i) == b) {
ansa = i;
}
if (s.charAt(i) == b && t.charAt(i) == a) {
ansb = i;
}
}
System.out.println(cnt - 2);
System.out.println((ansa + 1) + " " + (ansb + 1));
return;
}
}
}
}
HashSet<Character> s1 = new HashSet<Character>();
HashSet<Character> s2 = new HashSet<Character>();
for (int i = 0; i < n; i++) {
if (s.charAt(i) != t.charAt(i)) {
s1.add(s.charAt(i));
s2.add(t.charAt(i));
}
}
for (Character key : s1) {
if (s2.contains(key)) {
int ansa = 0;
int ansb = 0;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (s.charAt(i) != t.charAt(i)) {
cnt++;
}
if (s.charAt(i) != t.charAt(i) && s.charAt(i) == key) {
ansa = i;
}
if (s.charAt(i) != t.charAt(i) && t.charAt(i) == key) {
ansb = i;
}
}
System.out.println(cnt - 1);
System.out.println((ansa + 1) + " " + (ansb + 1));
return;
}
}
int cnt = 0;
for (int i = 0; i < n; i++) {
if (s.charAt(i) != t.charAt(i)) {
cnt++;
}
}
System.out.println(cnt);
System.out.println(-1 + " " + -1);
}
public static void main(String[] args) {
new MainB().run();
}
void debug(Object... o) {
System.out.println(Arrays.deepToString(o));
}
void debug2(int[][] array) {
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
System.out.print(array[i][j]);
}
System.out.println();
}
}
boolean inner(int h, int w, int limH, int limW) {
return 0 <= h && h < limH && 0 <= w && w < limW;
}
void swap(int[] x, int a, int b) {
int tmp = x[a];
x[a] = x[b];
x[b] = tmp;
}
// find minimum i (a[i] >= border)
int lower_bound(int a[], int border) {
int l = -1;
int r = a.length;
while (r - l > 1) {
int mid = (l + r) / 2;
if (border <= a[mid]) {
r = mid;
} else {
l = mid;
}
}
// r = l + 1
return r;
}
boolean palindrome(String s) {
for (int i = 0; i < s.length() / 2; i++) {
if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
return false;
}
}
return true;
}
class MyScanner {
int nextInt() {
try {
int c = System.in.read();
while (c != '-' && (c < '0' || '9' < c))
c = System.in.read();
if (c == '-')
return -nextInt();
int res = 0;
do {
res *= 10;
res += c - '0';
c = System.in.read();
} while ('0' <= c && c <= '9');
return res;
} catch (Exception e) {
return -1;
}
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
String next() {
try {
StringBuilder res = new StringBuilder("");
int c = System.in.read();
while (Character.isWhitespace(c))
c = System.in.read();
do {
res.append((char) c);
} while (!Character.isWhitespace(c = System.in.read()));
return res.toString();
} catch (Exception e) {
return null;
}
}
int[] nextIntArray(int n) {
int[] in = new int[n];
for (int i = 0; i < n; i++) {
in[i] = nextInt();
}
return in;
}
int[][] nextInt2dArray(int n, int m) {
int[][] in = new int[n][m];
for (int i = 0; i < n; i++) {
in[i] = nextIntArray(m);
}
return in;
}
double[] nextDoubleArray(int n) {
double[] in = new double[n];
for (int i = 0; i < n; i++) {
in[i] = nextDouble();
}
return in;
}
long[] nextLongArray(int n) {
long[] in = new long[n];
for (int i = 0; i < n; i++) {
in[i] = nextLong();
}
return in;
}
char[][] nextCharField(int n, int m) {
char[][] in = new char[n][m];
for (int i = 0; i < n; i++) {
String s = sc.next();
for (int j = 0; j < m; j++) {
in[i][j] = s.charAt(j);
}
}
return in;
}
}
}
| Java | ["9\npergament\npermanent", "6\nwookie\ncookie", "4\npetr\negor", "6\ndouble\nbundle"] | 2 seconds | ["1\n4 6", "1\n-1 -1", "2\n1 2", "2\n4 1"] | NoteIn the second test it is acceptable to print iβ=β2, jβ=β3. | Java 7 | standard input | [
"greedy"
] | 2fa543c8b8f9dc500c36cf719800a6b0 | The first line contains integer n (1ββ€βnββ€β200β000) β the length of strings S and T. The second line contains string S. The third line contains string T. Each of the lines only contains lowercase Latin letters. | 1,500 | In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S. In the second line, either print the indexes i and j (1ββ€βi,βjββ€βn, iββ βj), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters. If there are multiple possible answers, print any of them. | standard output | |
PASSED | 1b8184d5c5ce4444908872283a367578 | train_000.jsonl | 1426610700 | Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.Help him do this! | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
public class B_Div2_296{
public static void main(String[]arg) throws IOException
{
new B_Div2_296().solve();
}
public void solve() throws IOException
{
/*HashMap map = new HashMap();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine());
String s = in.readLine();
String t = in.readLine();
char sc,tc,a,b;
int hammingDist = 0;
int red = 0;int j;
int x = -1, y = -1;
boolean flag1 = false, flag2 = false;
for(int i = 0; i < n; i++)
{
if(s.charAt(i) != t.charAt(i))
{
map.put(String.valueOf(s.charAt(i)),i);
}
}
System.out.println(hammingDist-red);
System.out.println(x + " " + y);*/
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
HashMap<String, Integer> mapTwo = new HashMap<String, Integer>();
HashMap<Character, Integer> mapOne = new HashMap<Character, Integer>();
int n = Integer.parseInt(in.readLine());
String s = in.readLine();
String t = in.readLine();
char cs,ct;
int hammingDist = 0;
for(int i = 0; i < n; i++)
{
cs = s.charAt(i);
ct = t.charAt(i);
if(cs!=ct)
{
hammingDist++;
mapOne.put(cs, i);
mapTwo.put(String.valueOf(cs)+String.valueOf(ct), i);
//System.out.println(String.valueOf(cs)+String.valueOf(ct));
}
}
boolean flag1 = false;
boolean flag2 = false;
int j;
int red = 0;
int u = -1, v = -1;
String cad = "";
for(int i = 0; i < n && !flag2; i++)
{
cs = s.charAt(i);
ct = t.charAt(i);
//System.out.println(ct+cs);
if(cs!=ct)
{
if(!flag1)
{
if(mapOne.containsKey(ct))
{
u = i+1;
v = mapOne.get(ct)+1;
red = 1;
flag1 = true;
}
}
if(!flag2)
{
cad = String.valueOf(ct) + String.valueOf(cs);
if(mapTwo.containsKey(cad))
{
//System.out.println("in");
u = i+1;
v = mapTwo.get(cad)+1;
red = 2;
flag2 = true;
}
}
}
}
if(flag2)
{
hammingDist -= red;
System.out.println(hammingDist);
System.out.println(u + " " + v);
}
else if(flag1)
{
hammingDist -= red;
System.out.println(hammingDist);
System.out.println(u + " " + v);
}
else
{
System.out.println(hammingDist);
System.out.println(u + " " + v);
}
}
}
| Java | ["9\npergament\npermanent", "6\nwookie\ncookie", "4\npetr\negor", "6\ndouble\nbundle"] | 2 seconds | ["1\n4 6", "1\n-1 -1", "2\n1 2", "2\n4 1"] | NoteIn the second test it is acceptable to print iβ=β2, jβ=β3. | Java 7 | standard input | [
"greedy"
] | 2fa543c8b8f9dc500c36cf719800a6b0 | The first line contains integer n (1ββ€βnββ€β200β000) β the length of strings S and T. The second line contains string S. The third line contains string T. Each of the lines only contains lowercase Latin letters. | 1,500 | In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S. In the second line, either print the indexes i and j (1ββ€βi,βjββ€βn, iββ βj), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters. If there are multiple possible answers, print any of them. | standard output | |
PASSED | 05b2c2cbb04bdcae12d29f570b5c6795 | train_000.jsonl | 1426610700 | Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.Help him do this! | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
import java.text.*;
public class b
{
static FastScanner in = new FastScanner(System.in);
static StringBuilder sb = new StringBuilder();
static DecimalFormat df = new DecimalFormat();
public static void main(String[] args)
{
df.setMaximumFractionDigits(20);
df.setMinimumFractionDigits(20);
// String formatted = df.format(0.2);
// Never sort array of primitive type
Integer n = in.nextInt();
String s = in.nextToken();
String t = in.nextToken();
int j,k;
j = k = -1;
int hamming = 0;
boolean foundSingle = false;
boolean foundDouble = false;
HashMap<Character, Integer> smap = new HashMap<Character, Integer>();
HashMap<Character, Integer> tmap = new HashMap<Character, Integer>();
HashMap<String, Integer> stmap = new HashMap<String, Integer>();
for(int i = 0; i < s.length(); i++) {
if(s.charAt(i)!=t.charAt(i)) { // if letters are not matching,
hamming++;
// for(String key : stmap.keySet()) {
// System.out.print(key + "\t");
// }
// System.out.println("");
if(!foundDouble && stmap.containsKey(s.substring(i,i+1)+t.substring(i,i+1))) { // check for double pair
//********* j = smap.get(t.charAt(i))+1;
j = stmap.get(s.charAt(i) + "" + t.charAt(i))+1;
k = i+1;
foundDouble = true;
}
else if(!foundDouble && !foundSingle && smap.containsKey(t.charAt(i))) { // check for single pair
j = smap.get(t.charAt(i))+1;
k = i+1;
foundSingle = true;
}
else if(!foundDouble && !foundSingle && tmap.containsKey(s.charAt(i))) { // check for single pair
j = tmap.get(s.charAt(i))+1;
k = i+1;
foundSingle = true;
}
if(!smap.containsKey(s.charAt(i))) // else, add new keys to maps
smap.put(s.charAt(i),i);
if(!tmap.containsKey(t.charAt(i)))
tmap.put(t.charAt(i),i);
if(!stmap.containsKey(t.substring(i,i+1)+s.substring(i,i+1)))
stmap.put(t.substring(i,i+1)+s.substring(i,i+1),i);
}
}
if(foundDouble) {
hamming -= 2;
// System.out.println("found double");
} else if(foundSingle) {
hamming -= 1;
// System.out.println("found single");
}
System.out.println(hamming);
System.out.println(j + " " + k);
}
static BigInteger b(long n) { return BigInteger.valueOf(n);}
static BigInteger b(String s) { return new BigInteger(s); }
static BigDecimal bd(double d) { return BigDecimal.valueOf(d);}
static BigDecimal bd(String s) { return new BigDecimal(s); }
}
class FastScanner
{
BufferedReader reader;
StringTokenizer tokenizer;
FastScanner (InputStream inputStream)
{
reader = new BufferedReader(new InputStreamReader(inputStream));
}
String nextToken()
{
while (tokenizer == null || ! tokenizer.hasMoreTokens())
{
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (Exception e){}
}
return tokenizer.nextToken();
}
boolean hasNext()
{
if (tokenizer == null || ! tokenizer.hasMoreTokens())
{
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (Exception e){ return false; }
}
return true;
}
int nextInt()
{
return Integer.parseInt(nextToken());
}
} | Java | ["9\npergament\npermanent", "6\nwookie\ncookie", "4\npetr\negor", "6\ndouble\nbundle"] | 2 seconds | ["1\n4 6", "1\n-1 -1", "2\n1 2", "2\n4 1"] | NoteIn the second test it is acceptable to print iβ=β2, jβ=β3. | Java 7 | standard input | [
"greedy"
] | 2fa543c8b8f9dc500c36cf719800a6b0 | The first line contains integer n (1ββ€βnββ€β200β000) β the length of strings S and T. The second line contains string S. The third line contains string T. Each of the lines only contains lowercase Latin letters. | 1,500 | In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S. In the second line, either print the indexes i and j (1ββ€βi,βjββ€βn, iββ βj), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters. If there are multiple possible answers, print any of them. | standard output | |
PASSED | bf046da05f031165ebfac669951a605f | train_000.jsonl | 1426610700 | Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.Help him do this! | 256 megabytes | //################################################################################################################
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
//################################################################################################################
public class R296D2B {
public static void main(String[] args) {
R296D2B b = new R296D2B();
InputReader1 reader = b.new InputReader1(System.in);
OutputWriter writer = b.new OutputWriter(System.out);
// think about the brute-force approach
// read input
// code boundary conditions
int len = reader.readInt();
char[] s = reader.readLine().toCharArray();
char[] t = reader.readLine().toCharArray();
int iham = 0;
Lst[][] mm = new Lst[26][26];
int[] found = new int[26];
Arrays.fill(found, -1);
for (int i = 0; i < len; i++) {
if (s[i] != t[i]) {
found[s[i] - 'a'] = i;
if (mm[s[i] - 'a'][t[i] - 'a'] == null) {
mm[s[i] - 'a'][t[i] - 'a'] = b.new Lst();
mm[s[i] - 'a'][t[i] - 'a'].ii.add(i);
} else {
mm[s[i] - 'a'][t[i] - 'a'].ii.add(i);
}
iham++;
}
}
boolean f2 = false;
boolean f1 = false;
int gi = -1;
int gj = -1;
for (int i = 0; i < mm.length; i++) {
for (int j = 0; j < mm[0].length; j++) {
if (i == j || mm[i][j] == null) {
continue;
}
if (mm[j][i] != null && mm[i][j].ii.size() > 0
&& mm[j][i].ii.size() > 0) {
f2 = true;
gi = mm[i][j].ii.get(0);
gj = mm[j][i].ii.get(0);
break;
} else if (found[j] != -1) {
f1 = true;
gi = mm[i][j].ii.get(0);
gj = found[j];
}
}
if (f2) {
break;
}
}
if (f2) {
writer.println(iham - 2);
writer.println((gi + 1) + " " + (gj + 1));
} else if (f1) {
writer.println(iham - 1);
writer.println((gi + 1) + " " + (gj + 1));
} else {
writer.println(iham);
writer.println(-1 + " " + -1);
}
reader.close();
writer.close();
}
class Lst {
List<Integer> ii;
public Lst() {
ii = new ArrayList<Integer>();
}
}
class InputReader1 {
// private final boolean finished = false;
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public InputReader1(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 peek() {
if (numChars == -1)
return -1;
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
return -1;
}
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 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 String readString() {
int length = readInt();
if (length < 0)
return null;
byte[] bytes = new byte[length];
for (int i = 0; i < length; i++)
bytes[i] = (byte) read();
try {
return new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException e) {
return new String(bytes);
}
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private String readLine0() {
StringBuffer buf = new StringBuffer();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r')
buf.appendCodePoint(c);
c = read();
}
return buf.toString();
}
public String readLine() {
String s = readLine0();
while (s.trim().length() == 0)
s = readLine0();
return s;
}
public String readLine(boolean ignoreEmptyLines) {
if (ignoreEmptyLines)
return readLine();
else
return readLine0();
}
public BigInteger readBigInteger() {
try {
return new BigInteger(readString());
} catch (NumberFormatException e) {
throw new InputMismatchException();
}
}
public char readCharacter() {
int c = read();
while (isSpaceChar(c))
c = read();
return (char) c;
}
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 boolean isExhausted() {
int value;
while (isSpaceChar(value = peek()) && value != -1)
read();
return value == -1;
}
public String next() {
return readString();
}
public boolean readBoolean() {
return readInt() == 1;
}
public void close() {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream stream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
stream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void println(String s) {
writer.println(s);
}
public void println(int x) {
writer.println(x);
}
public void print(int x) {
writer.print(x);
}
public void println(long x) {
writer.println(x);
}
public void printSpace() {
writer.print(" ");
}
public void close() {
writer.close();
}
}
}
| Java | ["9\npergament\npermanent", "6\nwookie\ncookie", "4\npetr\negor", "6\ndouble\nbundle"] | 2 seconds | ["1\n4 6", "1\n-1 -1", "2\n1 2", "2\n4 1"] | NoteIn the second test it is acceptable to print iβ=β2, jβ=β3. | Java 7 | standard input | [
"greedy"
] | 2fa543c8b8f9dc500c36cf719800a6b0 | The first line contains integer n (1ββ€βnββ€β200β000) β the length of strings S and T. The second line contains string S. The third line contains string T. Each of the lines only contains lowercase Latin letters. | 1,500 | In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S. In the second line, either print the indexes i and j (1ββ€βi,βjββ€βn, iββ βj), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters. If there are multiple possible answers, print any of them. | standard output | |
PASSED | 341d06fc46846cf937e3ab201b6ef27e | train_000.jsonl | 1426610700 | Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.Help him do this! | 256 megabytes | import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
public class Solution{
///////////////////////////////////////////////////////////////////////////
static class FastScanner{
BufferedReader s;
StringTokenizer st;
public FastScanner(InputStream InputStream){
st = new StringTokenizer("");
s = new BufferedReader(new InputStreamReader(InputStream));
}
public FastScanner(File f) throws FileNotFoundException{
st = new StringTokenizer("");
s = new BufferedReader (new FileReader(f));
}
public int nextInt() throws IOException{
if(st.hasMoreTokens())
return Integer.parseInt(st.nextToken());
else{
st = new StringTokenizer(s.readLine());
return nextInt();
}
}
public BigInteger big() throws IOException{
if(st.hasMoreTokens())
return new BigInteger(st.nextToken());
else{
st = new StringTokenizer(s.readLine());
return big();
}
}
public double nextDouble() throws IOException{
if(st.hasMoreTokens())
return Double.parseDouble(st.nextToken());
else{
st = new StringTokenizer(s.readLine());
return nextDouble();
}
}
public long nextLong() throws IOException{
if(st.hasMoreTokens())
return Long.parseLong(st.nextToken());
else{
st = new StringTokenizer(s.readLine());
return nextLong();
}
}
public String nextString() throws IOException{
if(st.hasMoreTokens())
return st.nextToken();
else{
st = new StringTokenizer(s.readLine());
return nextString();
}
}
public String readLine() throws IOException{
return s.readLine();
}
public void close() throws IOException{
s.close();
}
}
////////////////////////////////////////////////////////////////////
// Number Theory
long pow(long a,long b,long mod){
long x = 1; long y = a;
while(b > 0){
if(b % 2 == 1){
x = (x*y);
x %= mod;
}
y = (y*y);
y %= mod;
b /= 2;
}
return x;
}
int divisor(long x,long[] a){
long limit = x;
int numberOfDivisors = 0;
for (int i=1; i < limit; ++i) {
if (x % i == 0) {
limit = x / i;
if (limit != i) {
numberOfDivisors++;
}
numberOfDivisors++;
}
}
return numberOfDivisors;
}
void findSubsets(int array[]){
long numOfSubsets = 1 << array.length;
for(int i = 0; i < numOfSubsets; i++){
@SuppressWarnings("unused")
int pos = array.length - 1;
int bitmask = i;
while(bitmask > 0){
if((bitmask & 1) == 1)
// ww.print(array[pos]+" ");
bitmask >>= 1;
pos--;
}
// ww.println();
}
}
public static long gcd(long a, long b){
return b == 0 ? a : gcd(b,a%b);
}
public static long lcm(int a,int b, int c){
return lcm(lcm(a,b),c);
}
public static long lcm(long a, long b){
return (a*b/gcd(a,b));
}
public static long invl(long a, long mod) {
long b = mod;
long p = 1, q = 0;
while (b > 0) {
long c = a / b;
long d;
d = a;
a = b;
b = d % b;
d = p;
p = q;
q = d - c * q;
}
return p < 0 ? p + mod : p;
}
////////////////////////////////////////////////////////////////////
// FastScanner s = new FastScanner(new File("input.txt"));
// PrintWriter ww = new PrintWriter(new FileWriter("output.txt"));
static InputStream inputStream = System.in;
static FastScanner s = new FastScanner(inputStream);
static OutputStream outputStream = System.out;
static PrintWriter ww = new PrintWriter(new OutputStreamWriter(outputStream));
// private static Scanner s = new Scanner(System.in);
@SuppressWarnings("unused")
private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };
////////////////////////////////////////////////////////////////////
public static void main(String[] args) throws IOException{
new Solution().solve();
s.close();
ww.close();
}
////////////////////////////////////////////////////////////////////
void solve() throws IOException{
int n = s.nextInt();
char[] a = s.nextString().toCharArray();
char[] b = s.nextString().toCharArray();
int[][] vis = new int[26][26];
int[] one = new int[26];
int total = 0;
for(int[] x : vis) Arrays.fill(x, -1);
Arrays.fill(one, -1);
for(int i=0;i<a.length;i++){
if(a[i] != b[i]){
vis[a[i]-'a'][b[i]-'a'] = i+1;
one[a[i]-'a'] = i+1;
total++;
}
}
for(int i=0;i<26;i++){
for(int j=i+1;j<26;j++){
if(vis[i][j] != -1 && vis[j][i] != -1){
ww.println(total-2);
ww.println(vis[i][j]+" "+vis[j][i]);
return;
}
}
}
for(int i=0;i<26;i++){
for(int j=0;j<26;j++){
if(vis[i][j] != -1 && one[j] != -1){
ww.println(total-1);
ww.println(vis[i][j]+" "+one[j]);
return;
}
}
}
ww.println(total);
ww.println("-1"+" "+"-1");
}
}
| Java | ["9\npergament\npermanent", "6\nwookie\ncookie", "4\npetr\negor", "6\ndouble\nbundle"] | 2 seconds | ["1\n4 6", "1\n-1 -1", "2\n1 2", "2\n4 1"] | NoteIn the second test it is acceptable to print iβ=β2, jβ=β3. | Java 7 | standard input | [
"greedy"
] | 2fa543c8b8f9dc500c36cf719800a6b0 | The first line contains integer n (1ββ€βnββ€β200β000) β the length of strings S and T. The second line contains string S. The third line contains string T. Each of the lines only contains lowercase Latin letters. | 1,500 | In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S. In the second line, either print the indexes i and j (1ββ€βi,βjββ€βn, iββ βj), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters. If there are multiple possible answers, print any of them. | standard output | |
PASSED | cd6f17bae5d9aeacee09e43ddffb89c7 | train_000.jsonl | 1426610700 | Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.Help him do this! | 256 megabytes | import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
public class Solution{
///////////////////////////////////////////////////////////////////////////
static class FastScanner{
BufferedReader s;
StringTokenizer st;
public FastScanner(InputStream InputStream){
st = new StringTokenizer("");
s = new BufferedReader(new InputStreamReader(InputStream));
}
public FastScanner(File f) throws FileNotFoundException{
st = new StringTokenizer("");
s = new BufferedReader (new FileReader(f));
}
public int nextInt() throws IOException{
if(st.hasMoreTokens())
return Integer.parseInt(st.nextToken());
else{
st = new StringTokenizer(s.readLine());
return nextInt();
}
}
public BigInteger big() throws IOException{
if(st.hasMoreTokens())
return new BigInteger(st.nextToken());
else{
st = new StringTokenizer(s.readLine());
return big();
}
}
public double nextDouble() throws IOException{
if(st.hasMoreTokens())
return Double.parseDouble(st.nextToken());
else{
st = new StringTokenizer(s.readLine());
return nextDouble();
}
}
public long nextLong() throws IOException{
if(st.hasMoreTokens())
return Long.parseLong(st.nextToken());
else{
st = new StringTokenizer(s.readLine());
return nextLong();
}
}
public String nextString() throws IOException{
if(st.hasMoreTokens())
return st.nextToken();
else{
st = new StringTokenizer(s.readLine());
return nextString();
}
}
public String readLine() throws IOException{
return s.readLine();
}
public void close() throws IOException{
s.close();
}
}
////////////////////////////////////////////////////////////////////
// Number Theory
long pow(long a,long b,long mod){
long x = 1; long y = a;
while(b > 0){
if(b % 2 == 1){
x = (x*y);
x %= mod;
}
y = (y*y);
y %= mod;
b /= 2;
}
return x;
}
int divisor(long x,long[] a){
long limit = x;
int numberOfDivisors = 0;
for (int i=1; i < limit; ++i) {
if (x % i == 0) {
limit = x / i;
if (limit != i) {
numberOfDivisors++;
}
numberOfDivisors++;
}
}
return numberOfDivisors;
}
void findSubsets(int array[]){
long numOfSubsets = 1 << array.length;
for(int i = 0; i < numOfSubsets; i++){
@SuppressWarnings("unused")
int pos = array.length - 1;
int bitmask = i;
while(bitmask > 0){
if((bitmask & 1) == 1)
// ww.print(array[pos]+" ");
bitmask >>= 1;
pos--;
}
// ww.println();
}
}
public static long gcd(long a, long b){
return b == 0 ? a : gcd(b,a%b);
}
public static long lcm(int a,int b, int c){
return lcm(lcm(a,b),c);
}
public static long lcm(long a, long b){
return (a*b/gcd(a,b));
}
public static long invl(long a, long mod) {
long b = mod;
long p = 1, q = 0;
while (b > 0) {
long c = a / b;
long d;
d = a;
a = b;
b = d % b;
d = p;
p = q;
q = d - c * q;
}
return p < 0 ? p + mod : p;
}
////////////////////////////////////////////////////////////////////
// FastScanner s = new FastScanner(new File("input.txt"));
// PrintWriter ww = new PrintWriter(new FileWriter("output.txt"));
static InputStream inputStream = System.in;
static FastScanner s = new FastScanner(inputStream);
static OutputStream outputStream = System.out;
static PrintWriter ww = new PrintWriter(new OutputStreamWriter(outputStream));
// private static Scanner s = new Scanner(System.in);
@SuppressWarnings("unused")
private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };
////////////////////////////////////////////////////////////////////
public static void main(String[] args) throws IOException{
new Solution().solve();
s.close();
ww.close();
}
////////////////////////////////////////////////////////////////////
void solve() throws IOException{
int n = s.nextInt();
char[] a = s.nextString().toCharArray();
char[] b = s.nextString().toCharArray();
int[][] vis = new int[26][26];
int[] one = new int[26];
int total = 0;
for(int[] x : vis) Arrays.fill(x, -1);
Arrays.fill(one, -1);
for(int i=0;i<a.length;i++){
if(a[i] != b[i]){
vis[a[i]-'a'][b[i]-'a'] = i+1;
one[a[i]-'a'] = i+1;
total++;
}
}
for(int i=0;i<26;i++){
for(int j=0;j<26;j++){
if(vis[i][j] != -1 && vis[j][i] != -1){
ww.println(total-2);
ww.println(vis[i][j]+" "+vis[j][i]);
return;
}
}
}
for(int i=0;i<26;i++){
for(int j=0;j<26;j++){
if(vis[i][j] != -1 && one[j] != -1){
ww.println(total-1);
ww.println(vis[i][j]+" "+one[j]);
return;
}
}
}
ww.println(total);
ww.println("-1"+" "+"-1");
}
}
| Java | ["9\npergament\npermanent", "6\nwookie\ncookie", "4\npetr\negor", "6\ndouble\nbundle"] | 2 seconds | ["1\n4 6", "1\n-1 -1", "2\n1 2", "2\n4 1"] | NoteIn the second test it is acceptable to print iβ=β2, jβ=β3. | Java 7 | standard input | [
"greedy"
] | 2fa543c8b8f9dc500c36cf719800a6b0 | The first line contains integer n (1ββ€βnββ€β200β000) β the length of strings S and T. The second line contains string S. The third line contains string T. Each of the lines only contains lowercase Latin letters. | 1,500 | In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S. In the second line, either print the indexes i and j (1ββ€βi,βjββ€βn, iββ βj), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters. If there are multiple possible answers, print any of them. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.