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 | 1ddbba229965e499920e6e909953f72a | train_001.jsonl | 1571236500 | Consider a square grid with $$$h$$$ rows and $$$w$$$ columns with some dominoes on it. Each domino covers exactly two cells of the grid that share a common side. Every cell is covered by at most one domino.Let's call a placement of dominoes on the grid perfectly balanced if no row and no column contains a pair of cells covered by two different dominoes. In other words, every row and column may contain no covered cells, one covered cell, or two covered cells that belong to the same domino.You are given a perfectly balanced placement of dominoes on a grid. Find the number of ways to place zero or more extra dominoes on this grid to keep the placement perfectly balanced. Output this number modulo $$$998\,244\,353$$$. | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in Actual solution is at the top
*
* @author daltao
*/
public class Main {
public static void main(String[] args) throws Exception {
Thread thread = new Thread(null, new TaskAdapter(), "daltao", 1 << 27);
thread.start();
thread.join();
}
static class TaskAdapter implements Runnable {
@Override
public void run() {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastInput in = new FastInput(inputStream);
FastOutput out = new FastOutput(outputStream);
TaskF solver = new TaskF();
solver.solve(1, in, out);
out.close();
}
}
static class TaskF {
NumberTheory.Modular mod = new NumberTheory.Modular(998244353);
NumberTheory.Factorial fact = new NumberTheory.Factorial(10000, mod);
NumberTheory.Composite comp = new NumberTheory.Composite(fact);
boolean[] rows;
boolean[] cols;
int[][] rowPutWays;
int[][] colPutWays;
int h;
int w;
public void solve(int testNumber, FastInput in, FastOutput out) {
h = in.readInt();
w = in.readInt();
rows = new boolean[h + 1];
cols = new boolean[w + 1];
int rowCnt = 0;
int colCnt = 0;
int n = in.readInt();
for (int i = 0; i < n; i++) {
int x1 = in.readInt();
int y1 = in.readInt();
int x2 = in.readInt();
int y2 = in.readInt();
rows[x1] = rows[x2] = true;
cols[y1] = cols[y2] = true;
}
for (int i = 1; i <= h; i++) {
if (rows[i]) {
continue;
}
rowCnt++;
}
for (int i = 1; i <= w; i++) {
if (cols[i]) {
continue;
}
colCnt++;
}
rowPutWays = new int[h + 1][h / 2 + 1];
colPutWays = new int[w + 1][w / 2 + 1];
ArrayUtils.deepFill(rowPutWays, -1);
ArrayUtils.deepFill(colPutWays, -1);
int ans = 0;
for (int i = 0; i <= h / 2; i++) {
for (int j = 0; j <= w / 2; j++) {
// check
if (i * 2 + j > rowCnt || j * 2 + i > colCnt) {
continue;
}
int rWay = rowPutWays(h, i);
int cWay = colPutWays(w, j);
int way = mod.mul(rWay, cWay);
way = mod.mul(way, comp.composite(rowCnt - i * 2, j));
way = mod.mul(way, comp.composite(colCnt - j * 2, i));
way = mod.mul(way, fact.fact(j));
way = mod.mul(way, fact.fact(i));
ans = mod.plus(ans, way);
}
}
out.println(ans);
}
public int rowPutWays(int i, int j) {
if (j < 0) {
return 0;
}
if (i <= 0) {
return j == 0 ? 1 : 0;
}
if (rowPutWays[i][j] == -1) {
if (rows[i]) {
rowPutWays[i][j] = rowPutWays(i - 1, j);
} else {
rowPutWays[i][j] = rowPutWays(i - 1, j);
if (i > 1 && !rows[i - 1]) {
rowPutWays[i][j] = mod.plus(rowPutWays[i][j], rowPutWays(i - 2, j - 1));
}
}
}
return rowPutWays[i][j];
}
public int colPutWays(int i, int j) {
if (j < 0) {
return 0;
}
if (i <= 0) {
return j == 0 ? 1 : 0;
}
if (colPutWays[i][j] == -1) {
if (cols[i]) {
colPutWays[i][j] = colPutWays(i - 1, j);
} else {
colPutWays[i][j] = colPutWays(i - 1, j);
if (i > 1 && !cols[i - 1]) {
colPutWays[i][j] = mod.plus(colPutWays[i][j], colPutWays(i - 2, j - 1));
}
}
}
return colPutWays[i][j];
}
}
static class FastInput {
private final InputStream is;
private byte[] buf = new byte[1 << 13];
private int bufLen;
private int bufOffset;
private int next;
public FastInput(InputStream is) {
this.is = is;
}
private int read() {
while (bufLen == bufOffset) {
bufOffset = 0;
try {
bufLen = is.read(buf);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (bufLen == -1) {
return -1;
}
}
return buf[bufOffset++];
}
public void skipBlank() {
while (next >= 0 && next <= 32) {
next = read();
}
}
public int readInt() {
int sign = 1;
skipBlank();
if (next == '+' || next == '-') {
sign = next == '+' ? 1 : -1;
next = read();
}
int val = 0;
if (sign == 1) {
while (next >= '0' && next <= '9') {
val = val * 10 + next - '0';
next = read();
}
} else {
while (next >= '0' && next <= '9') {
val = val * 10 - next + '0';
next = read();
}
}
return val;
}
}
static class FastOutput implements AutoCloseable, Closeable {
private StringBuilder cache = new StringBuilder(1 << 20);
private final Writer os;
public FastOutput(Writer os) {
this.os = os;
}
public FastOutput(OutputStream os) {
this(new OutputStreamWriter(os));
}
public FastOutput println(int c) {
cache.append(c).append('\n');
return this;
}
public FastOutput flush() {
try {
os.append(cache);
cache.setLength(0);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return this;
}
public void close() {
flush();
try {
os.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
static class ArrayUtils {
public static void deepFill(Object array, int val) {
if (!array.getClass().isArray()) {
throw new IllegalArgumentException();
}
if (array instanceof int[]) {
int[] intArray = (int[]) array;
Arrays.fill(intArray, val);
} else {
Object[] objArray = (Object[]) array;
for (Object obj : objArray) {
deepFill(obj, val);
}
}
}
}
static class NumberTheory {
public static class Modular {
int m;
public Modular(int m) {
this.m = m;
}
public Modular(long m) {
this.m = (int) m;
if (this.m != m) {
throw new IllegalArgumentException();
}
}
public Modular(double m) {
this.m = (int) m;
if (this.m != m) {
throw new IllegalArgumentException();
}
}
public int valueOf(int x) {
x %= m;
if (x < 0) {
x += m;
}
return x;
}
public int valueOf(long x) {
x %= m;
if (x < 0) {
x += m;
}
return (int) x;
}
public int mul(int x, int y) {
return valueOf((long) x * y);
}
public int plus(int x, int y) {
return valueOf(x + y);
}
public String toString() {
return "mod " + m;
}
}
public static class InverseNumber {
int[] inv;
public InverseNumber(int[] inv, int limit, NumberTheory.Modular modular) {
this.inv = inv;
inv[1] = 1;
int p = modular.m;
for (int i = 2; i <= limit; i++) {
int k = p / i;
int r = p % i;
inv[i] = modular.mul(-k, inv[r]);
}
}
public InverseNumber(int limit, NumberTheory.Modular modular) {
this(new int[limit + 1], limit, modular);
}
}
public static class Factorial {
int[] fact;
int[] inv;
NumberTheory.Modular modular;
public Factorial(int[] fact, int[] inv, NumberTheory.InverseNumber in, int limit,
NumberTheory.Modular modular) {
this.modular = modular;
this.fact = fact;
this.inv = inv;
fact[0] = inv[0] = 1;
for (int i = 1; i <= limit; i++) {
fact[i] = modular.mul(fact[i - 1], i);
inv[i] = modular.mul(inv[i - 1], in.inv[i]);
}
}
public Factorial(int limit, NumberTheory.Modular modular) {
this(new int[limit + 1], new int[limit + 1], new NumberTheory.InverseNumber(limit, modular), limit,
modular);
}
public int fact(int n) {
return fact[n];
}
}
public static class Composite {
final NumberTheory.Factorial factorial;
final NumberTheory.Modular modular;
public Composite(NumberTheory.Factorial factorial) {
this.factorial = factorial;
this.modular = factorial.modular;
}
public Composite(int limit, NumberTheory.Modular modular) {
this(new NumberTheory.Factorial(limit, modular));
}
public int composite(int m, int n) {
if (n > m) {
return 0;
}
return modular.mul(modular.mul(factorial.fact[m], factorial.inv[n]), factorial.inv[m - n]);
}
}
}
}
| Java | ["5 7 2\n3 1 3 2\n4 4 4 5", "5 4 2\n1 2 2 2\n4 3 4 4", "23 42 0"] | 2 seconds | ["8", "1", "102848351"] | NoteIn the first example, the initial grid looks like this:Here are $$$8$$$ ways to place zero or more extra dominoes to keep the placement perfectly balanced:In the second example, the initial grid looks like this:No extra dominoes can be placed here. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 76fc2b718342821ac9d5a132a03c925e | The first line contains three integers $$$h$$$, $$$w$$$, and $$$n$$$ ($$$1 \le h, w \le 3600$$$; $$$0 \le n \le 2400$$$), denoting the dimensions of the grid and the number of already placed dominoes. The rows are numbered from $$$1$$$ to $$$h$$$, and the columns are numbered from $$$1$$$ to $$$w$$$. Each of the next $$$n$$$ lines contains four integers $$$r_{i, 1}, c_{i, 1}, r_{i, 2}, c_{i, 2}$$$ ($$$1 \le r_{i, 1} \le r_{i, 2} \le h$$$; $$$1 \le c_{i, 1} \le c_{i, 2} \le w$$$), denoting the row id and the column id of the cells covered by the $$$i$$$-th domino. Cells $$$(r_{i, 1}, c_{i, 1})$$$ and $$$(r_{i, 2}, c_{i, 2})$$$ are distinct and share a common side. The given domino placement is perfectly balanced. | 2,600 | Output the number of ways to place zero or more extra dominoes on the grid to keep the placement perfectly balanced, modulo $$$998\,244\,353$$$. | standard output | |
PASSED | 6e2ff9b28c902cf937021d76304e695e | train_001.jsonl | 1571236500 | Consider a square grid with $$$h$$$ rows and $$$w$$$ columns with some dominoes on it. Each domino covers exactly two cells of the grid that share a common side. Every cell is covered by at most one domino.Let's call a placement of dominoes on the grid perfectly balanced if no row and no column contains a pair of cells covered by two different dominoes. In other words, every row and column may contain no covered cells, one covered cell, or two covered cells that belong to the same domino.You are given a perfectly balanced placement of dominoes on a grid. Find the number of ways to place zero or more extra dominoes on this grid to keep the placement perfectly balanced. Output this number modulo $$$998\,244\,353$$$. | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
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);
FSbalansirovannieRaspolozheniyaDomino solver = new FSbalansirovannieRaspolozheniyaDomino();
solver.solve(1, in, out);
out.close();
}
static class FSbalansirovannieRaspolozheniyaDomino {
int mod = 998244353;
public void solve(int testNumber, FastScanner in, PrintWriter out) {
int h = in.nextInt(), w = in.nextInt(), n = in.nextInt();
boolean[] r = new boolean[h], c = new boolean[w];
for (int i = 0; i < 2 * n; i++) {
r[in.nextInt() - 1] = true;
c[in.nextInt() - 1] = true;
}
int freeR = 0, freeC = 0;
for (int i = 0; i < h; i++) {
if (!r[i]) {
freeR++;
}
}
for (int i = 0; i < w; i++) {
if (!c[i]) {
freeC++;
}
}
Combinations combinations = new Combinations(7201, mod);
int[] a = calc(r), b = calc(c);
int[][] choose = MathUtils.choose(3600 + 1, 3600 + 1, mod);
long ans = 0;
for (int twos = 0; twos < a.length; twos++) {
for (int ones = 0; ones < b.length; ones++) {
int free1 = freeR - twos * 2;
int free2 = freeC - ones * 2;
if (free1 < ones || free2 < twos) {
continue;
}
long add = (long) a[twos] * b[ones] % mod;
add = add * choose[free1][ones] % mod;
add = add * choose[free2][twos] % mod;
add = add * combinations.fact[twos] % mod;
add = add * combinations.fact[ones] % mod;
ans += add;
}
}
out.println(ans % mod);
}
private int[] calc(boolean[] banned) {
int twos = banned.length / 2;
int[][] dp = new int[banned.length + 1][twos + 1];
dp[0][0] = 1;
for (int i = 0; i < banned.length; i++) {
int[] cur = dp[i];
if (i + 1 < banned.length && !banned[i] && !banned[i + 1]) {
int[] next = dp[i + 2];
for (int j = 0; j < twos; j++) {
next[j + 1] += cur[j];
if (next[j + 1] >= mod) {
next[j + 1] -= mod;
}
}
}
{
int[] next = dp[i + 1];
for (int j = 0; j <= twos; j++) {
next[j] += cur[j];
if (next[j] >= mod) {
next[j] -= mod;
}
}
}
}
return dp[banned.length];
}
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
}
public FastScanner(String fileName) {
try {
br = new BufferedReader(new FileReader(fileName));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public String next() {
while (st == null || !st.hasMoreElements()) {
String line = null;
try {
line = br.readLine();
} catch (IOException e) {
}
st = new StringTokenizer(line);
}
return st.nextToken();
}
}
static class Combinations {
public final int max;
public final int mod;
public int[] inv;
public int[] fact;
public int[] invFact;
public Combinations(int max, int mod) {
this.max = max;
this.mod = mod;
inv = MathUtils.inverses(max, mod);
fact = new int[max];
invFact = new int[max];
fact[0] = invFact[0] = 1;
for (int i = 1; i < max; i++) {
fact[i] = (int) ((long) fact[i - 1] * i % mod);
invFact[i] = (int) ((long) invFact[i - 1] * inv[i] % mod);
}
}
}
static class MathUtils {
public static int[][] choose(int n, int m, int mod) {
int[][] choose = new int[n][m];
for (int i = 0; i < n; i++) {
choose[i][0] = 1;
for (int j = 1; j < m && j <= i; j++) {
choose[i][j] = choose[i - 1][j - 1] + choose[i - 1][j];
if (choose[i][j] >= mod) {
choose[i][j] -= mod;
}
}
}
return choose;
}
public static int[] inverses(int size, int mod) {
int[] inv = new int[size];
inv[1] = 1;
for (int i = 2; i < inv.length; i++) {
inv[i] = (int) ((long) (mod - mod / i) * inv[mod % i] % mod);
}
return inv;
}
}
}
| Java | ["5 7 2\n3 1 3 2\n4 4 4 5", "5 4 2\n1 2 2 2\n4 3 4 4", "23 42 0"] | 2 seconds | ["8", "1", "102848351"] | NoteIn the first example, the initial grid looks like this:Here are $$$8$$$ ways to place zero or more extra dominoes to keep the placement perfectly balanced:In the second example, the initial grid looks like this:No extra dominoes can be placed here. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 76fc2b718342821ac9d5a132a03c925e | The first line contains three integers $$$h$$$, $$$w$$$, and $$$n$$$ ($$$1 \le h, w \le 3600$$$; $$$0 \le n \le 2400$$$), denoting the dimensions of the grid and the number of already placed dominoes. The rows are numbered from $$$1$$$ to $$$h$$$, and the columns are numbered from $$$1$$$ to $$$w$$$. Each of the next $$$n$$$ lines contains four integers $$$r_{i, 1}, c_{i, 1}, r_{i, 2}, c_{i, 2}$$$ ($$$1 \le r_{i, 1} \le r_{i, 2} \le h$$$; $$$1 \le c_{i, 1} \le c_{i, 2} \le w$$$), denoting the row id and the column id of the cells covered by the $$$i$$$-th domino. Cells $$$(r_{i, 1}, c_{i, 1})$$$ and $$$(r_{i, 2}, c_{i, 2})$$$ are distinct and share a common side. The given domino placement is perfectly balanced. | 2,600 | Output the number of ways to place zero or more extra dominoes on the grid to keep the placement perfectly balanced, modulo $$$998\,244\,353$$$. | standard output | |
PASSED | ac538393dd8a7d671bbaa66e859ea1d9 | train_001.jsonl | 1571236500 | Consider a square grid with $$$h$$$ rows and $$$w$$$ columns with some dominoes on it. Each domino covers exactly two cells of the grid that share a common side. Every cell is covered by at most one domino.Let's call a placement of dominoes on the grid perfectly balanced if no row and no column contains a pair of cells covered by two different dominoes. In other words, every row and column may contain no covered cells, one covered cell, or two covered cells that belong to the same domino.You are given a perfectly balanced placement of dominoes on a grid. Find the number of ways to place zero or more extra dominoes on this grid to keep the placement perfectly balanced. Output this number modulo $$$998\,244\,353$$$. | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author anand.oza
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
FBalancedDominoPlacements solver = new FBalancedDominoPlacements();
solver.solve(1, in, out);
out.close();
}
static class FBalancedDominoPlacements {
static final NumberTheory.ModM mod = new NumberTheory.ModM(998244353);
public void solve(int testNumber, InputReader in, PrintWriter out) {
int h = in.nextInt();
int w = in.nextInt();
int n = in.nextInt();
boolean[] row = new boolean[h];
boolean[] col = new boolean[w];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
int x = in.nextInt() - 1;
int y = in.nextInt() - 1;
row[x] = true;
col[y] = true;
}
}
boolean[][] twoAllowed = new boolean[2][];
twoAllowed[0] = findChunks(row);
twoAllowed[1] = findChunks(col);
long[][][] count = new long[2][][];
for (int i = 0; i < 2; i++) {
count[i] = populate(twoAllowed[i]);
}
long answer = 0;
for (int a = 0; a <= h; a++) {
for (int b = 0; b <= w; b++) {
long prod = mod.mult(count(count[0], a, b, twoAllowed[0].length), count(count[1], b, a, twoAllowed[1].length));
prod = mod.mult(prod, mod.mult(mod.fact(a), mod.fact(b)));
answer = mod.add(answer, prod);
}
}
out.println(answer);
}
private long count(long[][] count, int one, int two, int total) {
if (one >= count.length || two >= count.length)
return 0;
int ghost = total - one - 2 * two;
if (ghost < 0)
return 0;
one += ghost;
long result = count[one][two];
result = mod.mult(result, mod.ncr(one, ghost));
return result;
}
private long[][] populate(boolean[] twoAllowed) {
long[][] count = new long[twoAllowed.length + 1][twoAllowed.length + 1];
for (int one = 0, two = 0; f(one, two) < twoAllowed.length; one++) {
count[one][0] = 1;
}
for (int one = 0, two = 1; f(one, two) < twoAllowed.length; two++) {
if (twoAllowed[f(one, two)]) {
count[0][two] = count[0][two - 1];
}
}
for (int one = 1; f(one, 0) < twoAllowed.length; one++) {
for (int two = 1; f(one, two) < twoAllowed.length; two++) {
count[one][two] = mod.add(count[one][two], count[one - 1][two]);
if (twoAllowed[f(one, two)]) {
count[one][two] = mod.add(count[one][two], count[one][two - 1]);
}
}
}
return count;
}
static int f(int one, int two) {
return one + 2 * two - 1;
}
private boolean[] findChunks(boolean[] blocked) {
List<Integer> chunks = new ArrayList<>();
for (int i = 0, j = 0; i < blocked.length; i = j) {
while (j < blocked.length && blocked[i] == blocked[j])
j++;
if (!blocked[i]) {
chunks.add(j - i);
}
}
int sum = 0;
for (int x : chunks) {
sum += x;
}
boolean[] twoAllowed = new boolean[sum];
Arrays.fill(twoAllowed, true);
for (int i = 0, index = 0; i < chunks.size(); i++) {
twoAllowed[index] = false;
index += chunks.get(i);
}
return twoAllowed;
}
}
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());
}
}
static class NumberTheory {
private static void ASSERT(boolean assertion) {
if (!assertion)
throw new AssertionError();
}
public abstract static class Modulus<M extends NumberTheory.Modulus<M>> {
ArrayList<Long> factorial = new ArrayList<>();
ArrayList<Long> invFactorial = new ArrayList<>();
public abstract long modulus();
public Modulus() {
super();
factorial.add(1L);
invFactorial.add(1L);
}
public long fact(int n) {
while (factorial.size() <= n) {
factorial.add(mult(factorial.get(factorial.size() - 1), factorial.size()));
}
return factorial.get(n);
}
public long fInv(int n) {
while (invFactorial.size() <= n) {
invFactorial.add(div(invFactorial.get(invFactorial.size() - 1), invFactorial.size()));
}
return invFactorial.get(n);
}
public long ncr(int n, int r) {
ASSERT(n >= 0);
if (r < 0 || n < r)
return 0;
return mult(fact(n), mult(fInv(r), fInv(n - r)));
}
public long normalize(long x) {
x %= modulus();
if (x < 0)
x += modulus();
return x;
}
public long add(long a, long b) {
return normalize(a + b);
}
public long mult(long a, long b) {
return normalize(a * b);
}
public long div(long a, long b) {
return mult(a, inv(b));
}
public long inv(long value) {
long g = modulus(), x = 0, y = 1;
for (long r = value; r != 0; ) {
long q = g / r;
g %= r;
long temp = g;
g = r;
r = temp;
x -= q * y;
temp = x;
x = y;
y = temp;
}
ASSERT(g == 1);
ASSERT(y == modulus() || y == -modulus());
return normalize(x);
}
}
public static class ModM extends NumberTheory.Modulus<NumberTheory.ModM> {
private final long modulus;
public ModM(long modulus) {
this.modulus = modulus;
}
public long modulus() {
return modulus;
}
}
}
}
| Java | ["5 7 2\n3 1 3 2\n4 4 4 5", "5 4 2\n1 2 2 2\n4 3 4 4", "23 42 0"] | 2 seconds | ["8", "1", "102848351"] | NoteIn the first example, the initial grid looks like this:Here are $$$8$$$ ways to place zero or more extra dominoes to keep the placement perfectly balanced:In the second example, the initial grid looks like this:No extra dominoes can be placed here. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 76fc2b718342821ac9d5a132a03c925e | The first line contains three integers $$$h$$$, $$$w$$$, and $$$n$$$ ($$$1 \le h, w \le 3600$$$; $$$0 \le n \le 2400$$$), denoting the dimensions of the grid and the number of already placed dominoes. The rows are numbered from $$$1$$$ to $$$h$$$, and the columns are numbered from $$$1$$$ to $$$w$$$. Each of the next $$$n$$$ lines contains four integers $$$r_{i, 1}, c_{i, 1}, r_{i, 2}, c_{i, 2}$$$ ($$$1 \le r_{i, 1} \le r_{i, 2} \le h$$$; $$$1 \le c_{i, 1} \le c_{i, 2} \le w$$$), denoting the row id and the column id of the cells covered by the $$$i$$$-th domino. Cells $$$(r_{i, 1}, c_{i, 1})$$$ and $$$(r_{i, 2}, c_{i, 2})$$$ are distinct and share a common side. The given domino placement is perfectly balanced. | 2,600 | Output the number of ways to place zero or more extra dominoes on the grid to keep the placement perfectly balanced, modulo $$$998\,244\,353$$$. | standard output | |
PASSED | 54554cc6e74408b3d0ebf9b220c00849 | train_001.jsonl | 1571236500 | Consider a square grid with $$$h$$$ rows and $$$w$$$ columns with some dominoes on it. Each domino covers exactly two cells of the grid that share a common side. Every cell is covered by at most one domino.Let's call a placement of dominoes on the grid perfectly balanced if no row and no column contains a pair of cells covered by two different dominoes. In other words, every row and column may contain no covered cells, one covered cell, or two covered cells that belong to the same domino.You are given a perfectly balanced placement of dominoes on a grid. Find the number of ways to place zero or more extra dominoes on this grid to keep the placement perfectly balanced. Output this number modulo $$$998\,244\,353$$$. | 512 megabytes | import java.io.*;
import java.util.*;
public class F implements Runnable {
public static void main (String[] args) {new Thread(null, new F(), "_cf", 1 << 28).start();}
int MAX = 4000;
int[] fact, invFact;
public void run() {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
System.err.println("");
int H = fs.nextInt(), W = fs.nextInt();
int N = fs.nextInt();
int[] rowMarked = new int[H+1];
int[] colMarked = new int[W+1];
for(int i = 0; i < N; i++) {
int r1 = fs.nextInt(), c1 = fs.nextInt();
int r2 = fs.nextInt(), c2 = fs.nextInt();
rowMarked[r1] = rowMarked[r2] = 1;
colMarked[c1] = colMarked[c2] = 1;
}
int markedRows = 0, markedCols = 0;
for(int i : rowMarked) if(i == 1) markedRows++;
for(int i : colMarked) if(i == 1) markedCols++;
int[][] waysRow = buildWays(H, rowMarked);
int[][] waysCol = buildWays(W, colMarked);
setFact();
int res = 0;
for(int addH = 0; addH <= H; addH++) {
for(int addV = 0; addV <= W; addV++) {
if(H-2*addV < 0) continue;
if(W-2*addH < 0) continue;
int goodRows = waysRow[H][addV];
goodRows = mult(goodRows, nChooseK(H-2*addV-markedRows, addH));
int goodCols = waysCol[W][addH];
goodCols = mult(goodCols, nChooseK(W-2*addH-markedCols, addV));
int totWays = mult(goodRows, goodCols);
totWays = mult(totWays, mult(fact[addH], fact[addV]) );
// System.out.println(addH + " " + addV + " " + goodRows + " " + goodCols + " : " + totWays);
res = add(res, totWays);
}
}
out.println(res);
out.close();
}
int[][] buildWays(int H, int[] rowMarked) {
int[][] waysRow = new int[H+1][H+1];
waysRow[0][0] = 1;
for(int row = 1; row <= H; row++) {
for(int piece = 0; piece <= H; piece++) {
waysRow[row][piece] = add(waysRow[row][piece], waysRow[row-1][piece]);
if(piece > 0 && row > 1 && rowMarked[row] == 0 && rowMarked[row-1] == 0) {
waysRow[row][piece] = add(waysRow[row][piece], waysRow[row-2][piece-1]);
}
}
}
return waysRow;
}
int nChooseK(int n, int k) {
if(k < 0 || k > n) return 0;
int den = mult(invFact[k], invFact[n-k]);
return mult(fact[n], den);
}
int MOD = 998244353;
int add(int a, int b) {
a += b;
if(a >= MOD) a -= MOD;
return a;
}
int mult(long a, long b) {
a *= b;
if(a >= MOD) a %= MOD;
return (int)a;
}
void setFact() {
fact = new int[MAX];
fact[0] = 1;
for(int i = 1; i < MAX; i++) {
fact[i] = mult(i, fact[i-1]);
}
int[] invs = new int[MAX];
invs[0] = invs[1] = 1;
for (int i = 2; i < invs.length; ++i) {
int temp = MOD - (MOD / i);
temp = mult(temp, invs[MOD%i]);
invs[i] = temp;
}
invFact = new int[MAX];
invFact[0] = invs[0];
for(int i = 1; i < MAX; i++) {
invFact[i] = mult(invFact[i-1], invs[i]);
}
}
class FastScanner {
public int BS = 1<<16;
public char NC = (char)0;
byte[] buf = new byte[BS];
int bId = 0, size = 0;
char c = NC;
double num = 1;
BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
}
catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
public char nextChar(){
while(bId==size) {
try {
size = in.read(buf);
}catch(Exception e) {
return NC;
}
if(size==-1)return NC;
bId=0;
}
return (char)buf[bId++];
}
public int nextInt() {
return (int)nextLong();
}
public long nextLong() {
num=1;
boolean neg = false;
if(c==NC)c=nextChar();
for(;(c<'0' || c>'9'); c = nextChar()) {
if(c=='-')neg=true;
}
long res = 0;
for(; c>='0' && c <='9'; c=nextChar()) {
res = (res<<3)+(res<<1)+c-'0';
num*=10;
}
return neg?-res:res;
}
public double nextDouble() {
double cur = nextLong();
return c!='.' ? cur:cur+nextLong()/num;
}
public String next() {
StringBuilder res = new StringBuilder();
while(c<=32)c=nextChar();
while(c>32) {
res.append(c);
c=nextChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while(c<=32)c=nextChar();
while(c!='\n') {
res.append(c);
c=nextChar();
}
return res.toString();
}
public boolean hasNext() {
if(c>32)return true;
while(true) {
c=nextChar();
if(c==NC)return false;
else if(c>32)return true;
}
}
public int[] nextIntArray(int n) {
int[] res = new int[n];
for(int i = 0; i < n; i++) res[i] = nextInt();
return res;
}
}
} | Java | ["5 7 2\n3 1 3 2\n4 4 4 5", "5 4 2\n1 2 2 2\n4 3 4 4", "23 42 0"] | 2 seconds | ["8", "1", "102848351"] | NoteIn the first example, the initial grid looks like this:Here are $$$8$$$ ways to place zero or more extra dominoes to keep the placement perfectly balanced:In the second example, the initial grid looks like this:No extra dominoes can be placed here. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 76fc2b718342821ac9d5a132a03c925e | The first line contains three integers $$$h$$$, $$$w$$$, and $$$n$$$ ($$$1 \le h, w \le 3600$$$; $$$0 \le n \le 2400$$$), denoting the dimensions of the grid and the number of already placed dominoes. The rows are numbered from $$$1$$$ to $$$h$$$, and the columns are numbered from $$$1$$$ to $$$w$$$. Each of the next $$$n$$$ lines contains four integers $$$r_{i, 1}, c_{i, 1}, r_{i, 2}, c_{i, 2}$$$ ($$$1 \le r_{i, 1} \le r_{i, 2} \le h$$$; $$$1 \le c_{i, 1} \le c_{i, 2} \le w$$$), denoting the row id and the column id of the cells covered by the $$$i$$$-th domino. Cells $$$(r_{i, 1}, c_{i, 1})$$$ and $$$(r_{i, 2}, c_{i, 2})$$$ are distinct and share a common side. The given domino placement is perfectly balanced. | 2,600 | Output the number of ways to place zero or more extra dominoes on the grid to keep the placement perfectly balanced, modulo $$$998\,244\,353$$$. | standard output | |
PASSED | 696b3ad987cf9739f72dbd4bafde7f82 | train_001.jsonl | 1571236500 | Consider a square grid with $$$h$$$ rows and $$$w$$$ columns with some dominoes on it. Each domino covers exactly two cells of the grid that share a common side. Every cell is covered by at most one domino.Let's call a placement of dominoes on the grid perfectly balanced if no row and no column contains a pair of cells covered by two different dominoes. In other words, every row and column may contain no covered cells, one covered cell, or two covered cells that belong to the same domino.You are given a perfectly balanced placement of dominoes on a grid. Find the number of ways to place zero or more extra dominoes on this grid to keep the placement perfectly balanced. Output this number modulo $$$998\,244\,353$$$. | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author lewin
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
FBalancedDominoPlacements solver = new FBalancedDominoPlacements();
solver.solve(1, in, out);
out.close();
}
static class FBalancedDominoPlacements {
int mod = 998244353;
int[] solve(boolean[] x) {
int[][] ret = new int[x.length + 1][x.length / 2 + 1];
ret[0][0] = 1;
for (int i = 1; i <= x.length; i++) {
for (int j = 0; j < x.length / 2 + 1; j++) {
ret[i][j] += ret[i - 1][j];
if (ret[i][j] >= mod) ret[i][j] -= mod;
if (j >= 1 && i >= 2 && !x[i - 1] && !x[i - 2]) {
ret[i][j] += ret[i - 2][j - 1];
if (ret[i][j] >= mod) ret[i][j] -= mod;
}
}
}
return ret[x.length];
}
public void solve(int testNumber, InputReader in, OutputWriter out) {
int h = in.nextInt(), w = in.nextInt(), n = in.nextInt();
boolean[] row = new boolean[h];
boolean[] col = new boolean[w];
for (int i = 0; i < n; i++) {
int r1 = in.nextInt(), c1 = in.nextInt(), r2 = in.nextInt(), c2 = in.nextInt();
r1--;
c1--;
r2--;
c2--;
row[r1] = row[r2] = col[c1] = col[c2] = true;
}
int[] r1 = solve(row), r2 = solve(col);
int f1 = 0, f2 = 0;
for (int i = 0; i < h; i++) if (!row[i]) f1++;
for (int i = 0; i < w; i++) if (!col[i]) f2++;
int[][] comb = Utils.getComb(4001, mod);
long[] fact = new long[4001];
fact[0] = 1;
for (int i = 1; i < fact.length; i++) fact[i] = fact[i - 1] * i % mod;
long ans = 0;
for (int t1 = 0; t1 < r1.length; t1++) {
if (r1[t1] == 0) continue;
for (int t2 = 0; t2 < r2.length; t2++) {
if (r2[t2] == 0) continue;
int free1 = f1 - t1 * 2;
int free2 = f2 - t2 * 2;
if (free1 >= t2 && free2 >= t1) {
ans = (ans + 1L * comb[free1][t2] * comb[free2][t1] % mod * r1[t1] % mod * r2[t2] % mod * fact[t2] % mod * fact[t1]) % mod;
}
}
}
out.println(ans);
}
}
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 close() {
writer.close();
}
public void println(long i) {
writer.println(i);
}
}
static class Utils {
public static int[][] getComb(int sz, int mod) {
int[][] comb = new int[sz][sz];
for (int i = 0; i < sz; i++) {
comb[i][0] = 1;
for (int j = 1; j <= i; j++) {
comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
if (comb[i][j] >= mod) comb[i][j] -= mod;
}
}
return comb;
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1 << 16];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (this.numChars == -1) {
throw new InputMismatchException();
} else {
if (this.curChar >= this.numChars) {
this.curChar = 0;
try {
this.numChars = this.stream.read(this.buf);
} catch (IOException var2) {
throw new InputMismatchException();
}
if (this.numChars <= 0) {
return -1;
}
}
return this.buf[this.curChar++];
}
}
public int nextInt() {
int c;
for (c = this.read(); isSpaceChar(c); c = this.read()) {
;
}
byte sgn = 1;
if (c == 45) {
sgn = -1;
c = this.read();
}
int res = 0;
while (c >= 48 && c <= 57) {
res *= 10;
res += c - 48;
c = this.read();
if (isSpaceChar(c)) {
return res * sgn;
}
}
throw new InputMismatchException();
}
public static boolean isSpaceChar(int c) {
return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
}
}
}
| Java | ["5 7 2\n3 1 3 2\n4 4 4 5", "5 4 2\n1 2 2 2\n4 3 4 4", "23 42 0"] | 2 seconds | ["8", "1", "102848351"] | NoteIn the first example, the initial grid looks like this:Here are $$$8$$$ ways to place zero or more extra dominoes to keep the placement perfectly balanced:In the second example, the initial grid looks like this:No extra dominoes can be placed here. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 76fc2b718342821ac9d5a132a03c925e | The first line contains three integers $$$h$$$, $$$w$$$, and $$$n$$$ ($$$1 \le h, w \le 3600$$$; $$$0 \le n \le 2400$$$), denoting the dimensions of the grid and the number of already placed dominoes. The rows are numbered from $$$1$$$ to $$$h$$$, and the columns are numbered from $$$1$$$ to $$$w$$$. Each of the next $$$n$$$ lines contains four integers $$$r_{i, 1}, c_{i, 1}, r_{i, 2}, c_{i, 2}$$$ ($$$1 \le r_{i, 1} \le r_{i, 2} \le h$$$; $$$1 \le c_{i, 1} \le c_{i, 2} \le w$$$), denoting the row id and the column id of the cells covered by the $$$i$$$-th domino. Cells $$$(r_{i, 1}, c_{i, 1})$$$ and $$$(r_{i, 2}, c_{i, 2})$$$ are distinct and share a common side. The given domino placement is perfectly balanced. | 2,600 | Output the number of ways to place zero or more extra dominoes on the grid to keep the placement perfectly balanced, modulo $$$998\,244\,353$$$. | standard output | |
PASSED | c88bb8940f0e768a686412ef8809a888 | train_001.jsonl | 1571236500 | Consider a square grid with $$$h$$$ rows and $$$w$$$ columns with some dominoes on it. Each domino covers exactly two cells of the grid that share a common side. Every cell is covered by at most one domino.Let's call a placement of dominoes on the grid perfectly balanced if no row and no column contains a pair of cells covered by two different dominoes. In other words, every row and column may contain no covered cells, one covered cell, or two covered cells that belong to the same domino.You are given a perfectly balanced placement of dominoes on a grid. Find the number of ways to place zero or more extra dominoes on this grid to keep the placement perfectly balanced. Output this number modulo $$$998\,244\,353$$$. | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskF solver = new TaskF();
solver.solve(1, in, out);
out.close();
}
static class TaskF {
static final long MODULO = 998244353;
static long[] invs;
static long[] facts;
static long[] invfacts;
static {
int k = (int) 5000;
invs = new long[k + 2];
invs[1] = 1;
for (int i = 2; i <= k + 1; ++i) {
invs[i] = ((MODULO - (MODULO / i) * (long) invs[(int) (MODULO % i)] % MODULO) % MODULO);
}
facts = new long[k + 2];
invfacts = new long[k + 2];
facts[0] = 1;
invfacts[0] = 1;
for (int i = 1; i <= k + 1; ++i) {
facts[i] = (facts[i - 1] * (long) i % MODULO);
invfacts[i] = (invfacts[i - 1] * (long) invs[i] % MODULO);
}
}
public void solve(int testNumber, InputReader in, PrintWriter out) {
int h = in.nextInt();
int w = in.nextInt();
int n = in.nextInt();
boolean[] rowTaken = new boolean[h];
boolean[] colTaken = new boolean[w];
for (int i = 0; i < 2 * n; ++i) {
rowTaken[in.nextInt() - 1] = true;
colTaken[in.nextInt() - 1] = true;
}
int rowFree = 0;
for (boolean x : rowTaken) if (!x) ++rowFree;
int colFree = 0;
for (boolean x : colTaken) if (!x) ++colFree;
int[] rowWays = findWays(rowTaken);
int[] colWays = findWays(colTaken);
long res = 0;
for (int nr = 0; nr < rowWays.length; ++nr)
if (rowWays[nr] > 0) {
for (int nc = 0; nc < colWays.length && nr + 2 * nc <= colFree && nc + 2 * nr <= rowFree; ++nc)
if (colWays[nc] > 0) {
res += rowWays[nr] * (long) colWays[nc] % MODULO * facts[rowFree - 2 * nr] % MODULO * invfacts[rowFree - 2 * nr - nc] % MODULO
* facts[colFree - 2 * nc] % MODULO * invfacts[colFree - 2 * nc - nr];
res %= MODULO;
}
}
out.println(res);
}
private int[] findWays(boolean[] rowTaken) {
int[][] ways = new int[3][rowTaken.length / 2 + 1];
ways[2][0] = 1;
int cur = -1;
for (int i = 0; i < rowTaken.length; ++i) {
cur = i % 3;
int prev = (i + 2) % 3;
int pprev = (i + 1) % 3;
Arrays.fill(ways[cur], 0);
for (int j = 0; j < ways[cur].length; ++j) {
if (ways[prev][j] > 0) {
ways[cur][j] += ways[prev][j];
}
if (ways[pprev][j] > 0 && !rowTaken[i] && !rowTaken[i - 1]) {
ways[cur][j + 1] += ways[pprev][j];
}
if (ways[cur][j] >= MODULO) ways[cur][j] -= MODULO;
}
}
return ways[cur];
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["5 7 2\n3 1 3 2\n4 4 4 5", "5 4 2\n1 2 2 2\n4 3 4 4", "23 42 0"] | 2 seconds | ["8", "1", "102848351"] | NoteIn the first example, the initial grid looks like this:Here are $$$8$$$ ways to place zero or more extra dominoes to keep the placement perfectly balanced:In the second example, the initial grid looks like this:No extra dominoes can be placed here. | Java 8 | standard input | [
"dp",
"combinatorics"
] | 76fc2b718342821ac9d5a132a03c925e | The first line contains three integers $$$h$$$, $$$w$$$, and $$$n$$$ ($$$1 \le h, w \le 3600$$$; $$$0 \le n \le 2400$$$), denoting the dimensions of the grid and the number of already placed dominoes. The rows are numbered from $$$1$$$ to $$$h$$$, and the columns are numbered from $$$1$$$ to $$$w$$$. Each of the next $$$n$$$ lines contains four integers $$$r_{i, 1}, c_{i, 1}, r_{i, 2}, c_{i, 2}$$$ ($$$1 \le r_{i, 1} \le r_{i, 2} \le h$$$; $$$1 \le c_{i, 1} \le c_{i, 2} \le w$$$), denoting the row id and the column id of the cells covered by the $$$i$$$-th domino. Cells $$$(r_{i, 1}, c_{i, 1})$$$ and $$$(r_{i, 2}, c_{i, 2})$$$ are distinct and share a common side. The given domino placement is perfectly balanced. | 2,600 | Output the number of ways to place zero or more extra dominoes on the grid to keep the placement perfectly balanced, modulo $$$998\,244\,353$$$. | standard output | |
PASSED | b1842869479e2cbcb29d87cbf8fd1fd1 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.io.*;
import java.util.*;
public class A
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(bu.readLine()),a[][]=new int[n][2],i,j;
for(i=0;i<n;i++)
{
String s[]=bu.readLine().split(" ");
int x,sum=0;
for(j=0;j<4;j++)
{
x=Integer.parseInt(s[j]);
sum+=x;
}
a[i][0]=sum;
a[i][1]=i;
}
Arrays.sort(a,new Comparator<int[]>(){
public int compare(int o1[],int o2[])
{
if(o1[0]<o2[0]) return 1;
else if(o1[0]==o2[0]) return o1[1]>o2[1]?1:-1;
else return -1;
}});
int ans=0;
for(i=0;i<n;i++)
if(a[i][1]==0) {ans=i+1; break;}
System.out.print(ans);
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 1a2d4ae80da823ebcd6ec296ee5cf08e | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.Comparator;
import java.util.Scanner;
import java.util.stream.IntStream;
public class TheRank {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int nrRows = scanner.nextInt();
final int[][] grid = IntStream.range(0, nrRows)
.mapToObj(i -> IntStream.range(0, 4).map(j -> scanner.nextInt()).toArray())
.toArray(int[][]::new);
System.out.println(solution(grid));
}
private static int solution(int[][] grid) {
int thomasScore = IntStream.range(0, grid.length).limit(1).map(i -> IntStream.range(0, 4).map(j -> grid[i][j]).sum()).reduce(Integer::sum).getAsInt();
int[] scores = IntStream.range(0, grid.length).skip(1).map(i -> IntStream.range(0, 4).map(j -> grid[i][j]).sum())
.boxed()
.sorted(Comparator.reverseOrder())
.mapToInt(x -> x)
.toArray();
return searchInsert(scores, thomasScore);
}
public static int searchInsert(int[] nums, int target) {
if(nums.length == 0 || target > nums[0]){
return 1;
}
if ( target < nums[nums.length - 1])
return nums.length + 1;
int l = 0;
int r = nums.length-1;
while(l < r){
int m = l+(r-l)/2;
if(target >= nums[m]){
r = m;
}else{
l = m+1;
}
}
return r + 1;
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 16f7f25ddc510bc2fe97f685c861e975 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;
public class Main implements Runnable, AutoCloseable {
Scanner in = new Scanner(new BufferedInputStream(System.in));
PrintStream out = new PrintStream(new BufferedOutputStream(System.out));
@Override
public void run() {
// int t = in.nextInt();
//// int t = 1;
// for (int i = 0; i < t; i++) {
doOnce();
// }
}
private void doOnce() {
int n = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = (in.nextInt() + in.nextInt() + in.nextInt() + in.nextInt()) * 1000 - i;
}
int son = a[0];
Arrays.sort(a);
out.println(n - Arrays.binarySearch(a, son));
}
// if (test(n, m, k)) {
// out.println("YES");
// } else {
// out.println("NO");
// }
public static void main(String[] args) {
try (Main main = new Main()) {
main.run();
}
}
@Override
public void close() {
out.close();
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 3cb4bbd6e42a9a551d181430e9458d1f | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes |
import java.io.*;
import java.util.*;
import java.math.*;
import java.net.StandardSocketOptions;
public class Main {
static long sx = 0, sy = 0, mod = (long) (998244353);
static ArrayList<Integer>[] a;
// static ArrayList<Long> p;
static HashMap<ArrayList<Integer>, Long> hm = new HashMap<>();
static Double[][] dp;
static boolean[][] vis;
static long[] far;
static int[] fa;
public static PrintWriter out = new PrintWriter(System.out);
static ArrayList<pair> pa = new ArrayList<>();
static long[] fact = new long[(int) 1e6];
static StringBuilder sb = new StringBuilder();
static boolean cycle = false;
static long mo = (long) (1e9 + 7);
static int[] c, col;
// static int n = 0, m, x, k;
// static int ans = Integer.MAX_VALUE;
static boolean b = false;
static boolean[] reach = new boolean[6000];
static int[][] par;
static int[] depth;
static int[] size;
static long[] pow;
static int time = 0;
static int[] disc;
static int[] low;
static char[][] ch;
// static TreeSet<Integer> hm = new TreeSet<>();
static double p, q;
static int cnt = 0;
static int[][] dirs = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 }, };
public static void main(String[] args) throws IOException {
// Scanner scn = new Scanner(new BufferedReader(new
// InputStreamReader(System.in)));
Reader scn = new Reader();
ArrayList<pair> p = new ArrayList<>();
int n = scn.nextInt();
for(int i=0; i<n; i++)
p.add(new pair(i, scn.nextInt(), scn.nextInt(), scn.nextInt(), scn.nextInt()));
Collections.sort(p);
for(int i=0; i<p.size(); i++)
if(p.get(i).i == 0){
System.out.println(i+1);
return;
}
}
// _________________________TEMPLATE_____________________________________________________________
// public static long lcm(long x, long y) {
//
// return (x * y) / gcd(x, y);
// }
//
// private static long gcd(long x, long y) {
// if (x == 0)
// return y;
//
// return gcd(y % x, x);
// }
//
// static class comp implements Comparator<Integer> {
//
// @Override
// public int compare(Integer p1, Integer p2) {
//
// return p2 - p1;
//
// }
// }
//
// }
//
// public static long pow(long a, long b) {
//
// if (b < 0)
// return 0;
// if (b == 0 || b == 1)
// return (long) Math.pow(a, b);
//
// if (b % 2 == 0) {
//
// long ret = pow(a, b / 2);
// ret = (ret % mod * ret % mod) % mod;
// return ret;
// }
//
// else {
// return ((pow(a, b - 1) % mod) * a % mod) % mod;
// }
// }
private static class pair implements Comparable<pair> {
int i,a,b,c,d;
int sum=0;
pair(int i,int a, int b, int c, int d) {
this.i = i;
this.a = a;
this.b = b;
this.c = c;
this.d = d;
sum+=a+b+c+d;
}
@Override
public int compareTo(pair o) {
if(this.sum!=o.sum)
return o.sum-this.sum;
else
return this.i-o.i;
}
// @Override
//
// public int hashCode() {
// return i;
// }
//
// @Override
//
// public boolean equals(Object o) {
//
// pair p = (pair) o;
// return this.i == p.i;
// }
}
private static class pair1 {
int a, b;
pair1(int a, int b) {
this.a = a;
this.b = b;
}
}
private static String reverse(String s) {
return new StringBuilder(s).reverse().toString();
}
public static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[1000000 + 1]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
public int[] nextIntArray(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
public int[][] nextInt2DArray(int m, int n) throws IOException {
int[][] arr = new int[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++)
arr[i][j] = nextInt();
}
return arr;
}
public long[][] nextInt2DArrayL(int m, int n) throws IOException {
long[][] arr = new long[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++)
arr[i][j] = nextInt();
}
return arr;
}
// kickstart - Solution
// atcoder - Main
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 7eb615192c4dd332f0f304b6dab8ec50 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.BigDecimal;
import java.math.BigInteger;
public class JavaApplication9 {
//***************************************************************************************
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
//****************************************************************************************
/*static boolean isp(long n)
{
if(n==3||n==2)
return true;
if(n%2==0||n%3==0||n==1)
return false;
for(int i=5;i*i<=n;i=i+6)
{
if(n%i==0||n%(i+2)==0)
return false;
}
return true;
}*/
//********************************************************
/* static int factorial(int n)
{
if (n == 0)
return 1;
return n*factorial(n-1);
} */
/* public int BinaryToDecimal(int binaryNumber){
int decimal = 0;
int p = 0;
while(true){
if(binaryNumber == 0){
break;
} else {
int temp = binaryNumber%10;
decimal += temp*Math.pow(2, p);
binaryNumber = binaryNumber/10;
p++;
}
}
return decimal;
}*/
/*-********************** Start *********************************-*/
public static void main(String[] args) throws IOException{
//----------------------- Input ---------------------------------------//
Reader st=new Reader();
//Scanner in=new Scanner(System.in);
//HashMap dp = new HashMap();
//String s=new String();
int n=st.nextInt();
//Vector v=new Vector();
int s=0,x=1,y=0;
for(int i=0;i<4;i++)
{
s=s+st.nextInt();
}
for(int i=1;i<=(n*4)-4;i++)
{
y=y+st.nextInt();
if(i%4==0){ if(y>s)x++; y=0; }
}
System.out.println(x);
}}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 20c132be7f5c0df2cd8169e4f3c03450 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
public class Rank{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int x[] = new int[n];
for(int i = 0; i< n; i++){
for(int j = 0; j< 4; j++)
x[i] += sc.nextInt();
}
int rank = 1;
for(int i = 0; i< n; i++){
if(x[0]< x[i])
rank++;
}
System.out.println(rank);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | b817dbde16a1dae53c1282b495e585ff | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | //package com.baba;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int sum = s.nextInt() + s.nextInt() + s.nextInt() + s.nextInt();
int ans = 1;
for (int i = 1; i < n; i++) {
int temp = s.nextInt() + s.nextInt() + s.nextInt() + s.nextInt();
if (temp > sum) {
ans++;
}
}
System.out.println(ans);
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 9e00976051ace67d42d270344f5c14bb | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | //package com.baba;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] arr = new int[n];
int i = 0;
while (n-- > 0) {
arr[i] += s.nextInt();
arr[i] += s.nextInt();
arr[i] += s.nextInt();
arr[i] += s.nextInt();
i++;
}
i = arr[0];
Arrays.sort(arr);
for (int j=arr.length-1; j>=0; j--){
if (arr[j]==i){
i = arr.length-j;
break;
}
}
System.out.println(i);
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 75f76c67b83a3ceadebfcd6b1e593c82 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.Scanner;
public class The_Rank {
public static void main(String args[]) {
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++)
for (int j = 0; j < 4; j++)
a[i] += reader.nextInt();
reader.close();
int rank = 1;
for (int i = 1; i < n; i++) {
if (a[i] > a[0])
rank++;
}
System.out.print(rank);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 79118706e6933c203648c9ad9cacde5a | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
import java.util.*;
public class rank
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int a,b,c,d,n,i;
n=s.nextInt();
int sum[]=new int[n];
a=s.nextInt();
b=s.nextInt();
c=s.nextInt();
d=s.nextInt();
int x=a+b+c+d;
sum[0]=a+b+c+d;
for(i=1;i<n;i++)
{
a=s.nextInt();
b=s.nextInt();
c=s.nextInt();
d=s.nextInt();
sum[i]=a+b+c+d;
}
Arrays.sort(sum);
for(i=n-1;i>=0;i--)
{
if(x==sum[i])
{
System.out.println(n-i);
break;
}
}
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | a7fb082fefd8447ef1524d71b233f302 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
import java.lang.*;
public class codejam
{
public static void main(String[] args)
{
// the code goes here//
Scanner in=new Scanner(System.in);
int n,s=0,c=1,max=0;
n=in.nextInt();
int num=0;
for(int i=1;i<=n;i++)
{
int a1,b1,a2,b2;
a1=in.nextInt();
b1=in.nextInt();
a2=in.nextInt();
b2=in.nextInt();
s=s+(a1+a2+b1+b2);
if(i==1)
{
max=s;
}
else if(s>max)
{
c++;
}
s=0;
}
System.out.println(c);
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 5404046635e69dbf7b3bba19973e3198 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
import java.lang.*;
public class codejam
{
public static void main(String[] args)
{
// the code goes here//
Scanner in=new Scanner(System.in);
int n,s=0,c=1,max=0;
n=in.nextInt();
int num=0;
for(int i=1;i<=n;i++)
{
int a1,b1,a2,b2;
a1=in.nextInt();
b1=in.nextInt();
a2=in.nextInt();
b2=in.nextInt();
s=s+(a1+a2+b1+b2);
if(i==1)
{
max=s;
}
else if(s>max)
{
c++;
}
s=0;
}
System.out.println(c);
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | bbe5cca15a0b903dd099758e62ab59c0 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import org.w3c.dom.ls.LSOutput;
import java.security.MessageDigest;
import java.util.*;
import java.math.*;
import java.lang.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
ArrayList<Integer> a = new ArrayList<> ();
int ans = 0;
for (int i = 0; i < n; ++i){
int sum = 0;
for (int j = 0; j < 4; ++j)
sum += in.nextInt();
a.add(sum);
if (a.get(i) > a.get(0))
ans++;
}
System.out.println(ans + 1);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 87d27e7a3a698584c4ec9cdc8da6cdfc | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.Scanner;
public class Rank_1017A {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int a = s.nextInt();
int b = s.nextInt();
int c = s.nextInt();
int d = s.nextInt();
int ts = a+b+c+d;
int count = 0;
for(int i=1; i<n; i++){
int x1 = s.nextInt();
int x2 = s.nextInt();
int x3 = s.nextInt();
int x4 = s.nextInt();
if(x1+x2+x3+x4 > ts){
count++;
}
}
System.out.println(count+1);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | f322fa8a400aedc4f70d8a6849a1716a | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 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];
for(int i=0;i<n;i++) {
for(int j=0;j<4;j++) {
x[i]+=sc.nextInt();
}
}
int sum=1;
for(int i=0;i<n;i++) {
if(i!=0) {
if(x[i]>x[0])
sum++;
}
}
System.out.print(sum);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 9f47bb5fd164dd5882d812d36527eb35 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class TheRank {
public static void main(String[]args) {
Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int n=s.nextInt();
int cnt=1;
int thomas=s.nextInt()+s.nextInt()+s.nextInt()+s.nextInt();
while (n>1){
int sum=0;
int a=s.nextInt();
int b=s.nextInt();
int c=s.nextInt();
int d=s.nextInt();
sum=a+b+c+d;
if(sum>thomas){
cnt++;
}
n--;
}
System.out.println(cnt);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 662ae70da4c7e3a6dc6e9a24235cd58d | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.Scanner;
public class The_Rank_1017A {
public static void main(String[] args) {
int num, id= 0;
int[][] estudiantes;
int suma[];
Scanner scanner = new Scanner(System.in);
num = scanner.nextInt();
estudiantes= new int[num][4];
suma = new int[num];
if(num>=1&&num<=1000) {
//Poniendo calificaciones
for(int i=0;i<num;i++) {
for(int j=0;j<4;j++) {
estudiantes[i][j] = scanner.nextInt();
suma[i]+=estudiantes[i][j];
}
}
//De mayor a menor
for(int i=0;i<num;i++)
for(int j=0;j<suma.length-i-1;j++) {
if(suma[j]<suma[j+1]) {
int temp=suma[j+1];
suma[j+1] = suma[j];
suma[j]= temp;
id =(id==j)?id+1:id;
}
}
System.out.println(id+1);
}
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 870532b20189ccf6859bdb033a649caf | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.Scanner;
public class THERank {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int rank=1;
long sum=0;
int x=1;
int n=sc.nextInt();
for(int i=0;i<n;i++){
long a=sc.nextLong();
long b=sc.nextLong();
long c=sc.nextLong();
long d=sc.nextLong();
sum=a+b+c+d;
if(i==0){
x= (int) sum;
}
else if(sum>x){
rank++;
}
}
System.out.println(rank);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | a6fa5c73042c77ca0d12007836691c08 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.Scanner;
public class test {
static Scanner sc = new Scanner(System.in);
static int read() {
final int r1 = sc.nextInt(), r2 = sc.nextInt(), r3 = sc.nextInt(), r4 = sc.nextInt();
return r1 + r2 + r3 + r4;
}
public static void main(final String[] args) {
final int n = sc.nextInt(), s = read();
int p = 1;
for (int i=1; i<n; i++) {
if (read() > s) {
p++;
}
}
System.out.println(p);
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 4fcfcf442f13b8b9caf4bdf923747f58 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | // practice with kaiboy
import java.io.*;
import java.util.*;
public class CF1017A extends PrintWriter {
CF1017A() { super(System.out, true); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1017A o = new CF1017A(); o.main(); o.flush();
}
void main() {
int n = sc.nextInt();
int x = sc.nextInt() + sc.nextInt() + sc.nextInt() + sc.nextInt();
int r = 1;
while (--n > 0) {
int y = sc.nextInt() + sc.nextInt() + sc.nextInt() + sc.nextInt();
if (x < y)
r++;
}
println(r);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 13b6e3754c7683ab0e107213e4111ce4 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.Scanner;
public class TheRank {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int n,max=0,m=1,i;
n=input.nextInt();
for ( i = 0; i < n; i++) {
int a,b,c,d,sum=0;
a=input.nextInt();
b=input.nextInt();
c=input.nextInt();
d=input.nextInt();
if(i==0){
max=a+b+c+d;
}else{
sum=a+b+c+d;
}
if(sum>max){
m++;
}
}
System.out.println(m);
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 631db5ad5af9e94ecd587eb33469134b | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*; import java.io.*; import java.math.*;
public class Main{
static void solve(){//Here is the main function
int N = nextInt();
Node[] list = new Node[N];
for(int i = 0; i < N; i++){
ArrayList<Integer> tmp = nextIntArray();
int sum = tmp.get(0) + tmp.get(1) + tmp.get(2) + tmp.get(3);
list[i] = new Node(i, sum);
}
Arrays.sort(list);
for(int i = 0; i < N; i++){
if(list[i].no == 0){
myout(i + 1);
return;
}
}
}
//Method addition frame start
static class Node implements Comparable<Node>{
int no;
int sum;
Node(int no, int sum){
this.no = no;
this.sum = sum;
}
public int compareTo(Node ato){
if(this.sum != ato.sum){
return ato.sum - this.sum;
}else{
return this.no - ato.no;
}
}
}
//Method addition frame end
//Don't have to see. start------------------------------------------
static class InputIterator{
ArrayList<String> inputLine = new ArrayList<>(1024);
int index = 0; int max; String read;
InputIterator(){
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try{
while((read = br.readLine()) != null){
inputLine.add(read);
}
}catch(IOException e){}
max = inputLine.size();
}
boolean hasNext(){return (index < max);}
String next(){
if(hasNext()){
return inputLine.get(index++);
}else{
throw new IndexOutOfBoundsException("There is no more input");
}
}
}
static HashMap<Integer, String> CONVSTR = new HashMap<>();
static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
static PrintWriter out = new PrintWriter(System.out);
static void flush(){out.flush();}
static void myout(Object t){out.println(t);}
static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
static String next(){return ii.next();}
static boolean hasNext(){return ii.hasNext();}
static int nextInt(){return Integer.parseInt(next());}
static long nextLong(){return Long.parseLong(next());}
static double nextDouble(){return Double.parseDouble(next());}
static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
static ArrayList<Integer> nextIntArray(){
ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<>(input.size());
for(int i = 0; i < input.size(); i++){
ret.add(Integer.parseInt(input.get(i)));
}
return ret;
}
static ArrayList<Long> nextLongArray(){
ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<>(input.size());
for(int i = 0; i < input.size(); i++){
ret.add(Long.parseLong(input.get(i)));
}
return ret;
}
@SuppressWarnings("unchecked")
static String myconv(Object list, int no){//only join
String joinString = CONVSTR.get(no);
if(list instanceof String[]){
return String.join(joinString, (String[])list);
}else if(list instanceof ArrayList){
return String.join(joinString, (ArrayList)list);
}else{
throw new ClassCastException("Don't join");
}
}
static ArrayList<String> myconv(String str, int no){//only split
String splitString = CONVSTR.get(no);
return new ArrayList<String>(Arrays.asList(str.split(splitString)));
}
public static void main(String[] args){
CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
solve();flush();
}
//Don't have to see. end------------------------------------------
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | b1111548d5550bcac3448b31a9c2af69 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] total = new int[n - 1];
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
int d = input.nextInt();
int totalForThomas = a + b + c + d;
for(int i = 0; i < n - 1; i ++) {
a = input.nextInt();
b = input.nextInt();
c = input.nextInt();
d = input.nextInt();
total[i] = a + b + c + d;
}
total = descendingSort(total);
System.out.println(rank(totalForThomas, total));
}
public static int rank(int scoreForThomas, int[] total) {
for(int i = 0; i < total.length; i ++) {
if(scoreForThomas >= total[i]) {
return i + 1;
}
}
return total.length + 1;
}
public static int[] descendingSort(int[] number) {
for(int i = 0; i < number.length - 1; i ++) {
for(int j = i; j < number.length; j ++) {
if(number[i] < number[j]) {
int temp = number[i];
number[i] = number[j];
number[j] = temp;
}
}
}
return number;
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 63b693d16af70f0c0b222721caa5dc8c | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
int d = input.nextInt();
int totalForThomas = a + b + c + d;
int index = 1;
for(int i = 1; i < n; i ++) {
a = input.nextInt();
b = input.nextInt();
c = input.nextInt();
d = input.nextInt();
int total = a + b + c + d;
if(total > totalForThomas) {
index ++;
}
}
System.out.println(index);
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 02816fbf7864aaf174c913da4a8a290f | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class Scanner {
BufferedReader br;
StringTokenizer st;
Scanner()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
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());
}
long nextLong() throws IOException
{
return Long.parseLong(next());
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner();
int n = sc.nextInt();
Integer sum[] = new Integer[n];
for(int i=0;i<n;i++)
{
sum[i] = sc.nextInt();
sum[i]+=sc.nextInt();
sum[i]+=sc.nextInt();
sum[i]+=sc.nextInt();
}
int val = sum[0];
Arrays.sort(sum,Collections.reverseOrder());
for(int i=0;i<sum.length;i++)
if(sum[i]==val)
{
System.out.println((i+1));
break;
}
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 92a22214f1b5d01db8b1b3de0c6d4fb3 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class The_Rank {
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int no = sc.nextInt();
Integer a[] = new Integer[no];
for(int i=0;i<no;i++)
{
int sum = sc.nextInt()+sc.nextInt()+sc.nextInt()+sc.nextInt();
a[i] = sum;
}
int Smith_rank = a[0];
int rank = 0;
Arrays.sort(a,Collections.reverseOrder());
for(int i=0;i<a.length;i++)
{
if(a[i]==Smith_rank)
{
rank = i+1;
break;
}
}
System.out.println(rank);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 78d08211ac70a245f4fc2b13d7332daa | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
import java.io.*;
//***************** Agar firdaus bar roo-e zameen ast,Hameen ast-o hameen ast-o hameen ast. *****************\\
public class Main{
public static long fast_exp(long base, long exp) {
long MOD = 1000000007;
long res=1;
while(exp>0) {
if(exp%2==1) res=(res*base)%MOD;
base=(base*base)%MOD;
exp/=2;
}
return res%MOD;
}
public static void swap(char c1,char c2){
char temp = c1;
c1=c2;
c2=temp;
}
public static void main(String[] args)throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int n = Integer.parseInt(br.readLine());
String[] str = br.readLine().split(" ");
int thomas=0;
int rank=1;
for(int i=0;i<4;i++) thomas+=Integer.parseInt(str[i]);
for(int i=0;i<n-1;i++){
str = br.readLine().split(" ");
int sum=0;
for(int j=0;j<4;j++) sum+=Integer.parseInt(str[j]);
if(sum>thomas) rank++;
}
pw.println(rank);
pw.flush();
pw.close();
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 83c6245ed0f61b868567b443fd89d453 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
public class Test {
static class Student {
int id, marks;
Student(int id, int marks) {
this.id = id;
this.marks = marks;
}
}
static int searchThomas(Student[] arr) {
for(int i = 0; i < arr.length; i++)
if(arr[i].id == 1)
return i + 1;
return 0;
}
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
int n = read.nextInt();
Student[] arr = new Student[n];
for(int i = 0; i < n; i++) {
int marks = read.nextInt() + read.nextInt() + read.nextInt() + read.nextInt();
arr[i] = new Student(i + 1, marks);
}
Arrays.sort(arr, (Student a, Student b) -> {
if(a.marks == b.marks)
return a.id - b.id;
return b.marks - a.marks;
});
System.out.println(searchThomas(arr));
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 035cef4b1f584a0bc1ee6780f3f73c14 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;
public class Main{
static long mod = 1000000007;
static InputReader in = new InputReader(System.in);
static PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args) throws Exception {
//int t=in.readInt();
//while(t-->0){
int n=in.readInt();
int[] a=new int[n];
for(int i=0;i<n;i++) {
for(int j=0;j<4;j++) {
a[i]+=in.readInt();
}
}
int rank=1;
for(int i=1;i<n;i++) {
if(a[i]>a[0]) {
rank++;
}
}
System.out.println(rank);
//long n=in.readLong();
// String a=in.readString();
//}
}
static String removeChar(String s,int a,int b) {
return s.substring(0,a)+s.substring(b,s.length());
}
static int[] nextIntArray(int n){
int[] arr= new int[n];
int i=0;
while(i<n){
arr[i++]=in.readInt();
}
return arr;
}
static long[] nextLongArray(int n){
long[]arr= new long[n];
int i=0;
while(i<n){
arr[i++]=in.readLong();
}
return arr;
}
static int[] nextIntArray1(int n) {
int[] arr= new int[n+1];
int i=1;
while(i<=n){
arr[i++]=in.readInt();
}
return arr;
}
static long[] nextLongArray1(int n){
long[]arr= new long[n+1];
int i=1;
while(i<=n) {
arr[i++]=in.readLong();
}
return arr;
}
static long gcd(long x, long y) {
if (x % y == 0)
return y;
else
return gcd(y, x % y);
}
static long pow(long n, long m) {
if(m==0)
return 1;
else if(m==1)
return n;
else {
long r=pow(n,m/2);
if(m%2==0)
return r*r;
else
return r*r*n;
}
}
static long max(long a,long b,long c) {
return Math.max(Math.max(a, b),c);
}
static long min(long a,long b,long c) {
return Math.min(Math.min(a, b), c);
}
static class Pair implements Comparable<Pair> {
int a, b;
Pair(int a, int b) {
this.a = a;
this.b = b;
}
public int compareTo(Pair o) {
if (this.a != o.a)
return Integer.compare(this.a, o.a);
else
return Integer.compare(this.b, o.b);
// return 0;
}
public boolean equals(Object o) {
if (o instanceof Pair) {
Pair p = (Pair) o;
return p.a == a && p.b == b;
}
return false;
}
public int hashCode() {
return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public double readDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, readInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, readInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public long readLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 48447a9578c6958958f55793211449ea | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
Integer[] marks = new Integer[n];
for(int k = 0; k < n;k++){
int sum = 0,stud[] = new int[4];
for(int i = 0; i < 4; i++){
stud[i] = scan.nextInt();
sum += stud[i];
}
marks[k] = sum;
}
int temp = marks[0];
Arrays.sort(marks,Collections.reverseOrder());
for(int i = 0; i < n; i++)
if(temp == marks[i]){
System.out.println(i+1);
break;
}
scan.close();
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | d3b6b4fce00b7a75fa565632eb47a3aa | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.Scanner;
public class August {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int rank = 1,a,b,c,d,sum;
a = input.nextInt();
b = input.nextInt();
c = input.nextInt();
d = input.nextInt();
sum = a + b + c + d;
for(int i=1;i<n;i++){
a = input.nextInt();
b = input.nextInt();
c = input.nextInt();
d = input.nextInt();
if(sum<(a+b+c+d))++rank;
}
System.out.println(rank);
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 34e744cf8cce4e7f6ddaa51e36c74c2e | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
public class TheRank {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Integer> arr = new ArrayList<>();
ArrayList<Integer> ids = new ArrayList<>();
for (int i = 0; i < n; i++)
{
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int e = (a+b+c+d);
int index = 0;
while (index < arr.size())
{
if (e > arr.get(index))
break;
else
index++;
}
arr.add(index,e);
ids.add(index,i+1);
}
for (int i = 0; i < n; i++)
{
if (ids.get(i)==1)
System.out.println(i+1);
}
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 7fc1b3ecd508c9b9ed2249159319fc4d | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 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[] arr = new int[4*n];
int[] arr2 = new int[n];
int a=0;
for (int i=0;i<4*n;i++)
arr[i]=sc.nextInt();
for (int i=0;i<4*n;i=i+4) {
arr2[a]=arr[i]+arr[i+1]+arr[i+2]+arr[i+3];
a++;
}
int x=1;
for (int i=1;i<n;i++) {
if (arr2[i]>arr2[0])
x++;
}
System.out.println(x);
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | ecfdbf1154f853c9d9b828c99cc51f29 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] arr = new int[n];
for(int i = 0; i < n; i++){
for(int j = 0; j < 4; j++){
arr[i] += in.nextInt();
}
}
int x = arr[0];
Arrays.sort(arr);
int a = 0;
for(int i = arr.length-1; i >= 0; i--){
if(arr[i] == x){
System.out.println(a+1);
break;
}
a++;
}
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 0acbca82251901c8148c1e7940caefe1 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
public class rank {
public static void main(String[] args) {
int temp,k,rank=0;
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int marks_sum[] = new int[n];
int id[] = new int[n];
for(int i=0;i<n;i++){
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
marks_sum[i] = a+b+c+d;
id[i]= i+1;
}
for(int i=0 ; i<n-1 ;i++)
{
for(int j=0; j<n-i-1; j++){
if(marks_sum[j]<marks_sum[j+1]){
temp=marks_sum[j];
marks_sum[j]=marks_sum[j+1];
marks_sum[j+1]=temp;
k=id[j];
id[j]=id[j+1];
id[j+1]=k;
}
}
}
for(int i=0;i<n;i++){
if(id[i]==1)
rank=i+1;
}
System.out.println(rank);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 9bbf4634084708667684d1a662dd43f4 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
public class TheRank {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int thomasScore = s.nextInt() + s.nextInt() + s.nextInt() + s.nextInt();
int rank = 1;
for (int i = 1; i < n; ++i) {
int score = s.nextInt() + s.nextInt() + s.nextInt() + s.nextInt();
if (score > thomasScore) {
++rank;
}
}
System.out.println(rank);
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | d0dddce7c4ab176c084bd7c7ba48ac8b | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
public class B implements Runnable {
public void run() {
final InputReader sc = new InputReader(System.in);
final PrintWriter out = new PrintWriter(System.out);
int n=sc.nextInt();
int a[]=new int[n];
for(int j=0;j<n;j++)
{
int total=0;
for(int i=0;i<4;i++)
{
int temp=sc.nextInt();
total=total+temp;
}
a[j]=total;
}
int rank=1;
for(int j=1;j<n;j++)
{
if(a[0]>=a[j])
{
}
else
{
rank++;
}
}
System.out.println(rank);
out.close();
}
//========================================================
static class Pair
{
int a,b;
Pair(final int aa,final int bb)
{
a=aa;
b=bb;
}
}
static void sa(final int a[],final InputReader sc)
{
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
}
Arrays.sort(a);
}
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public InputReader(final InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
}
catch (final IOException e) {
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (final IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
final StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(final int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
public static void main(final String args[]) throws Exception {
new Thread(null, new B(),"Main",1<<27).start();
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | ae0e8fc8b9092b7ced3294911ada91be | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes |
import java.util.Scanner;
public class Tomas {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] massiv=new int[n];
for(int i=0;i<n;i++){
int j=sc.nextInt();
int k=sc.nextInt();
int l=sc.nextInt();
int m=sc.nextInt();
massiv[i]=l+k+j+m;
}
int t=0;
for(int r=0;r<massiv.length;r++){
if(massiv[0]<massiv[r]){
t++;
}
}
if(t>0){
System.out.println(n-(n-t)+1);
}
else{
System.out.println("1");
}
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | bfa28ad1e79b128c9a99760a6a92f97b | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int max = 0;
int[] sum = new int[n];
int rank = 1;
for(int i=0; i<n; i++) {
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
int d = input.nextInt();
sum[i] = a + b + c + d;
}
for(int i=1; i<n; i++) {
if(sum[0] < sum[i]) {
rank++;
}
}
System.out.println(rank);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | d71ecbada5edc22bd16a034c75423c0b | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class A {
public static void main(String args[])throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer(br.readLine());
StringBuilder sb=new StringBuilder();
int n=Integer.parseInt(st.nextToken());
int a[][]=new int[n][5];
for(int f=0;f<n;f++){
st=new StringTokenizer(br.readLine());
int sum=0;
for(int i=0;i<4;i++){
a[f][i]=Integer.parseInt(st.nextToken());
sum+=a[f][i];
}
a[f][4]=sum;
}
int req=a[0][4];
int count=1;
for(int i=0;i<n;i++){
if(a[i][4]>req)
count++;
}
sb.append(count+"\n");
System.out.print(sb);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 25c654a2e04f371f49b428a3221c76fd | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.Scanner;
public class codeForces {
public static void main(String[] args){
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int count=1;
int sum1=0;
int sum2=0;
// int x=Integer.parseInt(str[1]);
int a[][]=new int[n][4];
for (int i=0;i<n;i++){
int j=0;
sum2=0;
while (j<4) {
a[i][j]=s.nextInt();
if(i==0){
sum1=sum1+a[0][j];
}
else {
sum2=sum2+a[i][j];
}
j++;
}
if(sum2>sum1){
count++;
}
}
System.out.println(count);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | f0aab51012adeb2f79d47be3b9339573 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Arrays;
import java.math.BigInteger;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner in =new Scanner(System.in);
int l,p,n,h,k,r;
String s="",st="";
int x,y,z;
int t=1,i,m,j;
for(i=0;i<t;i++)
{
n=in.nextInt();
int g[]=new int[n];
int a,b,c,d;
for(j=0;j<n;j++)
{
a=in.nextInt();
b=in.nextInt();
c=in.nextInt();
d=in.nextInt();
g[j]=a+b+c+d;
}
k=g[0];
Arrays.sort(g);
for(j=n-1;j>=0;j--)
{
if(g[j]==k)
break;
}
System.out.println(n-j);
}
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | d2e29676049ea5d53ab1156a3fcf5cd8 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes |
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class A1017_TheRank {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
List<Integer> scores = new ArrayList<>();
while (n-- != 0)
scores.add(scanner.nextInt() + scanner.nextInt() + scanner.nextInt() + scanner.nextInt());
int thomasScore = scores.get(0);
Collections.sort(scores);
Collections.reverse(scores);
System.out.println(scores.indexOf(thomasScore) + 1);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | e4b404dc09dc2add3747ded808df3d11 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class codeforces
{
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int s = 0;
int c = 1;
int max = 0;
for(int i =1; i<=n; i++) {
int a1, b1, a2, b2;
a1=sc.nextInt();
b1=sc.nextInt();
a2=sc.nextInt();
b2=sc.nextInt();
s+=(a1+b1+a2+b2);
if(i==1){
max = s;
}else if(s>max){
c++;
}
s=0;
}
System.out.println(c);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 7a73a542df6c639f721aa73d09a900c1 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = Integer.parseInt(scan.nextLine());
int[] scores = new int[t];
for (int i = 0; i < t; i++) {
for (int j = 0; j < 4; j++) {
scores[i] += scan.nextInt();
}
}
int rank = 1;
for (int i = 0; i < t; i++) {
if (scores[i] > scores[0]) rank++;
}
System.out.println(rank);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 416e0ec3954731a472997d0b96020e96 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
public class Main{
public static void main(String[]args){
Scanner go = new Scanner (System.in);
int t = go.nextInt();
int []arr = new int[t];
int pos = 0;
for (int tc = 0; tc < t; tc++){
int d = go.nextInt(), f= go.nextInt(), g= go.nextInt(), h= go.nextInt();
arr[tc] = d + f + g + h;
if (tc == 0)pos += arr[tc];
}Arrays.sort(arr);
for (int tc = t - 1; tc >= 0;tc--){
if (arr[tc] == pos){
System.out.println(t - tc);
break;
}
}
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 1d216f79c3a3f7f7cb846a3d3ac6786f | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
public class div {
private static Scanner sc = new Scanner(System.in);
private static Map<Character, Integer> m = new HashMap<>();
private static List<Integer> l = new ArrayList<>();
private static int sum = 0;
public static void main(String[] args) {
int n = sc.nextInt();
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++) {
int a1 = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
a[i] = a1 + b + c + d;
}
if (n == 1){
System.out.println(1);
return;
}
int res = a[0];
a[0] = 0;
Arrays.sort(a, Collections.reverseOrder());
for (int i = 0; i < n; i++) {
if (res >= a[i]) {
System.out.println(i + 1);
return;
}
}
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | cf49284b62b1889c77faad96a695755d | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
public class problem1372A25 {
private static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
// int t=sc.nextInt();
// while(t>0) {
int n=sc.nextInt();
int[][] arr=new int[n][4];
Integer[] sumarr=new Integer[n];
int c=1;
int thomsum=0;
for (int i = 0; i <n ; i++) {
int sum=0;
for (int j = 0; j <4 ; j++) {
arr[i][j]=sc.nextInt();
sum+=arr[i][j];
}
sumarr[i]=sum;
if(i==0)
thomsum=sum;
}
Arrays.sort(sumarr,Collections.reverseOrder());
int pos=-1;
for (int i = 0; i <n ; i++) {
if(sumarr[i]==thomsum)
{
pos=i;
break;
}
}
System.out.println(pos+1);
// t--;
// }
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | dfea76a9d96e0c79cbb841df9f95af44 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.io.*;
import java.util.*;
public class TheRank {
public static void main(String[] args) throws Exception {
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int n = Integer.parseInt(buffer.readLine());
String [] inp;
Integer[]arr = new Integer[n];
for (int pos = 0; pos < n; pos++) {
inp = buffer.readLine().split(" ");
arr[pos] = Integer.parseInt(inp[0])+Integer.parseInt(inp[1])+Integer.parseInt(inp[2])+Integer.parseInt(inp[3]);
}
int thomasSore = arr[0];
Arrays.sort(arr);
int pos = Arrays.binarySearch(arr, thomasSore);
while (pos < n && arr[pos]==thomasSore)pos++;
pos--;
sb.append(n-pos);
System.out.println(sb);
}
}
| Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 1c61ed1268aab9a0b0306599ff5673cc | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
public class Rank {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int a = scn.nextInt();
int b = scn.nextInt();
int c = scn.nextInt();
int d = scn.nextInt();
int sum = a + b + c + d;
int count = 1;
for (int i = 2; i <= n; i++) {
int a1 = scn.nextInt();
int b1 = scn.nextInt();
int c1 = scn.nextInt();
int d1 = scn.nextInt();
if (a1 + b1 + c1 + d1 > sum)
count++;
}
System.out.println(count);
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 07fa59dba04e3d72bc3b92641d2ab288 | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
public class Rank {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int[][] arr = new int[10001][5];
for (int i = 1; i <= n; i++) {
for (int j = 1; j < 5; j++) {
arr[i][j] = scn.nextInt();
}
}
int[] sumArr = new int[n + 1];
for (int i = 1; i <= n; i++) {
int sum = 0;
for (int j = 1; j < 5; j++) {
sum += arr[i][j];
}
sumArr[i] = sum;
}
int count = 1;
int min = sumArr[1];
for (int i = 2; i < n + 1; i++) {
if (min < sumArr[i])
count++;
}
System.out.println(count);
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | f1eda7f381d39900695826c34edf015a | train_001.jsonl | 1533737100 | John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son. | 256 megabytes | import java.util.*;
public class Yash
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0; i<n; i++)
{
int a1 = sc.nextInt();
int a2 = sc.nextInt();
int a3 = sc.nextInt();
int a4 = sc.nextInt();
a[i] = a1+a2+a3+a4;
}
int tom = a[0];
int j = 1;
Arrays.sort(a);
for(int i=n-1; i>=0; i--)
{
if(a[i] == tom)
{
break;
}
j++;
}
System.out.println(j);
}
} | Java | ["5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99", "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0"] | 1 second | ["2", "1"] | NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$. | Java 11 | standard input | [
"implementation"
] | 3c984366bba580993d1694d27982a773 | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$)Β β the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$)Β β the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$. | 800 | Print the rank of Thomas Smith. Thomas's id is $$$1$$$. | standard output | |
PASSED | 623406422adc4b44681300ae00217f28 | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class GFG {
static class Pair{
int x;
int y;
Pair(int x,int y){
this.x=x;
this.y=y;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof Pair)) {
return false;
}
Pair c = (Pair) o;
return this.x==c.x&&this.y==c.y;
}
@Override
public int hashCode() {
return x*1000000007+y;
}
}
public static void main (String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine().trim());
while(t--!=0){
int n=Integer.parseInt(br.readLine().trim());
String s=br.readLine().trim();
Map<Pair,Integer> m=new HashMap<>();
int l=-1;
int r=-1;
m.put(new Pair(0,0),-1);
int x=0,y=0;
for(int i=0;i<n;i++){
char c=s.charAt(i);
if(c=='L')
x++;
else if(c=='R')
x--;
else if(c=='U')
y++;
else if(c=='D')
y--;
Pair p=new Pair(x,y);
if(!m.containsKey(p))
m.put(p,i);
else{
int k=m.get(p);
if(l==-1||r-l+1>i-k){
l=k+1;
r=i;
}
m.put(p,i);
}
}
if(l==-1)
System.out.println(l);
else
System.out.println((l+1)+" "+(r+1));
}
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 4a82bd6fd676ba410699e54e747db61a | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | //package codeforces.round617div3;
import java.io.*;
import java.util.*;
public class WalkingRobot {
private static int UNVISITED = 0;
private static int VISITING = -1;
private static int VISITED = 1;
public static void main(String[] args) {
// try {
// FastScanner in = new FastScanner(new FileInputStream("src/input.in"));
// PrintWriter out = new PrintWriter(new FileOutputStream("src/output.out"));
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
solve(t, in, out);
// } catch (IOException e) {
// e.printStackTrace();
// }
}
private static void solve(int q, FastScanner in, PrintWriter out) {
for (int qq = 0; qq < q; qq++) {
int n = in.nextInt();
String s = in.next();
Map<List<Integer>, Integer> map = new HashMap<>();
List<Integer> list = new ArrayList<>();
list.add(0);
list.add(0);
map.put(list, -1);
int ans = Integer.MAX_VALUE;
int left = -1, right = -1;
int x = 0, y = 0;
for(int i = 0; i < n; i++) {
switch (s.charAt(i)) {
case 'L':
x--;
break;
case 'R':
x++;
break;
case 'U':
y++;
break;
case 'D':
y--;
break;
}
List<Integer> ll = new ArrayList<>();
ll.add(x);
ll.add(y);
if(map.containsKey(ll)) {
if(i - map.get(ll) < ans) {
ans = i - map.get(ll);
left = map.get(ll) + 1;
right = i;
}
}
map.put(ll, i);
}
if(ans < Integer.MAX_VALUE) {
out.println((left + 1) + " " + (right + 1));
}
else {
out.println(-1);
}
}
out.close();
}
private static long modularAdd(long a, long b, int mod) {
long sum = a + b;
if (sum >= mod) {
sum -= mod;
}
return sum;
}
private static long modularSubtract(long a, long b, int mod) {
long diff = a - b;
if (diff < 0) {
diff += mod;
}
return diff;
}
private static Stack<Integer> topologicalSort(Set<Integer>[] g) {
Stack<Integer> stack = new Stack<>();
int[] state = new int[g.length];
for (int node = 0; node < g.length; node++) {
if (!topoSortHelper(g, stack, state, node)) {
return null;
}
}
return stack;
}
private static boolean topoSortHelper(Set<Integer>[] g, Stack<Integer> stack, int[] state, int currNode) {
if (state[currNode] == VISITED) {
return true;
} else if (state[currNode] == VISITING) {
return false;
}
state[currNode] = VISITING;
for (int neighbor : g[currNode]) {
if (!topoSortHelper(g, stack, state, neighbor)) {
return false;
}
}
state[currNode] = VISITED;
stack.push(currNode);
return true;
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner(InputStream stream) {
try {
br = new BufferedReader(new InputStreamReader(stream));
} catch (Exception e) {
e.printStackTrace();
}
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 6beb834a88a7ace60456fe912b253877 | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
import java.io.*;
public class Sol
{
static class Loc
{
int x; int y;
Loc()
{
x =0; y = 0;
}
Loc (Loc a)
{
this.x = a.x; this.y = a.y;
}
}
public static void main(String Args[])throws IOException
{
Scanner in = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-->0)
{
int n = Integer.parseInt(br.readLine());
String s = br.readLine();
System.out.println(solve2(s,n));
}
}
static String solve2(String s, int n)
{
HashMap<String , Integer> map = new HashMap<>();
// Loc p= new Loc();
int x =0; int y = 0;
map.put("0:0",0);int starti=0;int endi = 0;
int min = Integer.MAX_VALUE;
for(int i = 1;i<=n;i++)
{
char c = s.charAt(i-1);
if(c=='L')
{
x--;
}
else if(c=='R')
{
x++;
}
else if(c=='U')
{
y++;
}
else
{
y--;
}
if(map.containsKey(x+":"+y))
{
int a = map.get(x+":"+y);
if(min>(i-a))
{
min = i-a;
starti= a+1;
endi = i;
}
}
map.put(x+":"+y,i);
}
if(min!=Integer.MAX_VALUE)
return starti+" "+endi;
return "-1";
}
// static void solve(Loc[][] pos, int n)
// {
// int starti= 0;
// int endi = 0;
// for(int gap = 1;gap<=n;gap++)
// {
// for(int i = 1, j=gap+i; j<=n; i++,j++)
// {
// Loc k1 = pos[1][i-1];
// Loc p = pos[1][j];
// pos[i][j] = diff(p,k1);
// if(pos[i][j].x ==0 && pos[i][j].y==0)
// {
// starti = i;
// endi = j;
// System.out.println(starti+" "+endi);
// return;
// }
// }
// }
// System.out.println(-1);
// }
// static Loc diff(Loc a, Loc b)
// {
// Loc ans = new Loc();
// ans.x = a.x - b.x;
// ans.y = a.y - b.y;
// return ans;
// }
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | b831fb8348e0276540efcf6515a06061 | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes |
import java.io.*;
import java.util.*;
public class C {
static FastReader in = new FastReader();
static PrintWriter out = new PrintWriter(System.out);
static void solve() {
try {
int size = in.nextInt();
String s = in.next();
Map<pair, Integer> map = new HashMap<>();
pair move = new pair(0, 0);
map.put(new pair(move.x, move.y), 0);
int N = (int) 1e9;
int st = N, end = N;
T:
for (int i = 0; i < size; i++) {
switch (s.charAt(i)) {
case 'R':
move.x++;
break;
case 'L':
move.x--;
break;
case 'U':
move.y++;
break;
case 'D':
move.y--;
break;
}
pair p = new pair(move.x, move.y);
// out.println(move.x + " " + move.y);
if (!map.containsKey(p)) {
map.put(p, i + 1);
} else {
int hi = map.get(p);
if (i - hi < end - st || st == N) {
st = hi;
end = i;
}
map.put(p, i + 1);
}
}//for
if (st == N) {
out.println(-1);
} else {
st++;
end++;
out.println(st + " " + end);
}
} catch (Exception e) {
e.printStackTrace();
}
}//solve
static void tc() {
try {
int tc = in.nextInt();
for (int t = 0; t < tc; t++) {
solve();
}
} catch (Exception e) {
e.printStackTrace();
}
}//tc
/*
1
12
ULDRURLDLDUR
*/
public static void main(String[] args) {
tc();
// solve();
out.flush();
}//psvm
static class pair implements Comparable<pair> {
int x, y;
pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(pair o) {
int z = Integer.compare(x, o.x);
if (z == 0) {
return Integer.compare(y, o.y);
}
return z;
}
@Override
public boolean equals(Object obj) {
pair p = (pair) obj;
if (x == p.x && y == p.y) {
return true;
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
}//pair
static class FastReader {
BufferedReader br;
StringTokenizer st;
FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
FastReader(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException x) {
x.printStackTrace();
}
}
String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
String nextLine() throws IOException {
return br.readLine();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
boolean hasNext() throws IOException {
String s = br.readLine();
if (s == null) {
return false;
}
st = new StringTokenizer(s);
return true;
}
}
}//class
| Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 425afecd800ece2110042747efed6724 | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class test {
static int N=1000007;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
String s = sc.next();
HashMap<Long, Integer> hm = new HashMap<>();
long l = 200000, u = 200000, ans = Integer.MAX_VALUE;
int lid = -1, rid = -1;
hm.put(l*N+u, -1);
for (int i = 0; i < n; i++) {
if (s.charAt(i) == 'L')
l--;
else if (s.charAt(i) == 'R')
l++;
else if (s.charAt(i) == 'U')
u++;
else
u--;
long key = l * N + u;
if (hm.containsKey(key)) {
int te = hm.get(key);
if (ans > Math.abs(i - te)) {
lid = te + 1;
rid = i + 1;
ans=i-te;
}
}
hm.put(key, i);
}
lid++;
if(ans==Integer.MAX_VALUE)System.out.println(-1);
else {
System.out.println(lid+" "+rid);
}
}
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 8115b404a1d4e5aa0a69f49b12e1e4a1 | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.awt.*;
import java.io.*;
import java.util.*;
public class Abc {
public static void main(String[] args) throws Exception {
FastReader sc = new FastReader();
int t=sc.nextInt();
while (t-->0){
int n=sc.nextInt();
char s[]=sc.next().toCharArray();
Map<Point,Integer> p=new HashMap<>();
p.put(new Point(0,0),0);
int curl=-1,currr=-1;
int min=Integer.MAX_VALUE;
Point curr=new Point(0,0);
for (int i=1;i<=n;i++){
if (s[i-1]=='L'){
curr.x--;
}else if (s[i-1]=='R'){
curr.x++;
}else if (s[i-1]=='U'){
curr.y++;
}else if (s[i-1]=='D'){
curr.y--;
}
if (p.containsKey(new Point(curr.x,curr.y))){
if (i-p.get(curr)<min){
min=i-p.get(curr);
currr=i-1;
curl=p.get(curr);
}
}
p.put(new Point(curr.x,curr.y),i);
}
if (min==Integer.MAX_VALUE) System.out.println(-1);
else System.out.println((curl+1)+" "+(currr+1));
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | d910510912ac6a76f22d3ec8e155c112 | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.HashMap;
import java.util.Scanner;
public class que3 {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
A: for (int i = 0; i < n; i++) {
int strt = scn.nextInt();
StringBuilder s = new StringBuilder(scn.next());
int[][] arr = new int[s.length()][4];
int[][] diff = new int[s.length()][2];
for (int l = 0; l < s.length(); l++) {
char ch = s.charAt(l);
if (ch == 'L') {
arr[l][0]++;
} else if (ch == 'R') {
arr[l][1]++;
} else if (ch == 'U') {
arr[l][2]++;
} else {
arr[l][3]++;
}
if (l > 0) {
arr[l][0] += arr[l - 1][0];
arr[l][1] += arr[l - 1][1];
arr[l][2] += arr[l - 1][2];
arr[l][3] += arr[l - 1][3];
}
}
int min = Integer.MAX_VALUE;
int st = -1;
int ed = -1;
HashMap<String, Integer> map = new HashMap<>();
map.put(0 + "$" + 0, -1);
for (int l = 0; l < s.length(); l++) {
diff[l][0] = arr[l][0] - arr[l][1];
diff[l][1] = arr[l][2] - arr[l][3];
String str = diff[l][0] + "$" + diff[l][1];
if (map.containsKey(str)) {
if (l - map.get(str) < min) {
st = map.get(str)+1;
ed = l;
min = l - map.get(str);
}
}
map.put(str, l);
}
if (st == -1) {
System.out.println(-1);
} else {
System.out.println((st+1) + " " + (ed+1));
}
}
}
}
| Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 80210b6dd35e3f3602092434eee769f5 | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static String str;
static int t, n;
static Map<Node, Integer> map = new HashMap<>();
static StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static class Node {
int x, y;
public Node(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Node) {
Node t = (Node)obj;
return t.x == this.x && t.y == this.y;
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
}
public static void main(String[] args) throws IOException {
// st = new StreamTokenizer(
// new BufferedReader(new InputStreamReader(new FileInputStream("/Users/huangweixuan/testdata.txt"))));
st.nextToken();
t = (int)st.nval;
int x, y, min = 0x7fffffff, l = 0, r = 0;
char op;
Node p;
while (t-- > 0) {
st.nextToken();
n = (int)st.nval;
st.nextToken();
str = st.sval;
x = 0;
y = 0;
min = 0x7fffffff;
map.clear();
map.put(new Node(x, y), 0);
for (int i = 0; i < n; ++i) {
op = str.charAt(i);
switch (op) {
case 'L':
--y;
break;
case 'R':
++y;
break;
case 'U':
--x;
break;
case 'D':
++x;
break;
default:
}
p = new Node(x, y);
if (map.containsKey(p)) {
if (i + 1 - map.get(p) < min) {
min = i + 1 - map.get(p);
l = map.get(p) + 1;
r = i + 1;
}
}
map.put(p, i + 1);
}
bw.write((min == 0x7fffffff ? "-1" : l + " " + r) + "\n");
}
bw.close();
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | a6245dffc5aa2b4ba66a309b5cea81cb | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static String str;
static int t, n;
static Map<Node, Integer> map = new HashMap<>();
static StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static class Node {
int x, y;
public Node(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Node) {
Node t = (Node)obj;
return t.x == this.x && t.y == this.y;
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
}
public static void main(String[] args) throws IOException {
// st = new StreamTokenizer(
// new BufferedReader(new InputStreamReader(new FileInputStream("/Users/huangweixuan/testdata.txt"))));
st.nextToken();
t = (int)st.nval;
int x, y, min, l = 0, r = 0;
char op;
Node p;
while (t-- > 0) {
st.nextToken();
n = (int)st.nval;
st.nextToken();
str = st.sval;
x = 0;
y = 0;
min = 0x7fffffff;
map.clear();
map.put(new Node(x, y), 0);
for (int i = 0; i < n; ++i) {
op = str.charAt(i);
switch (op) {
case 'L':
--y;
break;
case 'R':
++y;
break;
case 'U':
--x;
break;
case 'D':
++x;
break;
default:
}
p = new Node(x, y);
if (map.containsKey(p)) {
if (i + 1 - map.get(p) < min) {
min = i + 1 - map.get(p);
l = map.get(p) + 1;
r = i + 1;
}
}
map.put(p, i + 1);
}
bw.write((min == 0x7fffffff ? "-1" : l + " " + r) + "\n");
}
bw.close();
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | e3d133927dfb69594c16cb5fef7f45b3 | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Objects;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
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);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
static class TaskC
{
public void solve(int testNumber, Scanner in, PrintWriter out)
{
int t = in.nextInt();
while (t-- > 0)
{
solve(in, out);
}
}
private void solve(Scanner in, PrintWriter out)
{
in.nextInt();
String path = in.next();
int x = 0, y = 0, index = 0;
int minL = 0, minR = Integer.MAX_VALUE;
Map<Position, Integer> map = new HashMap<>();
map.put(new Position(0, 0), index++);
for (char c : path.toCharArray())
{
switch (c)
{
case 'U':
y++;
break;
case 'D':
y--;
break;
case 'L':
x--;
break;
case 'R':
x++;
break;
}
if (map.containsKey(new Position(x, y)))
{
int l = map.get(new Position(x, y));
if ((index - l - 1) < (minR - minL))
{
minL = l;
minR = index - 1;
}
}
map.put(new Position(x, y), index);
index++;
}
if (minR == Integer.MAX_VALUE)
{
out.println(-1);
} else
out.println(++minL + " " + ++minR);
}
}
static class Position
{
int x;
int y;
Position(int x, int y)
{
this.x = x;
this.y = y;
}
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Position position = (Position) o;
return x == position.x &&
y == position.y;
}
public int hashCode()
{
return Objects.hash(x, y);
}
}
}
| Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 228c2128d5ea094809b954599aa9883a | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class Robot {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int NC = scan.nextInt();
//loop test cases
while (NC>0){
int length = scan.nextInt();
String instructions = scan.next();
//System.out.println(instructions);
//set up coordinate map
int[][] coordinate =new int[length+1][3];
coordinate [0][0]=0;
coordinate [0][1] = 0; coordinate [0][2] = 0;
//loop through string, except last element;
for(int i=0; i<length-1;i++ ){
if(instructions.substring(i, i+1).equals("L")){
coordinate[i+1][0]=i+1;
coordinate[i+1][1]=coordinate[i][1]-1;
coordinate[i+1][2]=coordinate[i][2];
}
if(instructions.substring(i, i+1).equals("R")){
coordinate[i+1][0]=i+1;
coordinate[i+1][1]=coordinate[i][1]+1;
coordinate[i+1][2]=coordinate[i][2];
}
if(instructions.substring(i, i+1).equals("U")){
coordinate[i+1][0]=i+1;
coordinate[i+1][1]=coordinate[i][1];
coordinate[i+1][2]=coordinate[i][2]+1;
}
if(instructions.substring(i, i+1).equals("D")){
coordinate[i+1][0]=i+1;
coordinate[i+1][1]=coordinate[i][1];
coordinate[i+1][2]=coordinate[i][2]-1;
}
}
//last element
if(instructions.substring(length-1).equals("L")){
coordinate[length][0]=length;
coordinate[length][1]=coordinate[length-1][1]-1;
coordinate[length][2]=coordinate[length-1][2];
}
if(instructions.substring(length-1).equals("R")){
coordinate[length][0]=length;
coordinate[length][1]=coordinate[length-1][1]+1;
coordinate[length][2]=coordinate[length-1][2];
}
if(instructions.substring(length-1).equals("U")){
coordinate[length][0]=length;
coordinate[length][1]=coordinate[length-1][1];
coordinate[length][2]=coordinate[length-1][2]+1;
}
if(instructions.substring(length-1).equals("D")){
coordinate[length][0]=length;
coordinate[length][1]=coordinate[length-1][1];
coordinate[length][2]=coordinate[length-1][2]-1;
}
//print
//sort coordinate
Arrays.sort(coordinate, (a, b) -> Double.compare(a[1], b[1]));
Arrays.sort(coordinate, (a, b) -> Double.compare(a[2], b[2]));
//Arrays.sort(coordinate, (a, b) -> Double.compare(a[0], b[0]));
//loop through the coordinate
boolean answered = false;
//answer list
ArrayList<Integer> answer = new ArrayList<Integer>();
//length
int size = 0;
for(int i=0; i<length; i++){
if(coordinate[i][1]==coordinate[i+1][1] && coordinate[i][2]==coordinate[i+1][2] ){
//System.out.println(coordinate[i][0]+1+" " + coordinate[i+1][0]);
answered = true;
answer.add(coordinate[i][0]+1); answer.add(coordinate[i+1][0]);
size++;
}
}
if(answered ==false){
System.out.println(-1);
}else{
//build answers array
int[][] answers = new int[size][2];
for(int i=0; i<size; i++){
answers[i][0] = answer.get(2*i); answers[i][1] = answer.get(2*i+1);
}
Arrays.sort(answers, (a, b) -> Double.compare(a[1]-a[0], b[1]-b[0]));
//print output
for(int j=0; j<2; j++){
System.out.print(answers[0][j]+" ");
}
System.out.println();
}
NC--;
}
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | a93b8f8537b9feabc6ec7be8a3113eb5 | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class Solution
{
static class Pair
{
int x,y;
Pair(int x,int y)
{
this.x=x;
this.y=y;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + x * 7 + (y * 3+5*(y-x) );
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Pair other = (Pair) obj;
if (x != other.x && y != other.y) {
return false;
}
return true;
}
}
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
int t=in.nextInt();
while(t-->0)
{
int n=in.nextInt();
String S=in.next();
HashMap<Pair,Integer> a=new HashMap<Pair, Integer>();
int x=0,y=0,min=Integer.MAX_VALUE,l=0,r=0;
a.put(new Pair(0,0), 0);
for(int i=1;i<=n;i++)
{
if(S.charAt(i-1)=='L')
x-=1;
else if(S.charAt(i-1)=='R')
x+=1;
else if(S.charAt(i-1)=='U')
y+=1;
else
y-=1;
Pair p=new Pair(x,y);
if(a.containsKey(p))
{
int b=a.get(p)+1;
int c=i;
if(c-b<min)
{
min=c-b;
l=b;
r=c;
}
a.remove(p);
}
if(min==2)
break;
a.put(p,i);
}
if(min==Integer.MAX_VALUE)
System.out.println(-1);
else
System.out.println(l+" "+r);
}
}
}
| Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 47f68336130c8dcc149ec3d7e78e54e8 | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class C {
private static FastReader fr;
private static OutputStream out;
private static int mod = (int)(1e9+7);
private void solve() {
int t = fr.nextInt();
while(t-- > 0) {
int n = fr.nextInt();
char arr[] = fr.next().toCharArray();
int l = 0, r = 0, len = Integer.MAX_VALUE;
HashMap<String, Integer> map = new HashMap<>();
String str = 0 + " " + 0;
map.put(str, 0);
int x = 0, y = 0;
for(int i=0;i<n;i++) {
if(arr[i] == 'L') {
x--;
}else if(arr[i] == 'R') {
x++;
}else if(arr[i] == 'U') {
y++;
}else {
y--;
}
str = x + " " + y;
if(map.containsKey(str)) {
int idx = map.get(str);
if(len > i - idx + 1) {
len = i - idx + 1;
l = idx + 1;
r = i + 1;
}
}
map.put(str, i+1);
}
if(len == Integer.MAX_VALUE) {
println(-1);
}else {
println(l + " " + r);
}
}
}
public static void main(String args[]) throws IOException{
new C().run();
}
private ArrayList<Integer> factors(int n, boolean include){
ArrayList<Integer> factors = new ArrayList<>();
if(n < 0)
return factors;
if(include) {
factors.add(1);
if(n > 1)
factors.add(n);
}
int i = 2;
for(;i*i<n;i++) {
if(n % i == 0) {
factors.add(i);
factors.add(n / i);
}
}
if(i * i == n) {
factors.add(i);
}
return factors;
}
private ArrayList<Integer> PrimeFactors(int n) {
ArrayList<Integer> primes = new ArrayList<>();
int i = 2;
while (i * i <= n) {
if (n % i == 0) {
primes.add(i);
while (n % i == 0) {
n /= i;
}
}
i++;
}
if (n > 1) {
primes.add(n);
}
return primes;
}
private boolean isPrime(int n) {
if(n == 0 || n == 1) {
return false;
}
if(n % 2 == 0) {
return false;
}
for(int i=3;i*i<=n;i+=2) {
if(n % i == 0) {
return false;
}
}
return true;
}
private ArrayList<Integer> Sieve(int n){
boolean bool[] = new boolean[n+1];
Arrays.fill(bool, true);
bool[0] = bool[1] = false;
for(int i=2;i*i<=n;i++) {
if(bool[i]) {
int j = 2;
while(i*j <= n) {
bool[i*j] = false;
j++;
}
}
}
ArrayList<Integer> primes = new ArrayList<>();
for(int i=2;i<=n;i++) {
if(bool[i])
primes.add(i);
}
return primes;
}
private HashMap<Integer, Integer> addToHashMap(HashMap<Integer, Integer> map, int arr[]){
for(int val: arr) {
if(!map.containsKey(val)) {
map.put(val, 1);
}else {
map.put(val, map.get(val) + 1);
}
}
return map;
}
private int factorial(int n) {
long fac = 1;
for(int i=2;i<=n;i++) {
fac *= i;
fac %= mod;
}
return (int)(fac % mod);
}
private static int pow(int base,int exp){
if(exp == 0){
return 1;
}else if(exp == 1){
return base;
}
int a = pow(base,exp/2);
a = ((a % mod) * (a % mod)) % mod;
if(exp % 2 == 1) {
a = ((a % mod) * (base % mod));
}
return a;
}
private static int gcd(int a,int b){
if(a == 0){
return b;
}
return gcd(b%a,a);
}
private static int lcm(int a,int b){
return (a * b)/gcd(a,b);
}
private void run() throws IOException{
fr = new FastReader();
out = new BufferedOutputStream(System.out);
solve();
out.flush();
out.close();
}
private static class FastReader{
private static BufferedReader br;
private static StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
out = new BufferedOutputStream(System.out);
}
public String next() {
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
public String nextLine() {
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public char[] nextCharArray() {
return next().toCharArray();
}
public int[] nextIntArray(int n) {
int arr[] = new int[n];
for(int i=0;i<n;i++) {
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
long arr[] = new long[n];
for(int i=0;i<n;i++) {
arr[i] = nextLong();
}
return arr;
}
public String[] nextStringArray(int n) {
String arr[] = new String[n];
for(int i=0;i<n;i++) {
arr[i] = next();
}
return arr;
}
}
public static void print(Object str) {
try {
out.write(str.toString().getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
public static void println(Object str) {
try {
out.write((str.toString() + "\n").getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
public static void println() {
println("");
}
public static void printArray(Object str[]){
for(Object s : str) {
try {
out.write(str.toString().getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | bf387a5cd903353ddc4546bfe6334267 | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | //package com.pb.codeforces.practice;
import java.util.HashMap;
import java.util.Scanner;
public class CF1296C {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while(t-- > 0) {
int n = in.nextInt();
char[] path = in.next().toCharArray();
int x,y,min,fx,fy;
min = Integer.MAX_VALUE;
x = y = fx = fy = 0;
HashMap<String,Integer> cmap = new HashMap<String,Integer>();
HashMap<Character,int[]> dmap = new HashMap<Character,int[]>();
dmap.put('U', new int[] {-1,0});
dmap.put('D', new int[] {1,0});
dmap.put('L', new int[] {0,-1});
dmap.put('R', new int[] {0,1});
cmap.put(x+"-"+y, 0);
for(int i=0; i<path.length; i++) {
char ch = path[i];
int[] m = dmap.get(ch);
x += m[0]; y += m[1];
if(cmap.containsKey(x+"-"+y)) {
int pIdx = cmap.get(x+"-"+y);
int dist = (i+1) - pIdx;
if(dist < min) {
min = dist;
fx = pIdx+1; fy = i+1;
}
}
cmap.put(x+"-"+y, i+1);
}
if(min == Integer.MAX_VALUE)
System.out.println(-1);
else
System.out.println(fx+" "+fy);
}
}
}
| Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | dcc396acd0132e23afdc1c5b1398f4c3 | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import static java.lang.System.in;
public class CodeForces617C {
public static void main(String[] args) {
Scanner sc = new Scanner(in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
String s = sc.next();
Map<Long, int[]> map = new HashMap<>();
int x0 = n;
int y0 = n;
map.put((long) x0 * n + y0, new int[]{1, 1});
int[] ans = new int[2];
int minDistance = Integer.MAX_VALUE;
for (int j = 0; j < n; j++) {
char ch = s.charAt(j);
if (ch == 'L') x0 -= 1;
if (ch == 'R') x0 += 1;
if (ch == 'U') y0 -= 1;
if (ch == 'D') y0 += 1;
long key = (long) x0 * n + y0;
int[] val = map.get(key);
if (val != null && val[1] > 0) {
int id = val[0];
int distance = j + 2 - id;
if (distance < minDistance) {
minDistance = distance;
ans[0] = id;
ans[1] = j + 1;
}
val[1] = 0;
if (minDistance == 2) break;
}
map.put(key, new int[]{j + 2, 1});
}
System.out.println(ans[0] > 0 ? ans[0] + " " + ans[1] : "-1");
}
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 8f1093deb97bc10523b02caa51b81c9a | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class C {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(in.readLine());
for(int t = 0; t < T; t++){
int n = Integer.parseInt(in.readLine());
char[] str = in.readLine().toCharArray();
HashMap<Point,Integer> map = new HashMap<>();
int l = -1;
int r = 0;
Point curr = new Point(0,0);
map.put(curr, 0);
for(int i = 1; i <= n; i++){
Point tmp = new Point(curr.x, curr.y);
if(str[i-1] == 'U'){
tmp.y++;
}else if(str[i-1] == 'D'){
tmp.y--;
}else if(str[i-1] == 'R'){
tmp.x++;
}else{
tmp.x--;
}
if(map.containsKey(tmp)){
if(l == -1 || i-map.get(tmp) < r-l){
l = map.get(tmp);
r = i;
}
}
map.put(tmp,i);
curr = tmp;
}
System.out.println((l!=-1) ? String.format("%d %d", l+1,r): "-1");
}
}
public static class Point {
int x;
int y;
Point(int x, int y){
this.x = x;
this.y = y;
}
@Override
public int hashCode(){
return (x*31 + y);
}
@Override
public boolean equals(Object o){
if(o instanceof Point){
Point p = (Point) o;
return p.x == this.x && p.y == this.y;
}
return false;
}
}
}
| Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 6c678c7e4baefee3ab42bd6ea0cae72d | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.util.Map;
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 t=in.nextInt();
while(t!=0)
{
t--;
int n=in.nextInt();
String s=in.next();
int x=0;
int y=0;
HashMap<String, Integer> map= new HashMap<String, Integer>();
map.put("0,0",0);
int min=2147483647;
int flag=-1;
int x1=0,x2=0;
for(int i=0;i<n;i++)
{
if(s.charAt(i)=='L')
x--;
else if(s.charAt(i)=='R')
x++;
else if(s.charAt(i)=='U')
y++;
else
y--;
String str=Integer.toString(x)+","+Integer.toString(y);
if(map.containsKey(str)==true)
{
flag=0;
int diff=(i+1)-map.get(str);
if(diff==2)
{
x1=i;
x2=i+1;
break;
}
if(diff<min)
{
x1=map.get(str)+1;
x2=i+1;
min=diff;
}
map.put(str,i+1);
}
else
map.put(str,i+1);
}
if(flag==0)
{
System.out.println(x1+" "+x2);
}
else
System.out.println(-1);
}
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | b0ff12b93d1e512d15711a31b661bd73 | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class YetAnotherWalkingRobotHashMap {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while(t-->0) {
int n = in.nextInt();in.nextLine();
char c[] = in.nextLine().toCharArray();
HashMap<Long,Integer> map = new HashMap<>();
long x,y;x=y=200000L;
map.put(x*1000000L+y, 0);
int ansx,ansy;ansx=ansy=-1;
int minLen = Integer.MAX_VALUE;
for(int i=0;i<n;i++) {
if(c[i]=='L') x--;
else if(c[i]=='R') x++;
else if(c[i]=='U') y++;
else y--;
if(map.containsKey(x*1000000L+y)&&(i+1)-map.get(x*1000000L+y)<minLen) {
ansx = map.get(x*1000000L+y);
ansy = i+1;
minLen = ansy - ansx;
}
map.put(x*1000000L+y,i+1);
}
if(ansx==-1) out.println(ansx);
else out.println((ansx+1)+" "+ansy);
}out.close();in.close();
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | a8841daf82a98c44a511b47bdad32f3b | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.HashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int t=s.nextInt();;
for(int i=0;i<t;i++)
{
int n=s.nextInt();
String str=s.next();
if(n==1)
System.out.println(-1);
else
{
HashMap<String,Integer> map=new HashMap<>();
map.put("0 0",0);
int min=Integer.MAX_VALUE;
int start=-1;
int end=-1;
int x=0;
int y=0;
for(int j=0;j<n;j++)
{
if(str.charAt(j)=='L')
{
x--;
}
else if(str.charAt(j)=='R')
{
x++;
}
else if(str.charAt(j)=='U')
{
y++;
}
else
{
y--;
}
String curr=x+" "+y;
if(map.containsKey(curr))
{
if(j+1-map.get(curr)<min)
{
min=j+1-map.get(curr);
start=map.get(curr)+1;
end=j+1;
map.put(curr,j+1);
}
else
{
map.put(curr,j+1);
}
}
else
{
map.put(curr,j+1);
}
}
if(start==-1&&end==-1)
System.out.println(-1);
else
System.out.println(start+" "+end);
}
}
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | a1a283fe3e39d086296628ab24374fbf | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | /*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
Sometime i think i am goona die and I want to hang myself cause i am not that good in cp ! :(
*/
import java.util.*;
import java.lang.Math;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
public class Main {
static int oo = (int)1e9;
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
MuskA solver = new MuskA();
solver.solve(1, in, out);
out.close();
}
static class MuskA {
static int inf = (int) 1e9 + 7;
public void solve(int testNumber, Scanner in, PrintWriter out) {
int T = in.nextInt();
while(T-->0){
int n = in.nextInt();
String S=in.next();
int lb=0,ub=0,r=-1,l=-1;
Map<String, Integer> m =new HashMap<>();
int ans=Integer.MAX_VALUE;
m.put("0 0",-1);
for(int i=0;i<S.length();i++){
if(S.charAt(i)=='L'){
lb++;
}else if(S.charAt(i)=='R'){
lb--;
}else if(S.charAt(i)=='U'){
ub++;
}else{
ub--;
}
String Check= lb+" "+ub;
if(m.containsKey(Check)){
if(ans>i-m.get(Check)){
l=m.get(Check)+2;
r=i+1;
ans=i-m.get(Check);
}
}
m.put(Check,i);
}
if(l==-1){
out.println(-1);
}else{
out.println(l+" "+r);
}
}
}
}
public int factorial(int n) {
int fact = 1;
int i = 1;
while(i <= n) {
fact *= i;
i++;
}
return fact;
}
public static long gcd(long x,long y)
{
if(x%y==0)
return y;
else
return gcd(y,x%y);
}
public static int gcd(int x,int y)
{
if(x%y==0)
return y;
else
return gcd(y,x%y);
}
public static int abs(int a,int b)
{
return (int)Math.abs(a-b);
}
public static long abs(long a,long b)
{
return (long)Math.abs(a-b);
}
public static int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
public static int min(int a,int b)
{
if(a>b)
return b;
else
return a;
}
public static long max(long a,long b)
{
if(a>b)
return a;
else
return b;
}
public static long min(long a,long b)
{
if(a>b)
return b;
else
return a;
}
public static long pow(long n,long p,long m)
{
long result = 1;
if(p==0)
return 1;
if (p==1)
return n;
while(p!=0)
{
if(p%2==1)
result *= n;
if(result>=m)
result%=m;
p >>=1;
n*=n;
if(n>=m)
n%=m;
}
return result;
}
public static long pow(long n,long p)
{
long result = 1;
if(p==0)
return 1;
if (p==1)
return n;
while(p!=0)
{
if(p%2==1)
result *= n;
p >>=1;
n*=n;
}
return result;
}
static long sort(int a[]){
int n=a.length;
int b[]=new int[n];
return mergeSort(a,b,0,n-1);
}
static long mergeSort(int a[],int b[],long left,long right){
long c=0;
if(left<right){
long mid=left+(right-left)/2;
c= mergeSort(a,b,left,mid);
c+=mergeSort(a,b,mid+1,right);
c+=merge(a,b,left,mid+1,right);
}
return c;
}
static long merge(int a[],int b[],long left,long mid,long right){
long c=0;int i=(int)left;int j=(int)mid; int k=(int)left;
while(i<=(int)mid-1&&j<=(int)right){
if(a[i]<=a[j]){
b[k++]=a[i++];
}
else{
b[k++]=a[j++];c+=mid-i;
}
}
while (i <= (int)mid - 1)
b[k++] = a[i++];
while (j <= (int)right)
b[k++] = a[j++];
for (i=(int)left; i <= (int)right; i++)
a[i] = b[i];
return c;
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 711d95467a431b8e21bbc0c39f1cff0a | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class Main
{
public static void main(String[] args) throws IOException
{
StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
while (in.nextToken() != StreamTokenizer.TT_EOF)
{
int num = (int)in.nval;
for(int i = 0; i < num; i++)
{
in.nextToken();
int numLength = (int)in.nval;
in.nextToken();
String s1 = in.sval;
Map<Point, Integer> maps = new HashMap<Point, Integer>();
Point point = new Point(0, 0);
maps.put(new Point(point), -1);
int left = 0;
int right = 0;
int length = 999999;
for(int j = 0; j < numLength; j++)
{
if(s1.charAt(j) == 'L')
{
point.x--;
}
else if(s1.charAt(j) == 'R')
{
point.x++;
}
else if(s1.charAt(j) == 'U')
{
point.y++;
}
else if(s1.charAt(j) == 'D')
{
point.y--;
}
//System.out.println(point.x + " " + point.y + " haveFind = " + maps.containsKey(point));
if(maps.containsKey(point) && j - maps.get(point) < length)
{
left = maps.get(point) + 1;
right = j;
length = right - left + 1;
//System.out.println("left = " + left + " right = " + right + " length = " + length);
}
maps.put(new Point(point), j);
}
// for(Map.Entry<Point, Integer> entry : maps.entrySet())
// {
// System.out.println(entry.getKey() + " " + entry.getValue());
// }
if(length == 999999)
{
out.println("-1");
out.flush();
}
else
{
out.println((left + 1) + " " + (right + 1));
out.flush();
}
//System.out.println();
}
}
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | ad4bf644f9a3f15c8e2bdfaa6ca7fa4f | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class Main
{
public static void main(String[] args) throws IOException
{
StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
while (in.nextToken() != StreamTokenizer.TT_EOF)
{
int num = (int)in.nval;
for(int i = 0; i < num; i++)
{
in.nextToken();
int numLength = (int)in.nval;
in.nextToken();
String s1 = in.sval;
Map<Point, Integer> maps = new HashMap<Point, Integer>();
Point point = new Point(0, 0);
maps.put(new Point(point), -1);
int left = 0;
int right = 0;
int length = 999999;
for(int j = 0; j < numLength; j++)
{
if(s1.charAt(j) == 'L')
{
point.x--;
}
else if(s1.charAt(j) == 'R')
{
point.x++;
}
else if(s1.charAt(j) == 'U')
{
point.y++;
}
else if(s1.charAt(j) == 'D')
{
point.y--;
}
//System.out.println(point.x + " " + point.y + " haveFind = " + maps.containsKey(point));
if(maps.containsKey(point) && j - maps.get(point) < length)
{
left = maps.get(point) + 1;
right = j;
length = right - left + 1;
//System.out.println("left = " + left + " right = " + right + " length = " + length);
}
maps.put(new Point(point), j);
}
if(length == 999999)
{
out.println("-1");
out.flush();
}
else
{
out.println((left + 1) + " " + (right + 1));
out.flush();
}
//System.out.println();
}
}
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 6e5e643572dcf0d07af59e1cfa823ac3 | train_001.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class RobotPath implements Runnable
{
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int read()
{
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = stream.read(buf);
}
catch (IOException e)
{
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
public int nextInt()
{
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.')
{
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
// if modulo is required set value accordingly
public static long[][] matrixMultiply2dL(long t[][],long m[][])
{
long res[][]= new long[t.length][m[0].length];
for(int i=0;i<t.length;i++)
{
for(int j=0;j<m[0].length;j++)
{
res[i][j]=0;
for(int k=0;k<t[0].length;k++)
{
res[i][j]+=t[i][k]+m[k][j];
}
}
}
return res;
}
static long combination(long n,long r)
{
long ans=1;
for(long i=0;i<r;i++)
{
ans=(ans*(n-i))/(i+1);
}
return ans;
}
public static void main(String args[]) throws Exception
{
new Thread(null, new RobotPath(),"RobotPath",1<<27).start();
}
// **just change the name of class from Main to reuquired**
public void run()
{
InputReader sc = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int tc=sc.nextInt();
while(tc-->0)
{
int n=sc.nextInt();
char ch[]=sc.next().toCharArray();
int x=0,y=0;
int diff=300000;
int l=-1,r=-1;
HashMap<Point,Integer> hm = new HashMap<Point,Integer>();
hm.put(new Point(0,0),0);
for(int i=0;i<n;++i)
{
if(ch[i]=='L') x--;
else if(ch[i]=='U') y++;
else if(ch[i]=='R') x++;
else if(ch[i]=='D') y--;
Point p= new Point(x,y);
if(hm.containsKey(p))
{
int temp=(int)hm.get(p);
if(diff>i+1-temp+1)
{
l=temp;
r=i+1;
hm.put(p,r);
diff=r-l+1;
}
hm.put(p,i+1);
}
else
{
hm.put(p,i+1);
}
/*for(Map.Entry m : hm.entrySet())
{
Point pt= (Point)m.getKey();
System.out.println(pt.x+","+pt.y+"-->"+m.getValue());
}
System.out.println(l+" "+r+" "+diff);
System.out.println("------------------------");*/
}
if(l==-1 || r==-1) w.println("-1");
else w.println((l+1)+" "+(r));
}
System.out.flush();
w.close();
}
}
class Point
{
int x;
int y;
Point(int r, int c)
{
x=r;
y=c;
}
Point(Point p)
{
x=p.x;
y=p.y;
}
public int hashCode()
{
return x*31+y;
}
public boolean equals(Object other)
{
if(this==other) return true;
if(other instanceof Point)
{
Point pt = (Point)other;
return pt.x==this.x && pt.y==this.y;
}
else return false;
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 8 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | ba5bbf68e6abac4be5020cd490c82494 | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes | import java.util.*;
import java.math.*;
public class shortest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int caminho[] = new int[150];
caminho[0]=0;
for(int i=1; i<=n; i++){
caminho[i]=in.nextInt();
}
int a = in.nextInt();
int b = in.nextInt();
int soma1 = 0;
int soma2 = 0;
for(int i=a; i!=b; i++){
soma1+=caminho[i];
if(i==n)i=0;
}
a-=1;
for(int i=a; i!=b-1; i--){
soma2+=caminho[i];
if(i==0)i=n+1;
}
if(soma1<=soma2) System.out.println(soma1);
else System.out.println(soma2);
}
}
| Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | 1d26e846cd314dceb53eb5b3a79f20e2 | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes |
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Test {
public static void main(String[] argv) {
FastScanner scan = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = scan.nextInt();
int d[] = new int[n + 1];
int sum = 0;
for (int i = 0; i < n; ++i) {
d[i] = scan.nextInt();
sum += d[i];
}
int s = scan.nextInt() - 1;
int t = scan.nextInt() - 1;
int k = 0;
for (int i = s; i % n != t; ++i) {
k += d[i % n];
}
out.println(Math.min(k, sum - k));
out.close();
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner(InputStream is) {
try {
br = new BufferedReader(new InputStreamReader(is));
} catch (Exception e) {
e.printStackTrace();
}
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
return null;
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.valueOf(next());
}
}
} | Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | 6f99b80633cb3e429dc2aac945c1ef41 | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
for(int i=0; i<n;i++) a[i] = sc.nextInt();
int s = sc.nextInt()-1;
int e = sc.nextInt()-1;
int t1 = 0;
int t2 = 0;
int x = Math.min(s,e);
int y = Math.max(s, e);
for(int i=x; i<y; i++){
t1 += a[i];
}
for(int i=0; i<n; i++){
if(i < x || i > y-1)
t2 += a[i];
}
System.out.print(Math.min(t1,t2));
}
} | Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | b67f25064624051997f77f91d8503e09 | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes | import java.util.*;
public class CircleLine {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
while(in.hasNext()){
int t=in.nextInt();
int []m=new int[t];
int x[]=new int[t];
int y[]=new int[t];
for (int i = 0; i < t-1; i++) {
m[i]=in.nextInt();
x[i]=i+1;
y[i]=i+2;
}
m[m.length-1]=in.nextInt();
x[m.length-1]=t;
y[m.length-1]=1;
int s=in.nextInt();
int k=in.nextInt();
if(s==k){
System.out.println(0);
}else{
int dis1=0;
int dis2=0;
for (int i = (Math.min(s, k)-1); i <(Math.max(s, k)-1); i++) {
dis1+=m[i];
}
for (int i = (Math.max(s, k)-1); i < y.length; i++) {
dis2+=m[i];
}
for (int i = 0; i < (Math.min(s, k)-1); i++) {
dis2+=m[i];
}
System.out.println(Math.min(dis1, dis2));
}
}
}
}
| Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | 14f04791c96fecb08a5e66f9e7af4380 | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes | import java.util.Scanner;
public class Stations {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] d = new int[n + 1];
for (int i = 1; i < d.length; i++)
d[i] = sc.nextInt();
int ymen = 0, temp=0, shmal = 0, s = sc.nextInt(), t = sc.nextInt();
if(s>t){
temp=s;
s=t;
t=temp;
}
if (s == t) {
;
} else {
for (int i = s; i < t; i++)
ymen += d[i];
for (int i = t; i < d.length; i++)
shmal += d[i];
for (int i = 1; i < s; i++) {
shmal += d[i];
}
}
if (ymen < shmal)
System.out.println(ymen);
else
System.out.println(shmal);
}
}
| Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | 909261713b962d7c0be0871e936780a7 | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes | import java.util.Scanner;
public class CircleLine{
public static int a[];
public static void main(String []args){
Scanner s1 = new Scanner(System.in);
int n = s1.nextInt();
a = new int[n];
int i = 0;
while(i < n)
a[i++] = s1.nextInt();
i = s1.nextInt();
int j =s1.nextInt();
int s = Math.min(i, j) - 1;
int t = Math.max(i,j) - 1;
if(s != t)
System.out.println(Math.min(sum(s,t), sum(0, n) - sum(s, t)));
else
System.out.println("0");
}
private static int sum(int s, int t)
{
int sum = 0;
for(int i = s; i < t;i++)
sum+= a[i];
return sum;
}
} | Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | 08f89b831fa9f0c22bd11346e36d2b34 | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes | import java.util.*;
public class a278
{
public static void main(String ar[])
{
Scanner ob=new Scanner(System.in);
int n=ob.nextInt();
int sum=0,sum1=0;
int arr[]=new int[n];
for(int i=0;i<n;i++)
arr[i]=ob.nextInt();
int x=ob.nextInt();
int y=ob.nextInt();
int s=Math.min(x,y);
int t=Math.max(x,y);
for(int i=s-1;i<t-1;i++)
sum+=arr[i];
for(int i=0;i<s-1;i++)
sum1+=arr[i];
for(int i=n-1;i>=t-1;i--)
sum1+=arr[i];
System.out.println(Math.min(sum,sum1));
}
}
| Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | 876f4c50de91e53488ac5db831e4c45b | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes | import java.util.*;
public class Circle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] line = new int[n];
for (int i = 0; i < n; i++) {
line[i] = input.nextInt();
}
int s = input.nextInt()-1;
int t = input.nextInt()-1;
int rightCounter = 0;
int leftCounter = 0;
// To the right
int i = s;
while (i != t) {
rightCounter += line[i];
i = (i + 1) % n;
}
// To the left (simulated by going from t to s to the right)
while (i != s) {
leftCounter += line[i];
i = (i+1) % n;
}
System.out.println(Math.min(leftCounter, rightCounter));
}
}
| Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | 827ce69ea577142bb618149fbc114128 | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes | import java.util.*;
import java.math.*;
public class mayn {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
int n = scan.nextInt();
int [] dis = new int [n];
int total = 0;
for (int i=0 ; i<n ; i++) {
dis[i] = scan.nextInt();
total += dis[i];
}
int begin = scan.nextInt() - 1;
int end = scan.nextInt() - 1;
int op = 0;
if (begin < end) {
for (int i=begin ; i<end ; i++) {
op += dis[i];
}
} else {
for (int i=0 ; i<end ; i++) {
op += dis[i];
}
for (int i=begin ; i<n ; i++) {
op += dis[i];
}
}
if (op < (total - op)) {
System.out.println(op);
} else {
System.out.println((total-op));
}
}
} | Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | 9f49fdf805b891d6a56c5f41ed68b0e3 | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes | /*
* @Author: steve
* @Date: 2015-10-08 18:27:08
* @Last Modified by: steve
* @Last Modified time: 2015-10-08 19:34:38
*/
import java.io.*;
public class dcircle {
public static void main(String[] args) throws Exception {
BufferedReader en= new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(en.readLine());
String[] stat= en.readLine().split(" ");
String[] d=en.readLine().split(" ");
int n1=Integer.parseInt(d[0]);
int n2=Integer.parseInt(d[1]);
int a=0;
int cosa=0;
for (int i=Math.min(n1,n2)-1; i<n+Math.min(n1,n2)-1;i++){
a=a+Integer.parseInt(stat[i%n]);
if (i==Math.max(n1,n2)-1){
cosa=a-Integer.parseInt(stat[i%n]);
a=Integer.parseInt(stat[i%n]);
}
}
int m=Math.min(cosa,a);
System.out.println(m);
}
} | Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | e4dc4ac7a02657f28d0faa4155b49fbf | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author user
*/
public class CF278A {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int ar[] = new int[t];
int c = -1;
int sum = 0;
while(st.hasMoreTokens()){
ar[++c] = Integer.parseInt(st.nextToken());
sum += ar[c];
}
st = new StringTokenizer(br.readLine());
int start = Integer.parseInt(st.nextToken());
int end = Integer.parseInt(st.nextToken());
if(start > end){
int temp = start;
start = end;
end = temp;
}
int temp = 0;
for(int a = start-1; a <= end-2; a++){
temp+=ar[a];
}
if(temp<sum-temp) System.out.println(temp);
else System.out.println(sum-temp);
}
}
| Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | ec8dc88c3c3c64198721a22236a4a46d | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author user
*/
public class CFround170div2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
String s = br.readLine();
StringTokenizer st = new StringTokenizer(br.readLine());
int start = Integer.parseInt(st.nextToken());
int end = Integer.parseInt(st.nextToken());
if(end<start){
int temp = start;
start = end;
end = temp;
}
st = new StringTokenizer(s);
int sum = 0 , temp = 0, c = 0;
while(st.hasMoreTokens()){
c++;
int n = Integer.parseInt(st.nextToken());
sum+= n;
if(c>=start && c<end) temp+= n;
}
if(sum-temp < temp) System.out.println(sum-temp);
else System.out.println(temp);
}
}
| Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | 268fa87380708966600e82cc30d1d5bb | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes |
import java.util.ArrayList;
import java.util.Scanner;
public class ACM {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int numberOfStations = 0;
numberOfStations = input.nextInt();
ArrayList<Integer> list = new ArrayList<>();
Integer intger = new Integer(0);
for (int i = 0; i < numberOfStations; i++) {
intger = input.nextInt();
list.add(intger);
}
int station1 = 0, station2 = 0;
station1 = input.nextInt();
station2 = input.nextInt();
input.close();
long shortDistance1 = 0;
long shortDistance2 = 0;
if (station1 > station2) {
for (int i = station2; i < station1; i++) {
shortDistance1 += list.get(i - 1);
}
for (int i= station1; i<=list.size();i++){
shortDistance2+=list.get(i-1);
}
for(int i=1; i<station2; i++){
shortDistance2+=list.get(i-1);
}
} else {
for (int i = station1; i < station2; i++) {
shortDistance1 += list.get(i - 1);
}
for (int i= station2; i<=list.size();i++){
shortDistance2+=list.get(i-1);
}
for(int i=1; i<station1; i++){
shortDistance2+=list.get(i-1);
}
}
System.out.println(Math.min(shortDistance1, shortDistance2));
}
}
| Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | c283d4321dcf101301b57637fdf59532 | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes | import java.util.Scanner;
public class CircleLine {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int x = input.nextInt();
int c[] = new int[x];
for (int i = 0; i < c.length; i++) {
c[i] = input.nextInt();
}
int s = input.nextInt();
int t = input.nextInt();
if (s == t) {
System.out.println(0);
return;
}
int v = Math.min(s, t);
int vv = Math.max(s, t);
int b = 0;
for (int i = v - 1; i <= vv -2; i++) {
b += c[i];
}
int bb = 0;
for (int i = 0; i <= v-2; i++) {
// if (i < v-2 || i > vv-2) {
bb += c[i];
// }
}
for (int i = vv-1; i < c.length; i++) {
bb+=c[i];
}
System.out.println(Math.min(bb, b));
}
}
| Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | 3f2dca0451786ba0a87305399d8f3c35 | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes | import java.io.*;
import java.util.*;
public class z6 {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
int n=in.nextInt();
int[] a=new int[n+1];
int sum=0;
for (int i=1;i<=n;i++)
{
a[i]=in.nextInt();
sum+=a[i];
}
int k=in.nextInt();
int l=in.nextInt();
if (k>l) {int c=k;k=l;l=c;}
int sum1=0;
for (int i=k;i<l;i++) sum1+=a[i];
out.println(Math.min(sum1,sum-sum1));
out.flush();
}
} | Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | c7091db93326afc43c872dafc418bf65 | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes | import java.io.*;
import java.util.*;
public class z6 {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
int n = in.nextInt();
int[] a = new int[n + 1];
int sum = 0;
for (int i = 1; i <= n; i++) {
a[i] = in.nextInt();
sum += a[i];
}
int k = in.nextInt();
int l = in.nextInt();
if (k > l) {
int c = k;
k = l;
l = c;
}
int sum1 = 0;
for (int i = k; i < l; i++)
sum1 += a[i];
out.println(Math.min(sum1, sum - sum1));
out.flush();
in.close();
out.close();
}
} | Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | 37b9a16b712115673aac7d46b95095fd | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes |
import java.io.*;
import java.util.*;
import java.*;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Random;
import java.lang.*;
public class zad {
private static BufferedReader in;
private static StringTokenizer tok;
private static PrintWriter out;
final static boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") !=null;
public static void init() throws FileNotFoundException{
if(ONLINE_JUDGE){
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
else{
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("out.txt");
}
}
private static String readString() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
private static int readInt() throws IOException {
return Integer.parseInt(readString());
}
private static double readDouble() throws IOException {
return Double.parseDouble(readString());
}
private static long readLong() throws IOException {
return Long.parseLong(readString());
}
private static float readFloat() throws IOException{
return Float.parseFloat(readString());
}
public static class time{
int ch;
int min;
time(int ch,int min){
this.ch = ch;
this.min = min;
}
public int getCh(){
return ch;
}
public int getMin(){
return min;
}
public boolean eq(time t1, time t2){
if(t1.getCh()== t2.getCh() && t1.getMin() == t2.getMin())
return true;
return false;
}
}
public static void Solve() throws IOException{
int n =readInt();
int[] mas = new int[n];
for(int i=0;i<n;i++){
mas[i] = readInt();
}
int start = readInt();
int finish = readInt();
long ans=0;
long k=0;
if(start == finish) out.print(0);
else{
if(start<finish){
for(int i=start-1;i<finish-1;i++){
ans+=mas[i];
mas[i]=0;
}
for(int i=0;i<n;i++){
k+=mas[i];
}
}
else{
for(int i=finish-1;i<start-1;i++){
ans+=mas[i];
mas[i]=0;
}
for(int i=0;i<n;i++){
k+=mas[i];
}
}
out.print(ans<=k ? ans : k);
}
}
public static void main(String[] args) throws IOException {
init();
Solve();
in.close();
out.close();
}
} | Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | b72c8a29dfb3aab976f3413635f372f4 | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
/**
* @param args
*/
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
int stations = Integer.parseInt(br.readLine());
int[] dists = new int[stations];
int count = 0;
String[] s = br.readLine().split(" ");
for (int x = 0; x < dists.length; x++) {
dists[count++] = Integer.parseInt(s[x]);
}
String[] p = br.readLine().split(" ");
int start = Integer.parseInt(p[0]), end = Integer.parseInt(p[1]);
long p1=0,p2=0;
int i = start-1;
while (i != end-1) {
p1 += dists[i];
i++;
if (i==dists.length) i = 0;
}
i = start-1;
while (i != end-1) {
i--;
if (i == -1) i = dists.length-1;
p2 += dists[i];
}
System.out.print(Math.min(p1, p2));
}
}
| Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output | |
PASSED | 025378f2b8c8f52dec8a40eaab36d71c | train_001.jsonl | 1362065400 | The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dnβ-β1 is the distance between the nβ-β1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t. | 256 megabytes |
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class SystemsOfEquations {
static class Reader
{
BufferedReader r;
StringTokenizer str;
Reader()
{
r=new BufferedReader(new InputStreamReader(System.in));
}
Reader(String fileName) throws FileNotFoundException
{
r=new BufferedReader(new FileReader(fileName));
}
public String getNextToken() throws IOException
{
if(str==null||!str.hasMoreTokens())
{
str=new StringTokenizer(r.readLine());
}
return str.nextToken();
}
public int nextInt() throws IOException
{
return Integer.parseInt(getNextToken());
}
public long nextLong() throws IOException
{
return Long.parseLong(getNextToken());
}
public double nextDouble() throws IOException
{
return Double.parseDouble(getNextToken());
}
public String nextString() throws IOException
{
return getNextToken();
}
public int[] intArray(int n) throws IOException
{
int a[]=new int[n];
for(int i=0;i<n;i++)
a[i]=nextInt();
return a;
}
public long[] longArray(int n) throws IOException
{
long a[]=new long[n];
for(int i=0;i<n;i++)
a[i]=nextLong();
return a;
}
public String[] stringArray(int n) throws IOException
{
String a[]=new String[n];
for(int i=0;i<n;i++)
a[i]=nextString();
return a;
}
public long gcd(long a, long b) {
if(b == 0){
return a;
}
return gcd(b, a%b);
}
}
public static void main(String args[]) throws IOException{
Reader r=new Reader();
PrintWriter pr=new PrintWriter(System.out,false);
//278A
int num=r.nextInt();
int arr[]=new int[num];
int first=0,last=0;
long temp1=0,temp2=0;
for(int i=0;i<num;i++)
{
arr[i]=r.nextInt();
}
first=r.nextInt();
last=r.nextInt();
if(first>last)
{
first=first+last;
last=first-last;
first=first-last;
}
for(int i=first-1;i<last-1;i++)
{
temp1+=arr[i];
//pr.print(temp1+" ");
}
//pr.println();
for(int j=last-1;;j++)
{
if(j==num) j=0;
if(j==(first-1)) break;
temp2+=arr[j];
//pr.print(temp2+" ");
}
if (temp1<=temp2 ) pr.print(temp1);
else pr.print(temp2);
pr.flush();
pr.close();
}
}
| Java | ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1"] | 2 seconds | ["5", "15", "1", "0"] | NoteIn the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | Java 7 | standard input | [
"implementation"
] | 22ef37041ebbd8266f62ab932f188b31 | The first line contains integer n (3ββ€βnββ€β100) β the number of stations on the circle line. The second line contains n integers d1,βd2,β...,βdn (1ββ€βdiββ€β100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1ββ€βs,βtββ€βn) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. | 800 | Print a single number β the length of the shortest path between stations number s and t. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.