exec_outcome stringclasses 1 value | code_uid stringlengths 32 32 | file_name stringclasses 111 values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18 values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1 value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27 values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k β | lang stringclasses 5 values | prob_desc_input_from stringclasses 3 values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k β | difficulty int64 -1 3.5k β | prob_desc_output_spec stringlengths 17 1.47k β | prob_desc_output_to stringclasses 3 values | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 31a19b11c9b85ef70243f05433344723 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | /***************************/
/* AUTHOR: shriman_chetan */
/* NAME: chetan raikwar */
/* DATE: 02/09/2019 */
/***************************/
import java.util.*;
public class Solution {
static int[][] matrix;
public static void main(String[] args) {
try(Scanner in = new Scanner(System.in)) {
int n = in.nextInt();
matrix = new int[n][n];
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
matrix[i][j] = in.nextInt();
System.out.println( getGoodSum(n) );
}
}
/* checks if given matrix index is valid */
static boolean isValidIndex(int row, int col, int n) {
return (row >= 0 && row < n) && (col >= 0 && col < n);
}
/* returns sum of all good matrix elements */
static Integer getGoodSum(int n) {
int center = n/2;
int sum = matrix[center][center]; // central element
// move in all 8 direction simultaneously
for(int i=1; i<n; i++) {
// north
sum = isValidIndex(center-i, center, n) ? sum + matrix[center-i][center] : sum;
// north east
sum = isValidIndex(center-i, center+i, n) ? sum + matrix[center-i][center+i] : sum;
// east
sum = isValidIndex(center, center+i, n) ? sum + matrix[center][center+i] : sum;
// south east
sum = isValidIndex(center+i, center+i, n) ? sum + matrix[center+i][center+i] : sum;
// south
sum = isValidIndex(center+i, center, n) ? sum + matrix[center+i][center] : sum;
// south west
sum = isValidIndex(center+i, center-i, n) ? sum + matrix[center+i][center-i] : sum;
// west
sum = isValidIndex(center, center-i, n) ? sum + matrix[center][center-i] : sum;
// north west
sum = isValidIndex(center-i, center-i, n) ? sum + matrix[center-i][center-i] : sum;
}
return sum;
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 31aacdd780f49a4f83177499490d65a9 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes |
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Quan
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[][] a = new int[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
a[i][j] = sc.nextInt();
}
int sum = 0;
for (int i = 0; i < n; i++) {
sum=sum+a[i][i]+a[i][n-1-i]+a[(n-1)/2][i]+a[i][(n-1)/2];
}
sum=sum-3*a[(n-1)/2][(n-1)/2];
System.out.println(sum);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | b33f48d5b0b55ced460833a9089915b6 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Main
{
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());
int[][] arr=new int[n][n];
int sum=0;
for(int i=0;i<n;i++)
{
String[] str=br.readLine().split(" ");
for(int j=0;j<n;j++)
{
arr[i][j]=Integer.parseInt(str[j]);
if(i==j)
sum+=arr[i][j];
if(i+j==n-1)
sum+=arr[i][j];
}
}
for(int i=0;i<n;i++)
{
sum+=arr[n/2][i];
sum+=arr[i][n/2];
}
sum=sum-(3*arr[n/2][n/2]);
bw.write(sum+"\n");
bw.flush();
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | ddbfea8e79e667cb7ac43e4371af26d7 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes |
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author anhnth37
*/
public class A2_0177 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int r = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int a = input.nextInt();
if (i == n / 2 || j == n / 2 || i == j || j == n - i - 1) {
r += a;
}
}
}
System.out.println(r);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 212c6647cc400212dc7cb230c70de3fb | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.io.*;
import java.util.*;
import java.lang.*;
public class Rextester{
public static void main(String[] args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = new Integer(br.readLine());
int count=0;
int x=0;
int[][] matrix = new int[n][n];
for(int i=0;i<n;i++){
StringTokenizer st = new StringTokenizer(br.readLine());
for(int j=0;j<n;j++){
matrix[i][j]=new Integer(st.nextToken());
if(i==n/2){
x+=matrix[i][j];
}
}
}
br.close();
for(int i=0;i<n;i++){
count+=matrix[i][i]+matrix[i][n-i-1]+matrix[i][n/2];
}
count+=x;
System.out.println((count-3*matrix[n/2][n/2]));
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 92b157c676de1a36df3c540284a24b99 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution{
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m[][] = new int[n][n];
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
m[i][j] = sc.nextInt();
}
}
int s=0;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i == j)
s += m[i][j];
if((i+j) == (n-1))
s += m[i][j];
if(i == n/2)
s += m[i][j];
if(j == n/2)
s += m[i][j];
}
}
s -= (m[n/2][n/2] * 3);
System.out.println(s);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | be867800269fa371f42a732d5e97d847 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.io.*;
import java.util.*;
public class A {
FastScanner in;
PrintWriter out;
void solve() {
int t = in.nextInt();
int sum=0;
for(int i=0;i<t;i++) {
for(int j=0;j<t;j++) {
int x = in.nextInt();
if(i==j)sum+=x;
else if(i+j==t-1)sum+=x;
else if(i==t/2)sum+=x;
else if(j==t/2)sum+=x;
}
}
out.print(sum);
}
public static void main(String[] args) {
new A().runIO();
}
void run() {
try {
in = new FastScanner(new File("A.in"));
out = new PrintWriter(new File("A.out"));
solve();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
void runIO() {
in = new FastScanner(System.in);
out = new PrintWriter(System.out);
solve();
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());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 188a31837c4c7e04d8ada1ab00c092da | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class chapter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int count = 0;
boolean matched = false;
int[][] matrix = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
matrix[i][j] = sc.nextInt();
}
}
int subCount = 0;
if (n != 1) {
for (int i = 0; i < matrix.length; i++) {
subCount += matrix[i][i];
for (int j = 0; j < n; j++) {
if (i == n - j - 1) {
subCount += matrix[i][j];
}
}
subCount += matrix[i][n / 2];
subCount += matrix[n / 2][i];
}
System.out.println(subCount - (3 * matrix[n / 2][n / 2]));
} else {
System.out.println(matrix[0][0]);
}
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | e9654f49625e63f66088855e24e7234a | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes |
import java.io.*;
import java.util.*;
public class q6cp101{
public static void main(String[] args) {
MyScanner in = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int n=in.nextInt();
int sol=0;
int mat[][]= new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
mat[i][j]=in.nextInt();
}
}
int z=n-1;
for (int i = 0; i < n; i++) {
sol+=mat[i][i]+mat[i][z]+mat[(n-1)/2][i]+mat[i][(n-1)/2];
z--;
}
sol-=(3*mat[(n-1)/2][(n-1)/2]);
out.print(sol);
out.close();
}
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
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 | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 4e02a346c50b19f8650771d700ae8c2b | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | //package codeforces;
import java.util.Scanner;
public class GoodElements {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int[][] matrix = new int[N][N];
int sum = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
matrix[i][j] = scanner.nextInt();
}
}
for (int i = 0; i < N; i++) {
sum = sum + matrix[i][i] + matrix[i][N-1-i] + matrix[i][(N-1)/2]+matrix[(N-1)/2][i];
}
System.out.println(sum - 3*matrix[(N-1)/2][(N-1)/2]);
scanner.close();
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 556c71cb793e374ea952dcf36af08df0 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class Sample {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m[][] = new int[n][n];
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
m[i][j] = sc.nextInt();
}
}
int s = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(i == j || i + j == n-1 || i == n/2 || j == n/2) {
s += m[i][j];
}
}
}
System.out.println(s);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 58e6b1e8e27bd349b967fa7190f7520e | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static StringBuilder data=new StringBuilder();
final static FastReader in = new FastReader();
public static void main(String[] args) {
int n=in.nextInt();
int [][]a= new int[n][n];
int answ=0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
a[i][j]=in.nextInt();
}
}
for (int i = 0,l=0,r=n-1; i < n; i++,l++,r--) {
answ+=a[i][l]+a[i][r]+a[i][n/2];
if(i==n/2){
for (int j = 0; j < n; j++) {
answ+=a[i][j];
}
}
}
System.out.println(answ-(a[n/2][n/2]*3));
}
static void fileOut(String s) {
File out = new File("output.txt");
try {
FileWriter fw = new FileWriter(out);
fw.write(s);
fw.flush();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
public FastReader(String path) {
try {
br = new BufferedReader(new
InputStreamReader(new FileInputStream(path)));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
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());
}
float nextFloat() {
return Float.parseFloat(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 1254fdb7fe02418c6e4e00b067a72e97 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author 404-NOTFOUND
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
A1GoodMatrixElements solver = new A1GoodMatrixElements();
solver.solve(1, in, out);
out.close();
}
static class A1GoodMatrixElements {
public void solve(int testNumber, FastScanner in, PrintWriter out) {
int n = in.nextInt();
int t[][] = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
t[i][j] = in.nextInt();
}
}
int sum = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j || j == n - i - 1) {
sum += t[i][j];
} else if (i == n / 2 || j == n / 2) {
sum += t[i][j];
}
}
}
out.println(sum);
}
}
static class FastScanner {
private final InputStream stream;
private final byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastScanner(InputStream stream) {
this.stream = stream;
}
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++];
}
boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public int nextInt() {
return Integer.parseInt(next());
}
public String next() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 809e656848e9088e7b1816b20752686d | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 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[][] x=new int[n][n];
int all = 0;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
x[i][j] = sc.nextInt();
for(int j=0;j<n;j++) {
all+=x[n/2][j];
all+=x[j][n/2];
all+=x[j][j];
all+=x[n-1-j][j];
}
all-=3*x[n/2][n/2];
System.out.println(all);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | a668f582b35d5fed04de1e298061f6f9 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class GoodMatrix {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[][] matrix = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
matrix[i][j] = sc.nextInt();
}
}
int total = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if(i == j) {
total += matrix[i][j];
matrix[i][j] = 0;
}
if(i == n - 1 -j) {
total += matrix[i][j];
matrix[i][j] = 0;
}
if(i == n/2) {
total += matrix[i][j];
matrix[i][j] = 0;
}
if(j == n/2) {
total += matrix[i][j];
matrix[i][j] = 0;
}
}
}
System.out.println(total);
sc.close();
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 4aefc5bb74308d760ef6c51684aa439a | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class GoodMatrixElements_177A1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int sum = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int a = input.nextInt();
if (i == j || i == n / 2 + 1 || j == n / 2 + 1 || i + j == n + 1) {
sum += a;
}
}
}
System.out.println(sum);
input.close();
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 11cdca17573e5543d0cb60a588bc3a14 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class AntonIMnogogranniki {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int i, j, n = in.nextInt(),a[][];
a = new int[n+1][n+1];
if(n == 1) {
a[1][1] = in.nextInt();
System.out.println(a[1][1]);
return;
}
for(i = 1;i<=n;i++) {
for(j = 1;j<=n;j++) {
a[i][j] = in.nextInt();
}
}
long sum = 0;
for(i = 1;i<=n;i++) {
sum+=(a[n/2+1][i]+a[i][n/2+1]+a[i][i]+a[i][n-i+1]);
}
sum-=(3*a[n/2+1][n/2+1]);
System.out.println(sum);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | efab0499b095b2aa975a1d5960d00372 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class CodeForces
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[][] array = new int[n][n];
for (int i = 0; i < array.length; i++)
{
for (int j = 0; j < array[0].length; j++)
{
array[i][j] = input.nextInt();
}
}
boolean[][] check = new boolean[n][n];
for (int i = 0; i < array.length; i++)
{
for (int j = 0; j < array[0].length; j++)
{
if (i == j)
{
check[i][j] = true;
}
if (i + j == n - 1)
{
check[i][j] = true;
}
if (i == (n - 1) / 2)
{
check[i][j] = true;
}
if (j == (n - 1) / 2)
{
check[i][j] = true;
}
}
}
int sum = 0;
for (int i = 0; i < array.length; i++)
{
for (int j = 0; j < array[0].length; j++)
{
if (check[i][j])
{
sum += array[i][j];
}
}
}
System.out.println(sum);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 57a8260a157f5b7430798653abcb7b0a | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 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 v = 0;
int answer = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
v = sc.nextInt();
if (i == n / 2 || j == n / 2) {
answer += v;
} else if (i == j || i == n - 1 - j) {
answer += v;
}
}
}
sc.close();
System.out.println(answer);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 0e5c397dc94ec47ab6df525821270f27 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.*;
import java.lang.*;;
import java.io.*;
public class Codechef
{
public static void main (String[] args)
{
java.util.Scanner s=new java.util.Scanner(System.in);
// int t=s.nextInt();
int t=1;
while(t-->0)
{
int n=s.nextInt();
int A[][]=new int [n][n];
int S=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
A[i][j]=s.nextInt();
if(i==j)
S+=A[i][j];
else
if(j+i==n-1)
S+=A[i][j];
else
if(i==((n-1)/2))
S+=A[((n-1)/2)][j];
else
if(j==((n-1)/2))
S+=A[i][((n-1)/2)];
}
}
System.out.println(S);
}
}} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 39cd6a3851b9045cba1e0d7ef0e3cf55 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class GoodMatrixElement {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int p=n/2;
int[][] x=new int[n][n];
int sum=0,sum1=0,sum2=0,sum3=0;
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
x[i][j]=sc.nextInt();
// sum1=sum1+x[i][p];
// sum2=sum2+x[p][j];
// sum3=sum3+x[i][n-i];
// if(i==j) {
// sum=sum+x[i][j];
// }
}
}
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
// sum4=sum4+x[i][j];
if(i==j) {
sum=sum+x[i][j];
}
if(j==p) {
sum1=sum1+x[i][p];
}
if(i==p) {
sum2=sum2+x[p][j];
}
if(j==((n-1)-i)) {
sum3=sum3+x[i][(n-1)-i];
}
}
}
int z=x[p][p]*3;
int sum5=sum+sum1+sum2+sum3;
sum5=sum5-z;
System.out.println(sum5);
sc.close();
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | d9fb7a1fcbef45fb8fd844c36b3f679a | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.*;
public class Fafa{
public static void main(String[] args){
int n,c=0;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
int[][] ar=new int[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
ar[i][j]=sc.nextInt();
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if((i==(n-1)/2)||(i==j))
c=c+ar[i][j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if((i==(n-1)/2)&&i!=j||((i+j)==n-1)&&i!=j)
c=c+ar[j][i];
}
}
System.out.println(c);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | bd0eb5816deb7e180020e0d9eb07f473 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class GoodMatrix{
public static void main(String arg[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[][]=new int[n][n];
int c=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
a[i][j]=sc.nextInt();
if(i==j||i==n/2||j==n/2||i+j==n-1)
c=c+a[i][j];
}
}
System.out.println(c);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | fb87adef7e36e854f3fbeeb83be7ca40 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner s1= new Scanner(System.in);
int n=s1.nextInt();
int a[][]= new int[n][n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
a[i][j]=s1.nextInt();
}
}
int s=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==j)
{
s+=a[i][j];
}
if(i+j==n-1)
{
s+=a[i][j];
}
if(i<n && j==n/2)
{
s+=a[i][j];
}
if(j<n && i==n/2)
{
s+=a[i][j];
}
}
}
int c=a[n/2][n/2];
System.out.println(s-(c*3));
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | d8d6059f5a8730bbeb13b6469931280d | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.*;
public class A1_177 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int sum = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
int a = sc.nextInt();
if (i == j || i == n - 1 - j || i == n/2 || j == n/2)
sum += a;
}
System.out.print(sum);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 44f0f4bdbde7ca352f367262c9a079f3 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class A10177_Matrix {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[][] a = new int[n][n];
int points = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = scan.nextInt();
if (i == j || i == n / 2 || j == n / 2 || (i + j) == n - 1) {
points += a[i][j];
}
}
}
System.out.println(points);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 5ee49e1462374bbbefa8cc51ef21f286 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.*;
import java.io.*;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[][] mat = new int[n][n];
int sum = 0;
for(int i = 0; i < n; i++){
for(int j =0; j < n; j++){
mat[i][j] = sc.nextInt();
}
}
int x = 0;
int y = n-1;
while(x <= n-1){
sum += mat[x][x];
sum +=mat[x][y];
x++;
y--;
}
x = n/2; y = n/2;
int itr = 0;
while(itr <= n-1){
sum += mat[x][itr];
sum += mat[itr][y];
itr++;
}
sum -= (3*mat[n/2][n/2]);
System.out.println(sum);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 6aff1edde1a23af9d0c9cf3e2e11923c | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;
import javafx.scene.Node;
public class JavaApplication3 {
public static void main(String[] args) {
int x;
//int y;
Scanner in = new Scanner(System.in);
x=in.nextInt();
//y=in.nextInt();
int [][] m = new int [x][x];
int c=0;
// int []a1 = new int[x];
// int []a2 = new int[y];
// ArrayList<Integer> a = new ArrayList<Integer>();
for(int i=0; i<x; i++){
for(int j=0; j<x; j++){
m[i][j]=in.nextInt();
if(i==j) c+=m[i][j];
if(i+j==x-1) c+=m[i][j];
if(i==(x-1)/2 || j==(x-1)/2) c+=m[i][j];
}
}
c-=m[(x-1)/2][(x-1)/2]*2;
System.out.println(c);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | f7d96374701ce816ad47491a909242da | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | //package src;
import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Stack;
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.lang.StringBuilder;
public class idk {
static Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method stub
// String str=scn.next();
// HashMap<Character,Integer>map=new HashMap<Character, Integer>();
int n=scn.nextInt();
long sum=0;
int arr[][]=new int[n][n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
arr[i][j]=scn.nextInt();
}
}
boolean bl[][]=new boolean[n][n];
for(int i=0;i<n;i++)
{
bl[n/2][i]=true;
bl[i][n/2]=true;
}
for(int i=0,j=0;i<n&&j<n;i++,j++)
{
bl[i][j]=true;
}
for(int i=0,j=n-1;i<n&&j>=0;i++,j--)
{
bl[i][j]=true;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(bl[i][j])
sum+=arr[i][j];
}
}
System.out.println(sum);
}
public static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
public static String rev(String str) {
int n = str.length();
char ch[] = str.toCharArray();
char temp = ' ';
for (int i = 0; i < n / 2; i++) {
temp = ch[i];
ch[i] = ch[n - i - 1];
ch[n - i - 1] = temp;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++)
sb.append(ch[i]);
return sb.toString();
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | f085c7c87252c96d46655797555a70e1 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.*;
public class mohammad{
public static void main(String args[]){
Scanner U = new Scanner(System.in);
int t = U.nextInt();
int[][] a= new int[t][t];
for(int i=0 ; i<t ; i++)
for(int j=0 ; j<t ; j++)
a[i][j]= U.nextInt();
int sum = 0;
for(int i=0 ; i<t ; i++)
for(int j=0 ; j<t ; j++){
if(i==j || (i+j)==(t-1) || i==(t-1)/2 ||j==(t-1)/2)
sum+=a[i][j];
}
System.out.println(sum);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | f60c9d615515288fb648ba864e460e92 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String... args) {
Scanner in = new Scanner(System.in);
int sum = 0;
int n = in.nextInt();
int [][] arr = new int[n][n];
for(int i =0;i<n;i++){
for(int j=0;j<n;j++){
arr[i][j] = in.nextInt();
if(i==j || i==(n-1)/2 || j==(n-1)/2 || (i+j)==n-1) sum+=arr[i][j];
}
}
System.out.println(sum);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | f0601dedea1f6a64a43770df6fbd025e | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.*;
import java.io.*;
public class CF177A2
{
public static void main (String[]args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int m = ((n-1)/2) + 1;
int ans = 0;
for(int i = 1, c = n ; i <= n; i++,c--){
StringTokenizer st = new StringTokenizer(br.readLine());
for(int j = 1;j <= n; j++){
int x = Integer.parseInt(st.nextToken());
if(i == j || j == c || i == m || j == m)
ans += x;
}
}
System.out.println(ans);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 83262b7363490cf0f88c1b7327ea104a | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class Mo {
public static void main(String[] args) {
Scanner sc= new Scanner (System.in);
int n= sc.nextInt();
int x= 0;
int[][]arr=new int[n][n];
for (int i=0; i<n; i++){
for (int j=0; j<n; j++)
arr[i][j]=sc.nextInt();
}
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
if(i==j)
x+=arr[i][j];
else if(i==(n-1)/2)
x+=arr[i][j];
else if(j==(n-1)/2)
x+=arr[i][j];
else if(i+j==n-1)
x+=arr[i][j];
}
}
System.out.print(x);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 769c92652802ffb2c8cf52f445b72778 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
import java.util.stream.Stream;
public class GoodMatrixElements {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt(),res=0;
sc.nextLine();
int[][] matrix=new int[n][n];
for (int i = 0; i < n; i++) {
int[] temp= Stream.of(sc.nextLine().trim().split(" ")).mapToInt(Integer::parseInt).toArray();
matrix[i]=temp;
}
for (int i = 0; i < n; i++) {
res+=matrix[i][i];
matrix[i][i]=0;
res+=matrix[i][n-i-1];
matrix[i][n-i-1]=0;
int h=(n-1)/2;
res+=matrix[i][h];
matrix[i][h]=0;
res+=matrix[h][i];
matrix[h][i]=0;
}
System.out.println(res);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 685f6e1b35cdcc0da970efcb0095353c | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.*;
public class P177A2 {
public static void main(String [] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int input;
int mid = (n - 1) / 2;
int total = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
input = in.nextInt();
if (i == mid || j == mid) {
total += input;
}
else if (i == j ) {
total += input;
}
else if (i + j == n - 1) {
total += input;
}
}
}
System.out.println(total);
in.close();
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | ede4b6a12c6331985a4cec3c46ffce2a | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.*;
public class Solution
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[][] mat=new int[n][n];
int[][] marked=new int[n][n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
mat[i][j]=sc.nextInt();
}
}
int sum=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(marked[i][j]!=1)
{
if(i==j)
{
sum+=mat[i][j];
marked[i][j]=1;
}
else if(i+j==n-1)
{
sum+=mat[i][j];
marked[i][j]=1;
}
else if(i==(n-1)/2)
{
sum+=mat[i][j];
marked[i][j]=1;
}
else if(j==(n-1)/2)
{
sum+=mat[i][j];
marked[i][j]=1;
}
}
}
}
System.out.println(sum);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 361d31b818a88900ea53491330f59513 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class A177 {
void go(Scanner s) {
int N = s.nextInt(), t = 0;
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++) {
boolean ok = false;
ok |= i == N / 2;
ok |= j == N / 2;
ok |= i == j;
ok |= i + j == N - 1;
t += ok ? s.nextInt() : s.nextInt() * 0;
}
System.out.println(t);
}
public static void main(String[] args) { new A177().go(new Scanner(System.in)); }
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 6797e67deb2f9fc8ef1a13a965c50372 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 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 sum = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int a = sc.nextInt();
if(i == j || j == n - i - 1 || i == n/2 || j == n/2) {
sum += a;
}
}
}
System.out.println(sum);
sc.close();
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 54382cf95a1d94bab706a6785bcd4d81 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class Trans {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bf.readLine());
int [][]arr=new int[n][n];
int sum=0;
int mid=(n-1)/2;
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
StringTokenizer tk;
for (int i = 0; i < n; i++) {
tk=new StringTokenizer(bf.readLine());
for (int j = 0; j < n; j++) {
arr[i][j]=Integer.parseInt(tk.nextToken());
if(j==mid || i==mid)sum+=arr[i][j];
}
}
int i=0;
int j=0;
while(true){
sum+=arr[i][j];
i+=1;
j+=1;
if(j>n-1 && i>n-1)break;
}
i=0;
j=n-1;
while(true){
sum+=arr[i][j];
i+=1;
j-=1;
if(i>n-1 && j<0)break;
}
int v=arr[mid][mid];
pw.write(sum-2*v+"\n");
pw.flush();
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | a479460b35433cc71a9d9d5fe94ed202 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes |
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int ar[][] = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
ar[i][j] = scan.nextInt();
}
}
int t=0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (n / 2 == j) {
t += ar[i][j];
}
else if (n / 2 == i) {
t += ar[i][j];
}
else if (i == j) {
t += ar[i][j];
}
else if(i + j == n-1) {
t += ar[i][j];}
// System.out.print(" (i "+i + ") j"+" "+j);
}
System.out.println();
}
System.out.println(t);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | bdbcb57c308e98b8eeee7f1b19c0b58e | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class GoodMatrixElements {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int matrixSize = scanner.nextInt();
int[][] matrix = new int[matrixSize][matrixSize];
int sum = 0;
int val = 0;
for (int a = 0; a < matrix.length; a++) {
for (int b = 0; b < matrix[0].length; b++) {
val = scanner.nextInt();
if (a == b) {
sum += val;
val = 0;
}
if (a == matrixSize/2 || b == matrixSize/2) {
sum+= val;
val = 0;
}
if (a + b == matrixSize - 1) {
sum+= val;
}
}
}
System.out.println(sum);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 5b81dceeee65f23235c46f9958b41f01 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class AA {
static Random random;
private static void mySort(int[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
int t = s[i];
s[i] = s[j];
s[j] = t;
}
Arrays.sort(s);
}
public static void main(String[] args) {
random = new Random(543534151132L + System.currentTimeMillis());
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
int nb=in.nextInt();
int count=0;
for(int i=0;i<nb;i++) {
for(int j=0;j<nb;j++) {
if(i==j || j==nb-i-1 || i==(nb-1)/2 || j==(nb-1)/2) {
count+=in.nextInt();
}else in.nextInt();
}
}
out.println(count);
out.close();
}
public static int gcd(int a, int b)
{
BigInteger b1 = BigInteger.valueOf(a);
BigInteger b2 = BigInteger.valueOf(b);
BigInteger gcd = b1.gcd(b2);
return gcd.intValue();
}
public static long gcd(long a, long b)
{
BigInteger b1 = BigInteger.valueOf(a);
BigInteger b2 = BigInteger.valueOf(b);
BigInteger gcd = b1.gcd(b2);
return gcd.longValue();
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public float nextFloat() {
return Float.parseFloat(next());
}
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 4fedee80718807e2c07f37f77aa5bd1f | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class Pr1 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int a[][] = new int[n][n];
int sum=0;
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
a[i][j] =in.nextInt();
}
}
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
if(i==j){
sum+=a[i][j];
}
else if ((n-1)==(i+j)){
sum+=a[i][j];}
else if (i==((n-1)/2) ) {
sum+=a[(n-1)/2] [j];
}
else if (j==((n-1)/2) ){
sum+=a[i][(n-1)/2];
}}}
System.out.print(sum);}} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | c0cf549f4e3c17e1d2bb88a6a67178be | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.*;
public class Prog177A2{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int sum=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
int cur=sc.nextInt();
if(i==j||i==n/2+1||j==n/2+1||i+j==n+1){
sum=sum+cur;
}
}
}
System.out.println(sum);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 4dc0befcfb9a950db3944723259eac69 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | /************************
* author:pritesh_808****
* future hndrxx ********
* *********************
* *********************
* *********************
* *********************
* *********************
*****************************/
/*********************
* * gang-gang********
* *******************
* *******************
* *******************
* ***EVOL************
* *******************
*********************/
import java.lang.*;
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Map<Character,Integer>hashmap=new HashMap();
List<ArrayList<Long>>list=new ArrayList();
Scanner scanner=new Scanner(System.in);
long T;
T=1;
for(long test_case=0;test_case<T;test_case++) {
long ans_real=0, arr[][];
int n=scanner.nextInt();
arr=new long[n][n];
int vis[][]=new int[n][n];
for(int sm=0;sm<n;sm++)
for(int h=0;h<n;h++)
vis[sm][h]=0;
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
arr[i][j]=scanner.nextLong();
if(vis[i][j]==0 &&i==j)
{
vis[i][j]=1;
ans_real+=arr[i][j];
}
if(vis[i][j]==0 &&j==n-1-i)
{
vis[i][j]=1;
ans_real+=arr[i][j];
}
if(vis[i][j]==0 &&j==n/2)
{
vis[i][j]=1;
ans_real+=arr[i][j];
}
if(vis[i][j]==0 &&i==n/2)
{
vis[i][j]=1;
ans_real+=arr[i][j];
}
}
}
System.out.println(ans_real);
}
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | f40a0d6b3d4179cf6cedd63fb2d55e37 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.*;
public class GoodMatrixElements1{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m[][] = new int[n][n];
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
m[i][j] = scan.nextInt();
}
}
int sum = 0;
for(int i=0,j=0;i<n&&j<n;i++,j++){
sum += m[i][j];
}
for(int i=0,j=n-1;i<n&&j>=0;i++,j--){
if(i==n/2&&j==n/2){
continue;
}
sum += m[i][j];
}
for(int i=n/2,j=0;j<n;j++){
if(i==n/2&&j==n/2){
continue;
}
sum += m[i][j];
}
for(int i=0,j=n/2;i<n;i++){
if(i==n/2&&j==n/2){
continue;
}
sum += m[i][j];
}
System.out.println(sum);scan.close();
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 4dd5d5b4f63510c495e09c5772a61c56 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
void solve (FastScanner in, PrintWriter out) {
int n = in.nextInt();
int[][] matrix = new int[n][n];
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) matrix[i][j] = in.nextInt();
}
int sum = 0;
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
if (i==n/2 || j==n/2 || i==j || n-i-1==j) {
sum += matrix[i][j];
}
}
}
out.println(sum);
}
void print (Object... ar) {
System.out.println(Arrays.deepToString(ar));
}
public static void main(String[] args) {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
Main main = new Main();
main.solve(in, out);
in.close();
out.close();
}
static class FastScanner {
private InputStream in;
private byte[] buffer = new byte[1024];
private int length = 0, p = 0;
public FastScanner (InputStream stream) {
in = stream;
}
public boolean hasNextByte () {
if (p < length) return true;
else {
p = 0;
try {length = in.read(buffer);}
catch (Exception e) {e.printStackTrace();}
if (length <= 0) return false;
}
return true;
}
public int readByte () {
if (hasNextByte() == true) return buffer[p++];
return -1;
}
public boolean isPrintable (int n) {return 33<=n&&n<=126;}
public void skip () {
while (hasNextByte() && !isPrintable(buffer[p])) p++;
}
public boolean hasNext () {skip(); return hasNextByte();}
public String next () {
if (!hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int t = readByte();
while (isPrintable(t)) {
sb.appendCodePoint(t);
t = readByte();
}
return sb.toString();
}
public String[] nextArray (int n) {
String[] ar = new String[n];
for (int i=0; i<n; i++) ar[i] = next();
return ar;
}
public int nextInt () {return Math.toIntExact(nextLong());}
public int[] nextIntArray (int n) {
int[] ar = new int[n];
for (int i=0; i<n; i++) ar[i] = nextInt();
return ar;
}
public long nextLong () {
if (!hasNext()) throw new NoSuchElementException();
boolean minus = false;
int temp = readByte();
if (temp == '-') {
minus = true;
temp = readByte();
}
if (temp<'0' || '9'<temp) throw new NumberFormatException();
long n = 0;
while (isPrintable(temp)) {
if ('0'<=temp && temp<='9') {
n *= 10;
n += temp - '0';
}
else throw new NumberFormatException();
temp = readByte();
}
return minus? -n : n;
}
public double nextDouble () {
return Double.parseDouble(next());
}
public void close () {
try {in.close();}
catch(Exception e){}
}
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 0e9156de78fa66520e1d1461ab42dc5c | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in Actual solution is at the top
*
* @author viatsko
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA2 solver = new TaskA2();
solver.solve(1, in, out);
out.close();
}
static class TaskA2 {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n = in.nextInt();
int[][] grid = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
grid[i][j] = in.nextInt();
}
}
int answer = 0;
int half = n / 2;
for (int i = 0; i < n; i++) {
if (i == half) {
answer += grid[half][half];
} else {
answer += grid[half][i] + grid[i][half] + grid[i][i] + grid[i][n - i - 1];
}
}
out.print(answer);
}
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | ea39ee52db928cb8d338b4250556a520 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes |
import java.util.Scanner;
import java.util.Arrays;
public class test
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int answer = 0;
for(int i = 0;i<n;i++)
{
for(int j = 0;j<n;j++)
{
int x = sc.nextInt();
if(i == n/2 || j == n/2 || i == j || (i+j) == n-1 )
{
answer += x;
}
}
}
System.out.println(answer);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 6c404e8b4d80b4db270e73c3428dda23 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.*;
import java.io.*;
public class Cf{
public static void main(String args[])throws Exception{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m[][]=new int[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
m[i][j]=sc.nextInt();
}
}
int s=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)
s+=m[i][j];
if((i+j)==(n-1)) s+=m[i][j];
if(i==n/2)s+=m[i][j];
if(j==n/2)
s+=m[i][j];
}
//System.out.println();
}
s-=(m[n/2][n/2]*3);
System.out.println(s);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 4c6ff88226776c90a4503c540c341099 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class GoodMatrixImplementation {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int k=sc.nextInt();
int[][] m=new int[k][k];
for(int i=0;i<k;i++){
for(int j=0;j<k;j++){
m[i][j]=sc.nextInt();
}}
int z=(k-1)/2;
int w=0;
for(int i=0;i<k;i++){
w=w+m[i][z]+m[z][i]+m[i][i]+m[i][k-1-i];
}
System.out.println(w-3*(m[z][z]));
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 07fda0b2f2bf8ae2ef68cef2c009398d | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class Matrix {
public static void main(String[] args) {
Scanner scanner = new Scanner (System.in);
int n = scanner.nextInt(),sum=0;
int [][] a;a=new int [n][n];
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
int x = scanner.nextInt();
a[i][j]=x;
}
}
for (int i=0;i<n;i++) {
sum+=a[n/2][i];
}
for (int i=0;i<n;i++) {
sum+=a[i][n/2];
}
for (int i=0;i<n;i++) {
sum+=a[i][i];
}
for (int i=0;i<n;i++) {
sum+=a[i][n-1-i];
}
int y = 3*a[n/2][n/2];
System.out.println(sum-y);
scanner.close(); }} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 80e5b168c369f099acdc4b13e4070718 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.*;
public class Problem12 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int[][] arr = new int[n][n];
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
arr[i][j]=sc.nextInt();
}
}
int mid=n/2;
int sum=0;
for(int u=0;u<n;u++) {
sum+=arr[u][mid];
sum+=arr[mid][u];
}
sum-=arr[mid][mid];
for(int w=0;w<n;w++) {
int temp=n-w-1;
sum+=arr[w][w];
sum+=arr[w][temp];
}
sum-=2*arr[mid][mid];
System.out.println(sum);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 8 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 9c78c6f5ec4ebd6c8b38e634feda31a2 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
public class A {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = null;
private void solution() throws IOException {
int n = nextInt();
boolean a[][]=new boolean [n][n];
int b[][]=new int [n][n];
long ans=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
b[i][j]=nextInt();
}
}
for(int i=0;i<n;i++){
a[i][i]=true;
}
for(int i=n-1;i>=0;i--){
a[i][n-1-i]=true;
}
if(n %2==1){
int z=(n-1)/2;
for(int i=0;i<n;i++){a[i][z]=true;}
for(int i=0;i<n;i++){a[z][i]=true;}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(a[i][j]){
ans+=b[i][j];
}
}
}
System.out.println(ans);
}
String nextToken() throws IOException {
if (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
public void print(int a[]) {
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}
public static void main(String args[]) throws IOException {
new A().solution();
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 6 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | a580d272517ce96b45c6e0567eeb3dda | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.io.*;
import java.util.*;
public class CodeForces {
public void solve() throws IOException {
int n = nextInt();
int arr[][] = new int[n][n];
for (int i = 0, l = arr.length; i < l; i++) {
for (int j = 0, m = arr.length; j < m; j++) {
arr[i][j] = nextInt();
}
}
int sum = 0;
if(n==1) {
sum=arr[0][0];
} else {
for (int i = 0, l = arr.length; i < l; i++) {
sum+=arr[i][i];
sum+=arr[l-i-1][i];
sum+=arr[n/2][i];
sum+=arr[i][n/2];
}
sum-=3*arr[n/2][n/2];
}
out.print(sum);
}
public static void main(String[] args) {
new CodeForces().run();
}
int NOD(int a, int b) {
while (a != 0 && b != 0) {
if (a >= b)
a = a % b;
else
b = b % a;
}
return a + b;
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter out;
boolean isOuterFile = false;
public void run() {
try {
if (isOuterFile) {
reader = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter(new BufferedWriter(new FileWriter(
"output.txt")));
} else {
reader = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
tokenizer = null;
// long t=new Date().getTime();
solve();
// writer.println(t-new Date().getTime());
reader.close();
out.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());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 6 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 6bc9e83739a31174eec738126ac4f5f1 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class GoodMatrixElements {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), i, j, sum = 0;
int a[][] = new int[n][n];
for(i = 0; i < n; i++) {
for(j = 0; j < n; j++) {
a[i][j] = sc.nextInt();
}
}
int mid = n / 2;
for(i = 0; i < n; i++) {
sum += a[i][i];
a[i][i] = 0;
sum += a[i][n-1-i];
a[i][n-1-i] = 0;
sum += a[mid][i];
a[mid][i] = 0;
sum += a[i][mid];
a[i][mid] = 0;
}
System.out.println(sum);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 6 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 60bb9a6e06b53b647574037b1f422175 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.awt.Point;
import java.io.*;
import java.util.Arrays;
public class Main{
public static void main(String[] args) throws Exception {
int n = nextInt();
int[][] a = new int[n][n];
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
a[i][j] = nextInt();
}
}
if(n == 1) exit(a[0][0]);
int ans = 0;
for(int i = 0, j = 0; i < n; i++, j++){
ans += a[i][j];
}
for(int i = 0, j = n - 1; i < n; i++, j--){
if(i == (n - 1) / 2) continue;
ans += a[i][j];
}
for(int i = 0, j = (n - 1) / 2; i < n; i++){
if(i == (n - 1) / 2) continue;
ans += a[i][j];
}
for(int i = 0, j = (n - 1) / 2; i < n; i++){
if(i == (n - 1) / 2) continue;
ans += a[j][i];
}
exit(ans);
}
private static PrintWriter out = new PrintWriter(System.out);;
private static BufferedReader inB = new BufferedReader(new InputStreamReader(System.in));
private static StreamTokenizer in = new StreamTokenizer(inB);
private static void exit(Object o) throws Exception {
out.println(o);
out.flush();
System.exit(0);
}
private static void println(Object o) throws Exception{
out.println(o);
out.flush();
}
private static void print(Object o) throws Exception{
out.print(o);
out.flush();
}
private static int nextInt() throws Exception {
in.nextToken();
return (int)in.nval;
}
private static String nextString() throws Exception {
in.nextToken();
return in.sval;
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 6 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 449d306bb80d220e716c43f7289a59f9 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class A2_177_Good_Matrix_Elements {
public static void main(String[] args){
Scanner input=new Scanner(System.in);
int n=input.nextInt();
int[][] num=new int[n][n];
int i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
num[i][j]=input.nextInt();
int count=0;
int med=(n-1)/2;
for(i=0;i<n;i++)
count=count+num[i][i];
for(i=0;i<n;i++)
count=count+num[i][n-i-1];
for(i=0;i<n;i++){
count=count+num[med][i];
count=count+num[i][med];
}
count=count-num[med][med]*3;
System.out.println(count);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 6 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | f4fd16a69e5565cdd9c394415a46fb3d | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes |
/**
* Write a description of class ABBYYA1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
public class ABBYYA1
{
public static void main(String args[])
{
Scanner S = new Scanner(System.in);
int n = S.nextInt();
int sum = 0;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
int x = S.nextInt();
if((i == n/2) || (j == n/2) || (i == j) || ((i + j) == n - 1))
sum += x;
}
}
System.out.println(sum);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 6 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 9c329ccedce1d86810dfb142a3323862 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
public class E {
private StreamTokenizer in;
private PrintWriter out;
public static void main (String[] args) throws IOException {
new E().soilve();
}
int nextInt () throws IOException {
in.nextToken();
return (int)in.nval;
}
void soilve () throws IOException {
in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
out = new PrintWriter(new OutputStreamWriter(System.out));
int n = nextInt();
int res = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int k = nextInt();
if (i == j || (i + j)==n-1 || (i == n/2) || (j == n/2)) {
res += k;
}
}
}
out.print(res);
out.flush();
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 6 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 8163d348f422bee47ec6fc694cdf5622 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class P177A {
public PrintWriter run() {
int n = sc.nextInt();
int sum = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int a = sc.nextInt();
if ((i == j) || (i == (n - j - 1)) ||
(i == ((n - 1) / 2)) || (j == ((n - 1) / 2))) {
sum += a;
}
}
}
pw.println(sum);
return pw;
}
private Scanner sc = new Scanner(new BufferedInputStream(System.in));
private PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
public static void main(String... args) throws Exception {
new P177A().run().close();
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 6 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | f45582f28d9369cd29eeace5bef2c707 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class A1 {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int result = 0;
for(int y = 0; y < n; y++)
for(int x = 0; x < n; x++)
{
int v = sc.nextInt();
if(isGood(x,y,n))
result += v;
}
System.out.println(result);
}
private static boolean isGood(int x, int y, int n) {
if(x == y) return true;
if(x == n - y - 1) return true;
if(2*x + 1 == n) return true;
if(2*y + 1 == n) return true;
return false;
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 6 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 6a270507d614588474fe0e7520021132 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author hheng
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA1 solver = new TaskA1();
solver.solve(1, in, out);
out.close();
}
}
class TaskA1 {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int N = in.nextInt();
int[][] mat = new int[N][N];
for (int i=0; i<N; i++) for (int j=0; j<N; j++) mat[i][j] = in.nextInt();
boolean[][] matbool = new boolean[N][N];
for (int i=0; i<N; i++) Arrays.fill(matbool[i], false);
for (int i=0; i<N; i++) matbool[i][i] = true;
for (int i=0, j=N-1; i<N; i++, j--) matbool[i][j] = true;
int c = (N-1)/2;
for (int i=0; i<N; i++) { matbool[i][c] = true; matbool[c][i] = true; }
int sum = 0;
for (int i=0; i<N; i++) for (int j=0; j<N; j++) if (matbool[i][j]) sum += mat[i][j];
out.println(sum);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 6 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | c9f14c758fd4c6c47a54887947e46f11 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author codeKNIGHT
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n=in.nextInt(),i,j;
int a[][]=new int[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=in.nextInt();
}
}
long c=0;
for(i=0;i<n;i++)
{
if(i==(n-1)/2)
continue;
c+=a[(n-1)/2][i];
c+=a[i][(n-1)/2];
}
//System.out.println(c);
int p=n;
for(i=0;i<n;i++)
{
p--;
if(i==(n-1)/2)
continue;
c+=a[i][i];
c+=a[i][p];
// System.out.println(c);
}
c+=a[(n-1)/2][(n-1)/2];
out.println(c);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 6 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 1636ddf103150f5a996cd9e1b2b72f83 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner r = new Scanner(System.in);
int n = r.nextInt();
int[][] a = new int[n][n];
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) a[i][j] = r.nextInt();
int c = 0;
int res = 0;
while (c < a.length && c < a[0].length) {
res += a[c][c++];
}
int row = 0;
int col = a[0].length - 1;
while (row < a.length && col >= 0) {
res += a[row++][col--];
}
int middleRow = n / 2;
for (int i = 0; i < a[0].length; i++) {
res += a[middleRow][i];
}
int middleCol = n / 2;
for (int i = 0; i < a.length; i++) {
res += a[i][middleCol];
}
System.out.println(res - a[middleRow][middleCol] * 3);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 6 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 3db4c6d2a540730bc7c1836ead044fb4 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.io.*;
import java.util.*;
public class GelMat{
public static void main(String[] args){
int n;// size of matrix
int sumEl=0;
int El=0;
int middle=0;
// System.out.println("Enter the range of matrix, it should be odd");
Scanner in=new Scanner(System.in);
n=in.nextInt();
while ((n%2)==0){
// System.out.println("The value should be odd");
n=in.nextInt();
};
middle=(n-1)/2+1;
int[][] SqMatrix=new int[n][n];
// System.out.println("Enter the matrix element");
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
El=in.nextInt();
while(!((El>=0)&&(El<=100))){
// System.out.println("Range should be between 0 and 100");
El=in.nextInt();
}
if((i==j)||(i==middle)||(j==middle)||(j==(n-i+1))){
sumEl+=El;
// System.out.println(i+" "+j);
}
}
}
System.out.println(sumEl);
}
} | Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 6 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 54817dcda0f17a7bc53d471d35d41e75 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;
import java.util.StringTokenizer;
public class P177A1 {
static int sum = 0;
static int n = -1;
static int[][] mat = null;
static Set<Pair> pset = new HashSet<Pair>();
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
n = Integer.parseInt(in.nextLine());
mat = new int[n][n];
for (int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(in.nextLine());
for (int k = 0; k < n; k++) {
mat[i][k] = Integer.parseInt(st.nextToken());
}
}
sumMid(); sumDiag();
System.out.println(sum);
}
static void sumMid() {
for (int i = 0; i < n; i++) {
Pair itried1 = new Pair(i, n / 2);
Pair itried2 = new Pair(n / 2, i);
if (!pset.contains(itried1)) {
sum += mat[i][n / 2];
pset.add(itried1);
}
if (!pset.contains(itried2)) {
sum += mat[n / 2][i];
pset.add(itried2);
}
}
}
static void sumDiag() {
for (int i = 0; i < n; i++) {
Pair itried1 = new Pair(i, i);
Pair itried2 = new Pair(n - i - 1, i);
if (!pset.contains(itried1)) {
sum += mat[i][i];
pset.add(itried1);
}
if (!pset.contains(itried2)) {
sum += mat[n - i - 1][i];
pset.add(itried2);
}
}
}
}
class Pair {
int a, b;
public Pair(int a, int b) {
this.a = a;
this.b = b;
}
public String toString() {
return "(" + a + ", " + b + ")";
}
public boolean equals(Object o) {
if (this == o) return true;
return a == ((Pair) o).a && b == ((Pair) o).b;
}
public int hashCode() {
return (a + 17 * b) % 1000;
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 6 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 283f2ba6672b0ca371a372db569b9156 | train_003.jsonl | 1335016800 | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an nβΓβn size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the "middle" row β the row which has exactly rows above it and the same number of rows below it. Elements of the "middle" column β the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5βΓβ5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. | 256 megabytes | import java.util.*;
public class cf177a {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[][] v = new int[n][n];
int[][] w = new int[n][n];
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
w[i][j] = in.nextInt();
for(int i=0; i<n; i++)
v[i][i] = v[n-i-1][i] = 1;
if(n%2 == 1) for(int i=0; i<n; i++)
v[i][n/2] = v[n/2][i] = 1;
int ans = 0;
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
ans += v[i][j]*w[i][j];
System.out.println(ans);
}
}
| Java | ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"] | 2 seconds | ["45", "17"] | NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | Java 6 | standard input | [
"implementation"
] | 5ebfad36e56d30c58945c5800139b880 | The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0ββ€βaijββ€β100) separated by single spaces β the elements of the given matrix. The input limitations for getting 30 points are: 1ββ€βnββ€β5 The input limitations for getting 100 points are: 1ββ€βnββ€β101 | 800 | Print a single integer β the sum of good matrix elements. | standard output | |
PASSED | 7f906309e6f1caae78af4d8914733dd7 | train_003.jsonl | 1366903800 | Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero (β<β0). The product of all numbers in the second set is greater than zero (β>β0). The product of all numbers in the third set is equal to zero. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. | 256 megabytes | import java.util.*;
import java.math.BigInteger;
public class sol{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int a[]=new int[n];
int e=0,p=0,z=0;
Stack<Integer> neg=new Stack<Integer>();
Stack<Integer> pos=new Stack<Integer>();
Stack<Integer> zero=new Stack<Integer>();
for(int i=0;i<n;i++)
{
a[i]=s.nextInt();
Integer q=new Integer(a[i]);
if(a[i]<0)
neg.add(q);
else if(a[i]>0)
pos.add(q);
else
zero.add(q);
}
if(neg.size()%2==0)
{
zero.add(neg.pop());
}
if(pos.size()==0)
{
pos.add(neg.pop());
pos.add(neg.pop());
}
System.out.print(neg.size()+" ");
for(Integer i:neg)
System.out.print(i+" ");
System.out.println("");
System.out.print(pos.size()+" ");
for(Integer i:pos)
System.out.print(i+" ");
System.out.println("");
System.out.print(zero.size()+" ");
for(Integer i:zero)
System.out.print(i+" ");
System.out.println("");
}
}
| Java | ["3\n-1 2 0", "4\n-1 -2 -3 0"] | 2 seconds | ["1 -1\n1 2\n1 0", "1 -1\n2 -3 -2\n1 0"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"brute force"
] | 03cf2cc26c84aab685ee78a1d6318b30 | The first line of the input contains integer n (3ββ€βnββ€β100). The second line contains n space-separated distinct integers a1,βa2,β...,βan (|ai|ββ€β103) β the array elements. | 1,100 | In the first line print integer n1 (n1β>β0) β the number of elements in the first set. Then print n1 numbers β the elements that got to the first set. In the next line print integer n2 (n2β>β0) β the number of elements in the second set. Then print n2 numbers β the elements that got to the second set. In the next line print integer n3 (n3β>β0) β the number of elements in the third set. Then print n3 numbers β the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | standard output | |
PASSED | 9c06b33b9f4bf94175eb68bcf40f52e7 | train_003.jsonl | 1366903800 | Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero (β<β0). The product of all numbers in the second set is greater than zero (β>β0). The product of all numbers in the third set is equal to zero. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. | 256 megabytes | /*
Link of Question : http://codeforces.com/problemset/problem/114/A
*/
import java.util.ArrayList;
import java.util.Scanner;
public class Array {
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int A[]=new int[n];
ArrayList<Integer> l1=new ArrayList<>();
ArrayList<Integer> l2=new ArrayList<>();
ArrayList<Integer> l3=new ArrayList<>();
ArrayList<Integer> zero=new ArrayList<>();
ArrayList<Integer> negative=new ArrayList<>();
ArrayList<Integer> possitve=new ArrayList<>();
int maxn=Integer.MAX_VALUE;
int maxp=Integer.MIN_VALUE;
for (int i = 0; i < n; i++)
{
A[i]=in.nextInt();
if (A[i]<0)
{
negative.add(A[i]);
if (maxn>A[i])
{
maxn=A[i];
}
}
if (A[i]>0)
{
possitve.add(A[i]);
if (maxp<A[i])
{
maxp=A[i];
}
}
if (A[i]==0)
{
zero.add(A[i]);
}
}
if (possitve.isEmpty())
{
int count=0;
int g=negative.size();
for (int i = negative.size()-1; i >0; i--)
{
l2.add(negative.get(i));
negative.remove(i);
count++;
if (count==2)
{
break;
}
}
}
else if (possitve.size()>0)
{
for (int i = 0; i < possitve.size(); i++)
{
l2.add(possitve.get(i));
possitve.remove(0);
i=-1;
}
}
if (negative.size()>1)
{
l1.add(negative.get(0));
negative.remove(0);
for (int i = 0; i < negative.size(); i++)
{
l3.add(negative.get(i));
}
l3.add(0);
}
else if (negative.size()<=1)
{
l1.add(negative.get(0));
l3.add(0);
}
System.out.println(l1.size()+" "+l1.toString().replace('[', ' ').replace(']', ' ').replace(',', ' '));
System.out.println(l2.size()+" "+l2.toString().replace('[', ' ').replace(']', ' ').replace(',', ' '));
System.out.println(l3.size()+" "+l3.toString().replace('[', ' ').replace(']', ' ').replace(',', ' '));;
}
}
| Java | ["3\n-1 2 0", "4\n-1 -2 -3 0"] | 2 seconds | ["1 -1\n1 2\n1 0", "1 -1\n2 -3 -2\n1 0"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"brute force"
] | 03cf2cc26c84aab685ee78a1d6318b30 | The first line of the input contains integer n (3ββ€βnββ€β100). The second line contains n space-separated distinct integers a1,βa2,β...,βan (|ai|ββ€β103) β the array elements. | 1,100 | In the first line print integer n1 (n1β>β0) β the number of elements in the first set. Then print n1 numbers β the elements that got to the first set. In the next line print integer n2 (n2β>β0) β the number of elements in the second set. Then print n2 numbers β the elements that got to the second set. In the next line print integer n3 (n3β>β0) β the number of elements in the third set. Then print n3 numbers β the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | standard output | |
PASSED | dd3bdf025760155c3ce7e1d3e4a20cbe | train_003.jsonl | 1366903800 | Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero (β<β0). The product of all numbers in the second set is greater than zero (β>β0). The product of all numbers in the third set is equal to zero. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. | 256 megabytes | //package HackerEarthA;
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.text.*;
import java.math.*;
import java.util.regex.*;
/**
*
* @author prabhat
*/
public class easy18{
public static long[] BIT;
public static long[] tree;
public static long[] sum;
public static int mod=1000000007;
public static int[][] dp;
public static boolean[][] isPalin;
public static int max1=1000005;
public static int[][] g;
public static LinkedList<Pair> l[];
public static int n,m,q,k,t,arr[],b[],cnt[],chosen[],pos[],ans;
public static ArrayList<Integer> adj[],al;
public static TreeSet<Integer> ts;
public static char[][] s;
public static int depth,mini,maxi;
public static long V[],low,high,min=Long.MAX_VALUE;
public static boolean visit[][],isPrime[],used[];
public static int[][] dist;
public static ArrayList<Integer>prime;
public static int[] x={0,1};
public static int[] y={-1,0};
public static ArrayList<Integer> divisor[]=new ArrayList[1500005];
public static int[][] subtree,parent,mat;
public static TreeMap<Integer,Integer> tm;
public static LongPoint[] p;
public static int[][] grid;
public static ArrayList<Pair> list;
public static TrieNode root;
static LinkedHashMap<String,Integer> map;
public static BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws Exception
{
InputReader in = new InputReader(System.in);
PrintWriter pw=new PrintWriter(System.out);
n=in.ii();
arr=in.iia(n);
ArrayList<Integer> pos=new ArrayList<>();
ArrayList<Integer> neg=new ArrayList<>();
ArrayList<Integer> zero=new ArrayList<>();
for(int i:arr)
{
if(i>0)pos.add(i);
else if(i<0)neg.add(i);
else zero.add(i);
}
if(neg.size()%2==1)
{
pw.print(1+" "+neg.get(0));
pw.println();
int u=neg.size()-1;
int v=pos.size();
pw.print(u+v+" ");
for(int i=1;i<neg.size();i++)pw.print(neg.get(i)+" ");
for(int i:pos)pw.print(i+" ");
pw.println();
pw.print(zero.size()+" ");
for(int i:zero)pw.print(i+" ");
}
else{
pw.print(1+" "+neg.get(0));
pw.println();
int u=neg.size()-2;
int v=pos.size();
pw.print(u+v+" ");
for(int i=2;i<neg.size();i++)pw.print(neg.get(i)+" ");
for(int i:pos)pw.print(i+" ");
pw.println();
pw.print(zero.size()+1+" ");
for(int i:zero)pw.print(i+" ");
pw.print(neg.get(1));
pw.println();
}
pw.close();
}
public static void dfs1(int cur)
{
used[cur]=true;
cnt[cur]=1;
for(int ver:adj[cur])
{
if(used[ver])continue;
dfs1(ver);
cnt[cur]+=cnt[ver];
}
}
static ArrayList<String> dfs(String s,String[] sarr,HashMap<String, ArrayList<String>> map)
{
if(map.containsKey(s))return map.get(s);
ArrayList<String> res=new ArrayList<>();
if(s.length()==0)
{
res.add("");
return res;
}
for(String word:sarr)
{
if(s.startsWith(word))
{
ArrayList<String > sub=dfs(s.substring(word.length()),sarr,map);
for(String s2:sub)
{
res.add(word+ (s2.isEmpty() ? "" : " ")+s2);
}
}
}
map.put(s,res);
return res;
}
static class SegmentTree{
int n;
int max_bound;
public SegmentTree(int n)
{
this.n=n;
tree=new long[4*n+1];
build(1,0,n-1);
}
void build(int c,int s,int e)
{
if(s==e)
{
tree[c]=arr[s];
return ;
}
int mid=(s+e)>>1;
build(2*c,s,mid);
build(2*c+1,mid+1,e);
tree[c]=(tree[2*c]+tree[2*c+1]);
}
void put(int c,int s, int e,int l,int r,int v) {
if(l>e||r<s||s>e)return ;
if (s == e)
{
tree[c] = arr[s]^v;
return;
}
int mid = (s + e) >> 1;
if (l>mid) put(2*c+1,m+1, e , l,r, v);
else if(r<=mid)put(2*c,s,m,l,r , v);
else{
}
}
long query(int c,int s,int e,int l,int r)
{
if(e<l||s>r)return 0L;
if(s>=l&&e<=r)
{
return tree[c];
}
int mid=(s+e)>>1;
return (query(2*c,s,mid,l,r)+query(2*c+1,mid+1,e,l,r));
}
}
static void update(int indx,long val)
{
while(indx<max1)
{
BIT[indx]+=val;
indx+=(indx&(-indx));
}
}
static long query1(int indx)
{
long sum=0;
while(indx>0)
{
sum+=BIT[indx];
// System.out.println(indx);
indx-=(indx&(-indx));
}
return sum;
}
public static ListNode removeNthFromEnd(ListNode a, int b) {
int cnt=0;
ListNode ra1=a;
ListNode ra2=a;
while(ra1!=null){ra1=ra1.next; cnt++;}
if(b>cnt)return a.next;
else if(b==1&&cnt==1)return null;
else{
int y=cnt-b+1;
int u=0;
ListNode prev=null;
while(a!=null)
{
u++;
if(u==y)
{
if(a.next==null)prev.next=null;
else
{
if(prev==null)return ra2.next;
prev.next=a.next;
a.next=null;
}
break;
}
prev=a;
a=a.next;
}
}
return ra2;
}
static ListNode rev(ListNode a)
{
ListNode prev=null;
ListNode cur=a;
ListNode next=null;
while(cur!=null)
{
next=cur.next;
cur.next=prev;
prev=cur;
cur=next;
}
return prev;
}
static class ListNode {
public int val;
public ListNode next;
ListNode(int x) { val = x; next = null; }
}
static class TrieNode
{
int value; // Only used in leaf nodes
TrieNode[] arr = new TrieNode[2];
public TrieNode() {
value = 0;
arr[0] = null;
arr[1] = null;
}
}
static void insert(int pre_xor)
{
TrieNode temp = root;
// Start from the msb, insert all bits of
// pre_xor into Trie
for (int i=31; i>=0; i--)
{
// Find current bit in given prefix
int val = (pre_xor & (1<<i)) >=1 ? 1 : 0;
// Create a new node if needed
if (temp.arr[val] == null)
temp.arr[val] = new TrieNode();
temp = temp.arr[val];
}
// Store value at leaf node
temp.value = pre_xor;
}
static int query(int pre_xor)
{
TrieNode temp = root;
for (int i=31; i>=0; i--)
{
// Find current bit in given prefix
int val = (pre_xor & (1<<i)) >= 1 ? 1 : 0;
// Traverse Trie, first look for a
// prefix that has opposite bit
if (temp.arr[val] != null)
temp = temp.arr[val];
// If there is no prefix with opposite
// bit, then look for same bit.
else if (temp.arr[1-val] != null)
temp = temp.arr[1-val];
}
return pre_xor^(temp.value);
}
public static String add(String s1,String s2)
{
int n=s1.length()-1;
int m=s2.length()-1;
int rem=0;
int carry=0;
int i=n;
int j=m;
String ans="";
while(i>=0&&j>=0)
{
int c1=(int)(s1.charAt(i)-'0');
int c2=(int)(s2.charAt(j)-'0');
int sum=c1+c2;
sum+=carry;
rem=sum%10;
carry=sum/10;
ans=rem+ans;
i--; j--;
}
while(i>=0)
{
int c1=(int)(s1.charAt(i)-'0');
int sum=c1;
sum+=carry;
rem=sum%10;
carry=sum/10;
ans=rem+ans;
i--;
}
while(j>=0)
{
int c2=(int)(s2.charAt(j)-'0');
int sum=c2;
sum+=carry;
rem=sum%10;
carry=sum/10;
ans=rem+ans;
j--;
}
if(carry>0)ans=carry+ans;
return ans;
}
public static String[] multiply(String A, String B) {
int lb=B.length();
char[] a=A.toCharArray();
char[] b=B.toCharArray();
String[] s=new String[lb];
int cnt=0;
int y=0;
String s1="";
q=0;
for(int i=b.length-1;i>=0;i--)
{
int rem=0;
int carry=0;
for(int j=a.length-1;j>=0;j--)
{
int mul=(int)(b[i]-'0')*(int)(a[j]-'0');
mul+=carry;
rem=mul%10;
carry=mul/10;
s1=rem+s1;
}
s1=carry+s1;
s[y++]=s1;
q=Math.max(q,s1.length());
s1="";
for(int i1=0;i1<y;i1++)s1+='0';
}
return s;
}
public static long nCr(long total, long choose)
{
if(total < choose)
return 0;
if(choose == 0 || choose == total)
return 1;
return nCr(total-1,choose-1)+nCr(total-1,choose);
}
static int get(long s)
{
int ans=0;
for(int i=0;i<n;i++)
{
if(p[i].x<=s&&s<=p[i].y)ans++;
}
return ans;
}
static class LongPoint {
public long x;
public long y;
public LongPoint(long x, long y) {
this.x = x;
this.y = y;
}
public LongPoint subtract(LongPoint o) {
return new LongPoint(x - o.x, y - o.y);
}
public long cross(LongPoint o) {
return x * o.y - y * o.x;
}
}
static int CountPs(String s,int n)
{
boolean b=false;
char[] S=s.toCharArray();
int[][] dp=new int[n][n];
boolean[][] p=new boolean[n][n];
for(int i=0;i<n;i++)p[i][i]=true;
for(int i=0;i<n-1;i++)
{
if(S[i]==S[i+1])
{
p[i][i+1]=true;
dp[i][i+1]=0;
b=true;
}
}
for(int gap=2;gap<n;gap++)
{
for(int i=0;i<n-gap;i++)
{
int j=gap+i;
if(S[i]==S[j]&&p[i+1][j-1]){p[i][j]=true;}
if(p[i][j])
dp[i][j]=dp[i][j-1]+dp[i+1][j]+1-dp[i+1][j-1];
else if(!p[i][j]) dp[i][j]=dp[i][j-1]+dp[i+1][j]-dp[i+1][j-1];
//if(dp[i][j]>=1)
// return true;
}
}
// return b;
return dp[0][n-1];
}
static void Seive()
{
isPrime=new boolean[1500005];
Arrays.fill(isPrime,true);
for(int i=0;i<1500005;i++){divisor[i]=new ArrayList<>();}
int u=0;
prime=new ArrayList<>();
for(int i=2;i<=(1500000);i++)
{
if(isPrime[i])
{
prime.add(i);
for(int j=i;j<1500000;j+=i)
{
divisor[j].add(i);
isPrime[j]=false;
}
/* for(long x=(divCeil(low,i))*i;x<=high;x+=i)
{
divisor[(int)(x-low)].add(i*1L);
}*/
}
}
}
static long divCeil(long a,long b)
{
return (a+b-1)/b;
}
static long root(int pow, long x) {
long candidate = (long)Math.exp(Math.log(x)/pow);
candidate = Math.max(1, candidate);
while (pow(candidate, pow) <= x) {
candidate++;
}
return candidate-1;
}
static long pow(long x, int pow)
{
long result = 1;
long p = x;
while (pow > 0) {
if ((pow&1) == 1) {
if (result > Long.MAX_VALUE/p) return Long.MAX_VALUE;
result *= p;
}
pow >>>= 1;
if (pow > 0 && p >= 4294967296L) return Long.MAX_VALUE;
p *= p;
}
return result;
}
static boolean valid(int i,int j)
{
if(i>=0&&i<n&&j>=0&&j<m)return true;
return false;
}
private static class DSU{
int[] parent;
int[] rank;
int cnt;
public DSU(int n){
parent=new int[n];
rank=new int[n];
for(int i=0;i<n;i++){
parent[i]=i;
rank[i]=1;
}
cnt=n;
}
int find(int i){
while(parent[i] !=i){
parent[i]=parent[parent[i]];
i=parent[i];
}
return i;
}
int Union(int x, int y){
int xset = find(x);
int yset = find(y);
if(xset!=yset)
cnt--;
if(rank[xset]<rank[yset]){
parent[xset] = yset;
rank[yset]+=rank[xset];
rank[xset]=0;
return yset;
}else{
parent[yset]=xset;
rank[xset]+=rank[yset];
rank[yset]=0;
return xset;
}
}
}
public static int[][] packU(int n, int[] from, int[] to, int max) {
int[][] g = new int[n][];
int[] p = new int[n];
for (int i = 0; i < max; i++) p[from[i]]++;
for (int i = 0; i < max; i++) p[to[i]]++;
for (int i = 0; i < n; i++) g[i] = new int[p[i]];
for (int i = 0; i < max; i++) {
g[from[i]][--p[from[i]]] = to[i];
g[to[i]][--p[to[i]]] = from[i];
}
return g;
}
public static int[][] parents3(int[][] g, int root) {
int n = g.length;
int[] par = new int[n];
Arrays.fill(par, -1);
int[] depth = new int[n];
depth[0] = 0;
int[] q = new int[n];
q[0] = root;
for (int p = 0, r = 1; p < r; p++) {
int cur = q[p];
for (int nex : g[cur]) {
if (par[cur] != nex) {
q[r++] = nex;
par[nex] = cur;
depth[nex] = depth[cur] + 1;
}
}
}
return new int[][]{par, q, depth};
}
public static int lower_bound(int[] nums, int target) {
int low = 0, high = nums.length - 1;
while (low < high) {
int mid = low + (high - low) / 2;
if (nums[mid] < target)
low = mid + 1;
else
high = mid;
}
return nums[low] == target ? low : -1;
}
public static int upper_bound(int[] nums, int target) {
int low = 0, high = nums.length - 1;
while (low < high) {
int mid = low + (high + 1 - low) / 2;
if (nums[mid] > target)
high = mid - 1;
else
low = mid;
}
return nums[low] == target ? low : -1;
}
public static boolean palin(String s)
{
int i=0;
int j=s.length()-1;
while(i<j)
{
if(s.charAt(i)==s.charAt(j))
{
i++;
j--;
}
else return false;
}
return true;
}
public static int gcd(int a,int b)
{
int res=1;
while(a>0)
{
res=a;
a=b%a;
b=res;
}
return res;
}
static int lcm(int a,int b)
{
return (a*b)/(gcd(a,b));
}
public static long pow(long n,long p,long m)
{
long result = 1;
if(p==0)
return 1;
while(p!=0)
{
if(p%2==1)
result *= n;
if(result>=m)
result%=m;
p >>=1;
n*=n;
if(n>=m)
n%=m;
}
return result;
}
/**
*
* @param n
* @param p
* @return
*/
public static long pow(long n,long p)
{
long result = 1;
if(p==0)
return 1;
if (p==1)
return n;
while(p!=0)
{
if(p%2==1)
result *= n;
p >>=1;
n*=n;
}
return result;
}
static class Edge implements Comparator<Edge> {
private int u;
private int v;
private long w;
public Edge() {
}
public Edge(int u, int v, long w) {
this.u=u;
this.v=v;
this.w=w;
}
public int getU() {
return u;
}
public void setU(int u) {
this.u = u;
}
public int getV() {
return v;
}
public void setV(int v) {
this.v = v;
}
public long getW() {
return w;
}
public void setW(int w) {
this.w = w;
}
public long compareTo(Edge e)
{
return (this.getW() - e.getW());
}
@Override
public int compare(Edge o1, Edge o2) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
static class Pair implements Comparable<Pair>
{
int x,y;
Pair (int a,int b)
{
this.x=a;
this.y=b;
}
public int compareTo(Pair o) {
// TODO Auto-generated method stub
if(this.x!=o.x)
return -Integer.compare(this.x,o.x);
else
return -Integer.compare(this.y, o.y);
//return 0;
}
public boolean equals(Object o) {
if (o instanceof Pair) {
Pair p = (Pair)o;
return p.x == x && p.y == y;
}
return false;
}
public int hashCode() {
return new Integer(x).hashCode() * 31 + new Integer(y).hashCode();
}
}
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private SpaceCharFilter filter;
byte inbuffer[] = new byte[1024];
int lenbuffer = 0, ptrbuffer = 0;
final int M = (int) 1e9 + 7;
int md=(int)(1e7+1);
int[] SMP=new int[md];
final double eps = 1e-6;
final double pi = Math.PI;
PrintWriter out;
String check = "";
InputStream obj = check.isEmpty() ? System.in : new ByteArrayInputStream(check.getBytes());
public InputReader(InputStream stream)
{
this.stream = stream;
}
int readByte() {
if (lenbuffer == -1) throw new InputMismatchException();
if (ptrbuffer >= lenbuffer) {
ptrbuffer = 0;
try {
lenbuffer = obj.read(inbuffer);
} catch (IOException e) {
throw new InputMismatchException();
}
}
if (lenbuffer <= 0) return -1;
return inbuffer[ptrbuffer++];
}
public int read()
{
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;
}
String is() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) // when nextLine, (isSpaceChar(b) && b!=' ')
{
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int ii() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
public long il() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
boolean isSpaceChar(int c) {
return (!(c >= 33 && c <= 126));
}
int skip()
{
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
float nf() {
return Float.parseFloat(is());
}
double id() {
return Double.parseDouble(is());
}
char ic() {
return (char) skip();
}
int[] iia(int n) {
int a[] = new int[n];
for (int i = 0; i<n; i++) a[i] = ii();
return a;
}
long[] ila(int n) {
long a[] = new long[n];
for (int i = 0; i <n; i++) a[i] = il();
return a;
}
String[] isa(int n) {
String a[] = new String[n];
for (int i = 0; i < n; i++) a[i] = is();
return a;
}
long mul(long a, long b) { return a * b % M; }
long div(long a, long b)
{
return mul(a, pow(b, M - 2));
}
double[][] idm(int n, int m) {
double a[][] = new double[n][m];
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = id();
return a;
}
int[][] iim(int n, int m) {
int a[][] = new int[n][m];
for (int i = 0; i < n; i++) for (int j = 0; j <m; j++) a[i][j] = ii();
return a;
}
public String readLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
public boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
}
| Java | ["3\n-1 2 0", "4\n-1 -2 -3 0"] | 2 seconds | ["1 -1\n1 2\n1 0", "1 -1\n2 -3 -2\n1 0"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"brute force"
] | 03cf2cc26c84aab685ee78a1d6318b30 | The first line of the input contains integer n (3ββ€βnββ€β100). The second line contains n space-separated distinct integers a1,βa2,β...,βan (|ai|ββ€β103) β the array elements. | 1,100 | In the first line print integer n1 (n1β>β0) β the number of elements in the first set. Then print n1 numbers β the elements that got to the first set. In the next line print integer n2 (n2β>β0) β the number of elements in the second set. Then print n2 numbers β the elements that got to the second set. In the next line print integer n3 (n3β>β0) β the number of elements in the third set. Then print n3 numbers β the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | standard output | |
PASSED | a6bb78d6756037cfb1969177d60fd6b0 | train_003.jsonl | 1366903800 | Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero (β<β0). The product of all numbers in the second set is greater than zero (β>β0). The product of all numbers in the third set is equal to zero. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. | 256 megabytes |
import java.util.Scanner;
public class A300 {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] arr = new int[n];
int f = 0, s = 0, t = 0, s2 = 0;
String first="", second="", third="";
for (int i = 0; i < n; ++i) {
arr[i] = in.nextInt();
if(arr[i]<0) ++s2;
if(arr[i]<0 && f == 0){
++f;
first+=arr[i];
continue;
}
if(arr[i]!=0){
++s;
second+=arr[i]+" ";
}
if(arr[i]==0){
++t;
third+="0 ";
}
}
if((s2-1)%2!=0){
boolean neg = false;
String num = "-", noNum="";
for (int i = 0; i < second.length(); i++) {
if(second.charAt(i)=='-'){
neg = true;
noNum += second.substring(0, i);
continue;
}
if(neg){
if(second.charAt(i)==' ' || i==second.length()-1){
noNum += second.substring(i+1);
break;
}
num+=second.charAt(i);
}
}
System.out.println(f+" "+first+"\n"+(s-1)+" "+noNum+"\n"+(t+1)+" "+num+" "+third);
} else System.out.println(f+" "+first+"\n"+s+" "+second+"\n"+t+" "+third);
}
static String print(int[] a, int... args){
String res = args.length+" ";
for (int i = 0; i < args.length; i++) {
res+=a[args[i]]+" ";
}
return res;
}
}
| Java | ["3\n-1 2 0", "4\n-1 -2 -3 0"] | 2 seconds | ["1 -1\n1 2\n1 0", "1 -1\n2 -3 -2\n1 0"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"brute force"
] | 03cf2cc26c84aab685ee78a1d6318b30 | The first line of the input contains integer n (3ββ€βnββ€β100). The second line contains n space-separated distinct integers a1,βa2,β...,βan (|ai|ββ€β103) β the array elements. | 1,100 | In the first line print integer n1 (n1β>β0) β the number of elements in the first set. Then print n1 numbers β the elements that got to the first set. In the next line print integer n2 (n2β>β0) β the number of elements in the second set. Then print n2 numbers β the elements that got to the second set. In the next line print integer n3 (n3β>β0) β the number of elements in the third set. Then print n3 numbers β the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | standard output | |
PASSED | c13b4d3009e12eeecc02ff24725c25e2 | train_003.jsonl | 1366903800 | Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero (β<β0). The product of all numbers in the second set is greater than zero (β>β0). The product of all numbers in the third set is equal to zero. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. | 256 megabytes | import java.io.*;
import java.util.*;
public class A {
public static void solution(BufferedReader reader, PrintWriter out)
throws IOException {
In in = new In(reader);
int n = in.nextInt();
ArrayList<Integer> a1 = new ArrayList<Integer>();
ArrayList<Integer> a2 = new ArrayList<Integer>();
ArrayList<Integer> a3 = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
int a = in.nextInt();
if (a < 0 && a1.size() == 0)
a1.add(a);
else if (a > 0 && a2.size() == 0)
a2.add(a);
else
a3.add(a);
}
if (a2.size() == 0)
for (int i = a3.size() - 1; i >= 0 && a2.size() < 2; i--)
if (a3.get(i) < 0) {
a2.add(a3.get(i));
a3.remove(i);
}
out.print(a1.size());
for (Integer a : a1)
out.printf(" %d", a);
out.println();
out.print(a2.size());
for (Integer a : a2)
out.printf(" %d", a);
out.println();
out.print(a3.size());
for (Integer a : a3)
out.printf(" %d", a);
out.println();
}
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(System.out)));
solution(reader, out);
out.close();
}
protected static class In {
private BufferedReader reader;
private StringTokenizer tokenizer = new StringTokenizer("");
public In(BufferedReader reader) {
this.reader = reader;
}
public String next() throws IOException {
while (!tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
return tokenizer.nextToken();
}
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());
}
}
}
| Java | ["3\n-1 2 0", "4\n-1 -2 -3 0"] | 2 seconds | ["1 -1\n1 2\n1 0", "1 -1\n2 -3 -2\n1 0"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"brute force"
] | 03cf2cc26c84aab685ee78a1d6318b30 | The first line of the input contains integer n (3ββ€βnββ€β100). The second line contains n space-separated distinct integers a1,βa2,β...,βan (|ai|ββ€β103) β the array elements. | 1,100 | In the first line print integer n1 (n1β>β0) β the number of elements in the first set. Then print n1 numbers β the elements that got to the first set. In the next line print integer n2 (n2β>β0) β the number of elements in the second set. Then print n2 numbers β the elements that got to the second set. In the next line print integer n3 (n3β>β0) β the number of elements in the third set. Then print n3 numbers β the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | standard output | |
PASSED | 1f19a8769710b29a1aa4ea79e2b7f1e4 | train_003.jsonl | 1366903800 | Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero (β<β0). The product of all numbers in the second set is greater than zero (β>β0). The product of all numbers in the third set is equal to zero. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. | 256 megabytes | import java.util.*;
public class CF300A{
public static void main(String ... Args){
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
ArrayList<Integer> l=new ArrayList<Integer>();
ArrayList<Integer> e=new ArrayList<Integer>();
ArrayList<Integer> g=new ArrayList<Integer>();
int [] arr=new int[n];
int countLess=0,countGreater=0;
for(int i=0;i<n;i++){
arr[i]=scan.nextInt();
if(arr[i]<0) countLess+=1;
if(arr[i]>0) countGreater+=1;
}
for(int i=0;i<n;i++){
int temp=arr[i];
if(temp<0){
l.add(temp);
}else if(temp==0){
e.add(temp);
}else{
g.add(temp);
}
}
if(countGreater==0){
int temp=l.get(l.size()-1);
g.add(temp);
l.remove(l.size()-1);
temp=l.get(l.size()-1);
g.add(temp);
l.remove(l.size()-1);
}
if(l.size()%2==0){
int temp=l.get(l.size()-1);
e.add(temp);
l.remove(l.size()-1);
}
System.out.print(l.size()+" ");
for(int i=0;i<l.size();i++){
System.out.print(l.get(i)+" ");
}
System.out.println();
System.out.print(g.size()+" ");
for(int i=0;i<g.size();i++){
System.out.print(g.get(i)+" ");
}
System.out.println();
System.out.print(e.size()+" ");
for(int i=0;i<e.size();i++){
System.out.print(e.get(i)+" ");
}
}
} | Java | ["3\n-1 2 0", "4\n-1 -2 -3 0"] | 2 seconds | ["1 -1\n1 2\n1 0", "1 -1\n2 -3 -2\n1 0"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"brute force"
] | 03cf2cc26c84aab685ee78a1d6318b30 | The first line of the input contains integer n (3ββ€βnββ€β100). The second line contains n space-separated distinct integers a1,βa2,β...,βan (|ai|ββ€β103) β the array elements. | 1,100 | In the first line print integer n1 (n1β>β0) β the number of elements in the first set. Then print n1 numbers β the elements that got to the first set. In the next line print integer n2 (n2β>β0) β the number of elements in the second set. Then print n2 numbers β the elements that got to the second set. In the next line print integer n3 (n3β>β0) β the number of elements in the third set. Then print n3 numbers β the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | standard output | |
PASSED | 3d6469478aa635b9405a754628eafe26 | train_003.jsonl | 1366903800 | Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero (β<β0). The product of all numbers in the second set is greater than zero (β>β0). The product of all numbers in the third set is equal to zero. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. | 256 megabytes | import java.util.*;
import java.io.*;
public class MyClass {
public static void main(String[] args)throws IOException, FileNotFoundException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String str1 = reader.readLine();
int n=Integer.parseInt(str1);
String str2 = reader.readLine();
String[] arr = str2.split(" ");
int[] array = new int[n];
int count=0;
for(int i=0 ; i<n ;i++)
{
array[i] = Integer.parseInt(arr[i]);
}
ArrayList<Integer> list1 = new ArrayList<>();
ArrayList<Integer> list2 = new ArrayList<>();
ArrayList<Integer> list3 = new ArrayList<>();
for(int i=0 ; i<n ;i++)
{
if(array[i]<0 && list1.isEmpty())
{
list1.add(array[i]);
}
else if(array[i]>0 && list2.isEmpty())
{
list2.add(array[i]);
}
else
list3.add(array[i]);
}
if(list2.isEmpty())
{
for(int i=0 ; i<list3.size() ;i++)
{
if(list3.get(i) < 0)
{
list2.add(list3.get(i));
list3.remove(i);
count++;
i--;
}
if(count == 2)
break;
}
}
System.out.print(list1.size());
System.out.print(" ");
System.out.print(list1.get(0));
System.out.println();
System.out.print(list2.size());
System.out.print(" ");
for(int i=0 ; i<list2.size() ;i++)
{
System.out.print(list2.get(i));
System.out.print(" ");
}
System.out.println();
System.out.print(list3.size());
System.out.print(" ");
for(int i=0 ; i<list3.size() ;i++)
{
System.out.print(list3.get(i));
System.out.print(" ");
}
}
}
| Java | ["3\n-1 2 0", "4\n-1 -2 -3 0"] | 2 seconds | ["1 -1\n1 2\n1 0", "1 -1\n2 -3 -2\n1 0"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"brute force"
] | 03cf2cc26c84aab685ee78a1d6318b30 | The first line of the input contains integer n (3ββ€βnββ€β100). The second line contains n space-separated distinct integers a1,βa2,β...,βan (|ai|ββ€β103) β the array elements. | 1,100 | In the first line print integer n1 (n1β>β0) β the number of elements in the first set. Then print n1 numbers β the elements that got to the first set. In the next line print integer n2 (n2β>β0) β the number of elements in the second set. Then print n2 numbers β the elements that got to the second set. In the next line print integer n3 (n3β>β0) β the number of elements in the third set. Then print n3 numbers β the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | standard output | |
PASSED | 1f5d9d2b603a6b151a55ff445f44e8f7 | train_003.jsonl | 1366903800 | Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero (β<β0). The product of all numbers in the second set is greater than zero (β>β0). The product of all numbers in the third set is equal to zero. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. | 256 megabytes |
import com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_2;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class Codeforces {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int arr[] = new int[n];
List s1 = new ArrayList<>();
List s2 = new ArrayList();
List s3 = new ArrayList();
for (int i = 0; i < n; i++) {
arr[i] = in.nextInt();
}
for (int i = 0; i < n; i++) {
if (arr[i] < 0) {
s1.add(arr[i]);
} else if (arr[i] > 0) {
s2.add(arr[i]);
} else {
s3.add(arr[i]);
}
}
if (s1.size() % 2 == 0) {
s3.add(s1.get(0));
s1.remove(0);
}
if (s2.size() == 0) {
s2.add(s1.get(0));
s2.add(s1.get(1));
s1.remove(0);
s1.remove(0);
}
System.out.print(s1.size() + " ");
for (Object e : s1) {
System.out.print(e + " ");
}
System.out.println();
System.out.print(s2.size() + " ");
for (Object e : s2) {
System.out.print(e + " ");
}
System.out.println();
System.out.print(s3.size() + " ");
for (Object e : s3) {
System.out.print(e + " ");
}
}
}
| Java | ["3\n-1 2 0", "4\n-1 -2 -3 0"] | 2 seconds | ["1 -1\n1 2\n1 0", "1 -1\n2 -3 -2\n1 0"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"brute force"
] | 03cf2cc26c84aab685ee78a1d6318b30 | The first line of the input contains integer n (3ββ€βnββ€β100). The second line contains n space-separated distinct integers a1,βa2,β...,βan (|ai|ββ€β103) β the array elements. | 1,100 | In the first line print integer n1 (n1β>β0) β the number of elements in the first set. Then print n1 numbers β the elements that got to the first set. In the next line print integer n2 (n2β>β0) β the number of elements in the second set. Then print n2 numbers β the elements that got to the second set. In the next line print integer n3 (n3β>β0) β the number of elements in the third set. Then print n3 numbers β the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | standard output | |
PASSED | b9a533dd999a03eea678eaf7956d20c0 | train_003.jsonl | 1366903800 | Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero (β<β0). The product of all numbers in the second set is greater than zero (β>β0). The product of all numbers in the third set is equal to zero. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class array {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
StringBuilder negg=new StringBuilder();
StringBuilder poss=new StringBuilder();
StringBuilder zer=new StringBuilder();
int n=sc.nextInt();
int a[]=new int[n];
int pos, neg,zero;
pos=neg=0;
for(int i=0;i<n;i++) {
a[i]=sc.nextInt();
if(a[i]>0)
pos++;
}
boolean flag=false;
if(pos==0) {pos=2; flag=true;}
negg.append(1+" ");
poss.append((pos==2&&flag?pos:1)+" ");
zer.append((pos==2&&flag?(n-3):n-2)+" ");
for(int i=0;i<n;i++) {
if(neg==0&&a[i]<0) {
negg.append(a[i]+" ");
neg++;
}
else if(a[i]>0&&pos>0) {
poss.append(a[i]+" ");
pos=-1;
}
else if (flag&&pos>0&&a[i]<0) {
poss.append(a[i]+" ");
pos--;
}
else zer.append(a[i]+" ");
}
PrintWriter pw=new PrintWriter(System.out);
pw.println(negg+"\n"+poss+"\n"+zer);
pw.flush();
pw.close();
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
Scanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
}
}
| Java | ["3\n-1 2 0", "4\n-1 -2 -3 0"] | 2 seconds | ["1 -1\n1 2\n1 0", "1 -1\n2 -3 -2\n1 0"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"brute force"
] | 03cf2cc26c84aab685ee78a1d6318b30 | The first line of the input contains integer n (3ββ€βnββ€β100). The second line contains n space-separated distinct integers a1,βa2,β...,βan (|ai|ββ€β103) β the array elements. | 1,100 | In the first line print integer n1 (n1β>β0) β the number of elements in the first set. Then print n1 numbers β the elements that got to the first set. In the next line print integer n2 (n2β>β0) β the number of elements in the second set. Then print n2 numbers β the elements that got to the second set. In the next line print integer n3 (n3β>β0) β the number of elements in the third set. Then print n3 numbers β the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | standard output | |
PASSED | 255235afcde89fc8d43062711ed874a7 | train_003.jsonl | 1366903800 | Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero (β<β0). The product of all numbers in the second set is greater than zero (β>β0). The product of all numbers in the third set is equal to zero. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. | 256 megabytes | import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Array {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
List<Integer> in = new ArrayList<>();
List<Integer> set1 = new ArrayList<>();
List<Integer> set2 = new ArrayList<>();
List<Integer> set3 = new ArrayList<>();
int x = 1, y = 1;
int neg=0;
int pos=0;
int count=0;
while (n-- > 0) {
int r=sc.nextInt();
if(r<0){
neg++;
}else if(r>0){
pos++;
}
in.add(r);
}
//all negative
if(pos==0){
count=neg;
for (int i = 0; i < in.size(); i++) {
if (in.get(i) == 0 || (count%2==0 && in.get(i)<0 && set3.size()<1)) {
set3.add(in.get(i));
count--;
}
else if(set1.size()!=2){
set1.add(in.get(i));
}
else{
set2.add(in.get(i));
}
}
}
//negs greater than +
else if(neg>pos){
count=neg;
for (int i = 0; i < in.size(); i++) {
if(count %2!=0){
if(in.get(i)<0)
{
set2.add(in.get(i));
}
else if (in.get(i) == 0){
set3.add(in.get(i));
}
else{
set1.add(in.get(i));
}
}
else{
if (in.get(i) == 0 || (set3.size()<1 && in.get(i)<0)) {
set3.add(in.get(i));
count--;
}
else if(in.get(i)< 0){
set2.add(in.get(i));
//count--;
}
else{
set1.add(in.get(i));
}
}
}
}
//+>-
else if(neg<pos){
count=neg;
for (int i = 0; i < in.size(); i++) {
if (in.get(i) == 0 || (count%2!=0 && in.get(i)<0)) {
set3.add(in.get(i));
count--;
}
else if(in.get(i)<0){
set2.add(in.get(i));
}
else{
set1.add(in.get(i));
}
}
}
else if(neg==pos){
count=neg;
for (int i = 0; i < in.size(); i++) {
if (in.get(i) == 0|| (count%2==0 && in.get(i)<0)) {
set3.add(in.get(i));
count--;
}
else if(count%2!=0){
set2.add(in.get(i));
count--;
}
else{
set1.add(in.get(i));
}
}
}
System.out.print(set2.size());
for(int i=0;i<set2.size();i++){
System.out.print(" "+set2.get(i));
}
System.out.println();
System.out.print(set1.size());
for(int i=0;i<set1.size();i++){
System.out.print(" "+set1.get(i));
}
System.out.println();
System.out.print(set3.size());
for(int i=0;i<set3.size();i++){
System.out.print(" "+set3.get(i));
}
}
} | Java | ["3\n-1 2 0", "4\n-1 -2 -3 0"] | 2 seconds | ["1 -1\n1 2\n1 0", "1 -1\n2 -3 -2\n1 0"] | null | Java 8 | standard input | [
"constructive algorithms",
"implementation",
"brute force"
] | 03cf2cc26c84aab685ee78a1d6318b30 | The first line of the input contains integer n (3ββ€βnββ€β100). The second line contains n space-separated distinct integers a1,βa2,β...,βan (|ai|ββ€β103) β the array elements. | 1,100 | In the first line print integer n1 (n1β>β0) β the number of elements in the first set. Then print n1 numbers β the elements that got to the first set. In the next line print integer n2 (n2β>β0) β the number of elements in the second set. Then print n2 numbers β the elements that got to the second set. In the next line print integer n3 (n3β>β0) β the number of elements in the third set. Then print n3 numbers β the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | standard output | |
PASSED | 4b926fd55b101a60d8d02e228d184327 | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader in = new FastReader();
int n = in.nextInt();
int min = Integer.MAX_VALUE;
int index = -1;
boolean same = false;
for (int i = 0; i < n; i++) {
int num = in.nextInt();
if (num < min) {
min = num;
index = i + 1;
same = false;
} else if (num == min) {
same = true;
}
}
System.out.println(same ? "Still Rozdil" : index);
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 203b561e065b53e4ae9ca30565a90871 | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.*;
import javax.naming.directory.InvalidAttributesException;
import java.io.InputStreamReader;
import java.io.Writer;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.IOException;
import java.lang.Math;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.io.PrintWriter;
public class one {
static boolean isPalindrome(String word) {
word = word.toLowerCase();
int start = 0;
int end = word.length() - 1;
boolean flag = true;
while (start <= end) {
if (word.charAt(start) != word.charAt(end)) {
flag = false;
break;
} else
start++;
end--;
}
return flag;
}
static boolean isVowel(char x) {
if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u' || x == 'A' || x == 'E' || x == 'I' || x == 'O'
|| x == 'U')
return true;
else
return false;
}
static boolean isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static boolean isPerfectSquare(double x) {
double sr = Math.sqrt(x);
return ((sr - Math.floor(sr)) == 0);
}
static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
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() throws IOException, InvalidAttributesException {
String str = "";
str = br.readLine();
return str;
}
public int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; ++i)
array[i] = nextInt();
return array;
}
public long[] nextLongArray(int n) {
long[] array = new long[n];
for (int i = 0; i < n; ++i)
array[i] = nextLong();
return array;
}
public ArrayList<Integer> nextIntArrayList(int n) {
ArrayList<Integer> ar = new ArrayList<>();
for (int i = 0; i < n; i++)
ar.add(nextInt());
return ar;
}
public ArrayList<Long> nextLongArrayList(int n) {
ArrayList<Long> ar = new ArrayList<>();
for (int i = 0; i < n; i++)
ar.add(nextLong());
return ar;
}
public int[][] nextIntMatrix(int n, int m) {
int[][] matrix = new int[n][m];
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
matrix[i][j] = nextInt();
return matrix;
}
public long[][] nextLongMatrix(int n, int m) {
long[][] matrix = new long[n][m];
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
matrix[i][j] = nextLong();
return matrix;
}
public char[][] nextCharMatrix(int n, int m) {
char[][] matrix = new char[n][m];
for (int i = 0; i < n; ++i)
matrix[i] = next().toCharArray();
return matrix;
}
}
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 print(int[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void print(double[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void print(long[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void print(char[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void print(String[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void print(int[][] matrix) {
for (int i = 0; i < matrix.length; ++i) {
println(matrix[i]);
}
}
public void print(double[][] matrix) {
for (int i = 0; i < matrix.length; ++i) {
println(matrix[i]);
}
}
public void print(long[][] matrix) {
for (int i = 0; i < matrix.length; ++i) {
println(matrix[i]);
}
}
public void print(char[][] matrix) {
for (int i = 0; i < matrix.length; ++i) {
println(matrix[i]);
}
}
public void print(String[][] matrix) {
for (int i = 0; i < matrix.length; ++i) {
println(matrix[i]);
}
}
public void println(int[] array) {
print(array);
writer.println();
}
public void println(double[] array) {
print(array);
writer.println();
}
public void println(long[] array) {
print(array);
writer.println();
}
// public void println(char[] array) {
// print(array);
// writer.println();
// }
public void println(String[] array) {
print(array);
writer.println();
}
public void println() {
writer.println();
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void print(char i) {
writer.print(i);
}
public void println(char i) {
writer.println(i);
}
public void println(char[] array) {
writer.println(array);
}
public void printf(String format, Object... objects) {
writer.printf(format, objects);
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
public void print(long i) {
writer.print(i);
}
public void println(long i) {
writer.println(i);
}
public void print(int i) {
writer.print(i);
}
public void println(int i) {
writer.println(i);
}
public void separateLines(int[] array) {
for (int i : array) {
println(i);
}
}
}
public static void main(String[] args) {
FastReader sc = new FastReader();
OutputStream outputStream = System.out;
OutputWriter out = new OutputWriter(outputStream);
// int t = sc.nextInt();
// while (t-- > 0) {
int n =sc.nextInt();
int [] arr = sc.nextIntArray(n);
int [] ar = new int [n];
for(int i=0;i<n;i++)
ar[i]=arr[i];
Arrays.sort(ar);
if(n==1)
{
out.println(1);
}
else if(ar[0]==ar[1])
out.println("Still Rozdil");
else
{
int k = -1;
for(int i=0;i<n;i++)
{
if(arr[i]==ar[0])
k=i+1;
}
out.println(k);
}
// }
out.flush();
out.close();
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | d3d2d98e8749bd356bda0ceae53371cb | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.Scanner;
public class LittleElephantAndRozdil {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] a = new int[n];
int min = Integer.MAX_VALUE, index = 0, br = 0;
for(int i = 0; i < n; i++) {
a[i] = s.nextInt();
if(a[i] < min) {
min = a[i];
index = i;
}
}
for(int i = 0; i < n; i++) if(a[i] == min) br++;
if(br > 1) System.out.println("Still Rozdil");
else System.out.println(index + 1);
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | fd1048bde4d6aeaed435818a7b2d555c | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.*;
public class Elephant{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int n,i,count=0,j=0;
n=sc.nextInt();
int[] a=new int[n];
for(i=0;i<n;i++){
a[i]=sc.nextInt();
}
int[] b=new int[1];
b[0]=1000000000;
for(i=0;i<n;i++){
if(a[i]<b[0]){
b[0]=a[i];
}
}
for(i=0;i<n;i++){
if(b[0]==a[i]){
count++;
j=i;
}
}
if(count>1){
System.out.println("Still Rozdil");
}
else{
System.out.println(j+1);
}
}
} | Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | b2501fbe284a1a8202dc67dfa9c72eb2 | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author grolegor
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n = in.nextInt();
List<Town> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
int time = in.nextInt();
list.add(new Town(time, i));
}
if (n == 1) {
out.println(1);
} else {
list.sort(Comparator.comparing(Town::getTime));
if (list.get(0).getTime() == list.get(1).getTime()) {
out.println("Still Rozdil");
} else {
out.println(list.get(0).idx + 1);
}
}
}
}
static class Town {
int time;
int idx;
public Town(int time, int idx) {
this.time = time;
this.idx = idx;
}
public int getTime() {
return time;
}
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 539c2b2ad2ac105554fe5a6c6f4b7ea7 | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.*;
// warm-up
public class LittleElephantAndRozdil {
static void solve() {
Scanner sc = new Scanner(System.in);
int noc=sc.nextInt(), i=1, k=1, min=Integer.MAX_VALUE, minD=Integer.MAX_VALUE;
boolean ok = true;
while (noc-->0) {
int d = sc.nextInt();
if (d<minD) { min=i; minD=d; k=1; }
else if (d==minD) k++;
i++;
}
ok=(k==1);
System.out.println(ok ? min : "Still Rozdil");
sc.close();
}
public static void main(String args[]) {
solve();
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 237e645be7ddc69abfaf139a1fe8c1d8 | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.*;
public class LittleElephantAndRozdil_205A {
public static void main(String args[]) {
int n,a,min=1000000000,point=0,count=0;
Scanner scan=new Scanner(System.in);
n=scan.nextInt();
int[] array=new int[n];
for(int i=0;i<n;i++) {
a=scan.nextInt();
array[i]=a;
if(a<min) {
min=a;
point=i;
}
}
for(int i=point+1;i<n;i++) {
if(min==array[i]) count++;
}
if(count!=0) System.out.print("Still Rozdil");
else System.out.print(point+1);
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 8d9293d66fdffba80e8c447142819c74 | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner z=new Scanner (System.in);
int n=z.nextInt();
int []arr=new int [n];
for(int i=0;i<n;i++)
arr[i]=z.nextInt();
int min=arr[0];
int j=0;
for(int i=1;i<n;i++){
if(arr[i]<min){
min= arr[i];
j=i;}}
int c=0;
for(int i=0;i<n;i++){
if(arr[i]==min)
c++;}
if(c>1)
System.out.print("Still Rozdil");
else
System.out.print(j+1);
}
} | Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 56a8f8a83bbce30a2119dd9e088681fb | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String args[]) {
//System.out.println("Hello World!");
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] arr = new int[n];
for(int i=0;i<n;i++){
arr[i]=s.nextInt();
}
int min = Integer.MAX_VALUE;
int mini = -1;
for(int i=0;i<arr.length;i++){
if(arr[i]<min){
min=arr[i];
mini=i;
}
}
arr[mini]=Integer.MAX_VALUE;
int ans=1;
for(int i=0;i<arr.length;i++){
if(arr[i]==min){
ans=0;
break;
}
}
if(ans==0){
System.out.print("Still Rozdil");
}
else{
System.out.print(mini+1);
}
}
} | Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 74eed1fe9c0e01b78f17425c073b51fd | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
public class LittleElephantRozdil {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int min=Integer.MAX_VALUE;
int Numbermin=0;
int minPos=0;
for(int i=0;i<n;i++){
int x= sc.nextInt();
if(x<min){
min=x;
Numbermin=0;
minPos=i;
}
else if(x==min)
Numbermin++;
}
if(Numbermin==0)
System.out.println(minPos+1);
else
System.out.println("Still Rozdil");
sc.close();
}
} | Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | c5181891e97c395a4b51ef9b5428d576 | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
long[] arr = new long[(int) n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextLong();
}
Long min = (long) Math.pow(10, 9);
int index = 0;
for (int i = 0; i < n; i++) {
if (min > arr[i]) {
min = arr[i];
index = i;
}
}
arr[index] = (long) Math.pow(10, 9);
if (n != 1) {
for (long l : arr) {
if (l == min) {
System.out.println("Still Rozdil");
return;
}
}
}
System.out.println(index + 1);
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 8ee2fa3239aaa9355f9b8d7ae05d3ac5 | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.*;
public class Lil {
public static void main(String args[]) {
Scanner in = new Scanner(System.in) ;
int n=in.nextInt();int m=Integer.MAX_VALUE,pos=0;;
int a[]=new int[n];
for(int i=0;i<n;i++) {
a[i]=in.nextInt();
}
for(int i=0;i<n;i++) {
if(a[i]<=m) {
m=a[i];
pos=i;
}
}
Arrays.sort(a);
System.out.println((n==1)?"1":(a[0]==a[1])?"Still Rozdil":pos+1) ;
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 9d599a69b435b78104074b409e5d9695 | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.*;
public class Main {
public static class Solution {
public String littleElephantAndRozdil() {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
long min = scanner.nextLong();
// n--;
boolean dupe = false;
int idx = 1;
for (int i = 1; i < n; i++) {
long num = scanner.nextLong();
if (num < min) {
dupe = false;
min = num;
idx = i + 1;
} else if (num == min) {
dupe = true;
}
}
scanner.close();
if (dupe) {
return "Still Rozdil";
}
String sol = "" + idx;
return sol;
}
}
public static void main(String[] args) {
Solution sol = new Solution();
System.out.println(sol.littleElephantAndRozdil());
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | eb0df1738601532a17105afcee4e2a8c | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner z=new Scanner (System.in);
int n=z.nextInt();
int []arr=new int [n];
for(int i=0;i<n;i++)
arr[i]=z.nextInt();
int min=arr[0];
int j=0;
for(int i=1;i<n;i++){
if(arr[i]<min){
min= arr[i];
j=i;}}
int c=0;
for(int i=0;i<n;i++){
if(arr[i]==min)
c++;}
if(c>1)
System.out.print("Still Rozdil");
else
System.out.print(j+1);
}
} | Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 1f88e905a85dee24e205e51803fbae5c | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | /* +_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+
+_+_+_+ Captain Levi's Code +_+_+_+_+_+_+_+_+
+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+ */
import java.util.*;
import java.io.*;
public class codeforces{
public static void main(String[] args){
int i,j,k,n,t,flag,min,store,ans;
Scanner sc = new Scanner(System.in);
// n = sc.nextInt();
t = sc.nextInt();
int a[] = new int[t];
for(i=0 ; i<t ;++i)
{
a[i] = sc.nextInt();
}
// int copy[] = new int[t];
// for(i=0 ;i<t ;++i)
// {
// copy[i]=a[i];
// }
// Arrays.sort(copy);
flag =0;min = Integer.MAX_VALUE ;
store =0;
// for(i=1; i<t ;++i)
// {
// if(copy[i]==copy[i-1])
// {
// flag=10;
// }
// }
for(i=0 ; i<t ; ++i)
{
if(a[i]<min)
{
min = a[i];
flag = 0;
store =i;
}
else if(min == a[i])
{
flag++;
}
}
if (flag == 0)
System.out.println(store+1);
else
System.out.println("Still Rozdil");
}
}
/* +_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+
+_+_+_+ Captain Levi's Code +_+_+_+_+_+_+_+_+
+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+ */
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 6f44f643a18104645a8755e8a60c543d | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.*;
public class LittleElephantAndRozdil {
public static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
int c = scan.nextInt();
int city[] = new int[c];
int min = 0;
int count = 0;
for(int i=0; i<c; i++) {
city[i] = scan.nextInt();
if(city[i] <= city[min])
min = i;
}
for(int i=0; i<c; i++) {
if(city[i] == city[min])
count++;
}
if(count < 2)
System.out.println(min + 1);
else
System.out.println("Still Rozdil");
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | b43b38b6b9ddd1cdd97a170a138cd8f2 | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Little_Elephant_and_Rozdil {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int arr[] =new int[n];
int temp = 1000000000;
int index=0;
for (int i = 0; i < n; i++) {
arr[i]=in.nextInt();
if(temp>arr[i]){
index =i;
temp=arr[i];
}
}
int flag = 0;
Arrays.sort(arr);
if(arr.length==1){
System.out.println("1");
}
else if(arr[1]==arr[0]){
System.out.println("Still Rozdil");
}
else{
System.out.println(index+1);
}
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | b14def4120dd9d4abf1d23843a972dd9 | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.io.*;
import java.util.*;
public class solution {
public static void merge(long arr[], int l, int m, int r) {
int n1 = m - l + 1;
int n2 = r - m;
long L[] = new long[n1];
long R[] = new long[n2];
for (int i = 0; i < n1; ++i)
L[i] = arr[l + i];
for (int j = 0; j < n2; ++j)
R[j] = arr[m + 1 + j];
int i = 0, j = 0;
int k = l;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
} else {
arr[k] = R[j];
j++;
}
k++;
}
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}
public static void sort(long arr[], int l, int r) {
if (l < r) {
int m = (l + r) / 2;
sort(arr, l, m);
sort(arr, m + 1, r);
merge(arr, l, m, r);
}
}
public static boolean check(int n) {
String s = "";
s += n;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != '4' && s.charAt(i) != '7') {
return false;
}
}
return true;
}
public static int gcd(int a, int b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
public static long findTrailingZeros(long n) {
// Initialize result
long count = 0;
// Keep dividing n by powers
// of 5 and update count
for (long i = 5; n / i >= 1; i *= 5)
count += n / i;
return count;
}
public static int ceilSearch(long arr[], int low, int high, long x) {
int mid;
if (x <= arr[low])
return low;
if (x > arr[high])
return -1;
mid = (low + high) / 2;
if (arr[mid] == x)
return mid;
else if (arr[mid] < x) {
if (mid + 1 <= high && x <= arr[mid + 1])
return mid + 1;
else
return ceilSearch(arr, mid + 1, high, x);
} else {
if (mid - 1 >= low && x > arr[mid - 1])
return mid;
else
return ceilSearch(arr, low, mid - 1, x);
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
long a[] = new long[n];
long min = Long.MAX_VALUE;
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i=0;i<n;i++){
a[i] = Integer.parseInt(st.nextToken());
min = Math.min(a[i],min);
}
int index= -1;
boolean flag = true;
for(int i=0;i<n;i++){
if(a[i] == min && index == -1){
index = i+1;
}
else if(a[i] == min && index != -1){
flag = false;
}
}
if(flag){
System.out.println(index);
}
else{
System.out.println("Still Rozdil");
}
}
} | Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | d4b3769461b3fbdb92c9eaae3d931b0d | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Rozdil {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int no = Integer.parseInt(bf.readLine());
StringTokenizer st = new StringTokenizer(bf.readLine());
int min = Integer.parseInt(st.nextToken());
int count = 0;
int city = 0;
for (int i = 1; i < no; i++) {
int dist = Integer.parseInt(st.nextToken());
if (dist<min){
min = dist;
count =0;
city =i;
}
else if (min==dist) count++;
}
if (count==0)
System.out.println(city+1);
else
System.out.println("Still Rozdil");
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | d67bf94a4399b99ad9892a799de7dd40 | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.Scanner;
import java.util.TreeMap;
public class A205 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
boolean bool = true;
int index = -1;
int number = Integer.MAX_VALUE;
for (int i = 1; i <= n; i++) {
int num = sc.nextInt();
if (num < number) {
bool = true;
number = num;
index = i;
}
else if (num == number) {
bool = false;
}
else {
}
}
if (bool) {
System.out.println(index);
}
else {
System.out.println("Still Rozdil");
}
}
} | Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | fc17c78302d78e543c0f1fd38564e09c | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
public class LittleElephantandRozdil {
public static void main(String[] args)throws Exception {
BufferedReader input =new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(input.readLine());
int[] arr= new int[n];
String s= input.readLine();
String[] s1 = s.split(" ");
int index=0,min=Integer.MAX_VALUE,count=0;
for(int i=0;i<n;i++)
{
arr[i]=Integer.parseInt(s1[i]);
if(arr[i]==min)
count++;
else if(arr[i]<min) {
min=arr[i];
count=1;
index=i;
}
}
if(count>1) {
System.out.println("Still Rozdil");
}
else {
System.out.println(index+1);
}
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 21e14addf6be3d74fb745babfe6b5d12 | train_003.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | //package codeforcespage2;
import java.util.*;
public class LittleElephantAndRozdil {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int n=in.nextInt();
ArrayList al=new ArrayList();
for(int i=0;i<n;i++)
{
al.add(in.nextInt());
}
ArrayList pre=new ArrayList(al);
//System.out.println(al);
Collections.sort(al);
//System.out.println(al);
Object first=al.get(0);
int fre=Collections.frequency(al, first);
//System.out.println("fre="+fre);
if(fre==1)
{
for(int i=0;i<pre.size();i++)
{
if(first==pre.get(i))
{
System.out.println(i+1);
return;
}
}
}
else
{
System.out.println("Still Rozdil");
}
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 11 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1ββ€βnββ€β105) β the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.