Output Clear
Console Clear

Special functions

cache

Object to store data between iterations; it will be reset after each complete run. Use it as any other JS object to store data in its properties.

print(arg1[, arg2, arg3, ...])

Print on output for the current case; will separate each arguments with a single space character; if an argument is an array, its elements are also printed separatedly.

If return is used in the program, the returned value (if any) will be printed.

println(arg1[, arg2, arg3, ...])

Works like print, but appends a new line character at the end of the printing sequence.

log(arg1[, arg2, arg3, ...])

Logs a message to the console; objects passed to this function are converted to JSON.

readLine()

Reads the next line as a string.

readInt()
Reads the next line, returning its integer value.

readInts()

Reads the next line, and interprets it as a list of integers, returning an array with them.

readFloats()

Reads the next line, and interprets it as a list of floats, returning an array with them.

readStrings()

Reads the next line assuming is a list of space-separated strings, and returns them as an array.

smartRead([firstIsCount])

Reads the next line and tries to guess what it is made of; the parameter indicates if the first number is the number of subgroups (if it's not present it will be autodetected), and detects strings, numbers and floats.

Array functions

array.shift()

Removes the first element of an array, and returns that element.

array.pop()

Removes the last element of an array, and returns that element.

array.unshift(arg1[, arg2, arg3, ...])

Adds the specified elements (in order) to the top of array.

array.push(arg1[, arg2, arg3, ...])

Adds the specified elements (in order) to the bottom of array.

array.splice(index, howmanytoremove[, arg1, arg2, arg3, ...])

The splice() method adds and/or removes elements to/from an array, and returns the removed element(s).

array.sort([compareFunction])

Sorts the elements of an array in place. compareFunction takes 2 parameters, and compares them; if the result is <0, a is before b; if is 0, keeps the order between a and b, and >0 puts a after b.

array.join([separator])

Joins all the elements of an array into a string, placing separator between them (or "," if unespecified).

String functions

string.toLowerCase(), string.toUpperCase()

Converts an string to all lowercase or all uppercase respectively.

string.indexOf(arg[, start]), string.lastIndexOf(arg[, start])

Find the next instance of arg in a string starting from position start, from the start or from the end respectively. Returns -1 if not found.

string.substr(start[, length])

Extracts a substring from a string, starting from start; if length is not specified, it will extract to the end.

string.substring(start[, end])

Extracts a substring from a string between two specified indices; if only one is specified, it will extract to the end.

string.split(separator[, limit])

Splits the strings into substrings; if limit is used, it will stop splitting when the number is reached. Use empty string as the separator to return an array with the individual characters.

string.charAt(index)

Returns the character at certain position of a string.

string.charCodeAt(index)

Returns the Unicode value of a character at certain position of a string.