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
|
3bdbefb45e4a304d8144af75b6f17742
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.io.*;
import java.util.StringTokenizer;
/**
* 297A
* ΞΈ(|a| + |b|) time
* ΞΈ(|a| + |b|) space
*
* @author artyom
*/
public class _297A implements Runnable {
private BufferedReader in;
private StringTokenizer tok;
private Object solve() throws IOException {
String a = nextToken(), b = nextToken();
int x = 0;
for (int i = 0, n = a.length(); i < n; i++) {
x += a.charAt(i) - 48;
}
if ((x & 1) == 1) {
x++;
}
int y = 0;
for (int i = 0, n = b.length(); i < n; i++) {
y += b.charAt(i) - 48;
}
return y <= x ? "YES" : "NO";
}
//--------------------------------------------------------------
public static void main(String[] args) {
new _297A().run();
}
@Override
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
tok = null;
System.out.print(solve());
in.close();
} catch (IOException e) {
System.exit(0);
}
}
private String nextToken() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
private int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 8
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
7e3d7d14f667c4673790f59f77907517
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.util.Scanner;
public class ParityGame1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
char[] a = input.next().toCharArray();
char[] b = input.next().toCharArray();
int count=0;
for(int i=0; i<a.length;i++){
if(a[i]=='1')count++;
}
if(count%2==1)count++;
for(int i=0; i<b.length;i++){
if(b[i]=='1')count--;
}
if(count>=0){
System.out.println("YES");
}
else
System.out.println("NO");
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 8
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
2b139312eb08d70f79030cd537b70265
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
//package codeforces;
import java.util.Scanner;
/**
* Created by nitin.s on 09/10/16.
*/
public class ParityGame {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String a = in.nextLine();
String b = in.nextLine();
int onesA = 0, onesB = 0;
for(int i = 0; i < a.length(); ++i) {
if(a.charAt(i) == '1') ++onesA;
}
for(int i = 0; i < b.length(); ++i) {
if(b.charAt(i) == '1') ++onesB;
}
if(onesA % 2 == 1) ++onesA;
if(onesA < onesB) {
System.out.println("NO");
} else {
System.out.println("YES");
}
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 8
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
643f8141c09e833e401426119b39f85c
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.util.*;
public class Parity {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String a = in.next();
String b = in.next();
int a1 = a.length() - a.replace("1", "").length();
if (a1 % 2 != 0)
a1++;
int b1 = b.length() - b.replace("1", "").length();
System.out.println(a1 >= b1 ? "YES" : "NO");
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 8
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
e3bdc247c49df5024de24505a605c61e
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.lang.*;
public class templ {
public static int a[]=new int[1000000];
int binarySearch(int arr[], int l, int r, int x)
{
if (r >= l)
{
int mid = l + (r - l)/2;
if (arr[mid] == x)
return mid;
if (arr[mid] > x)
return binarySearch(arr, l, mid-1, x);
return binarySearch(arr, mid+1, r, x);
}
return -1;
}
int partition(int arr[],int a[], int low, int high)
{
int pivot = arr[high];
int i = (low-1);
for (int j=low; j<high; j++)
{
if (arr[j] <= pivot)
{
i++;
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
int temp = arr[i+1];
arr[i+1] = arr[high];
arr[high] = temp;
temp = a[i+1];
a[i+1] = a[high];
a[high] = temp;
return i+1;
}
void sort(int arr[],int a[], int low, int high)
{
if (low < high)
{
int pi = partition(arr,a, low, high);
sort(arr,a, low, pi-1);
sort(arr,a, pi+1, high);
}
}
String inttobin(int n)
{
String s="";
while(n!=0)
{
int d=n%2;
s=d+s;
n=n/2;
}
return s;
}
int bintoint(String S)
{
int p=0;
for(int i=0;i<S.length();i++)
{
char c=S.charAt(i);
if(c=='1')
p+=Math.pow(2,i);
}
return p;
}
public static void main(String[] args) throws FileNotFoundException {
try
{
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
templ ob=new templ();
String s=in.nextLine();
String s1=in.nextLine();
int l=s.length();
int l1=s1.length();
int k=0;
for(int i=0;i<l;i++)
{
char c=s.charAt(i);
if(c=='1')
k++;
}
int k1=0;
for(int i=0;i<l1;i++)
{
char c=s1.charAt(i);
if(c=='1')
k1++;
}
int p;
if(k%2==0)
p=0;
else
p=1;
if(p+k>=k1)
out.println("YES");
else
out.println("NO");
out.close();
}
catch(Exception e){
return;
}
}
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
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 {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
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 String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 8
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
f521ded2be88f09c17039855eb583891
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Parser in = new Parser(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, Parser in, PrintWriter out) {
String a = in.next();
String b = in.next();
int cnt = 0;
for (int i = 0; i < a.length(); i++) {
if (a.charAt(i) == '1') cnt++;
}
if (cnt % 2 != 0) cnt++;
int cntb = 0;
for (int i = 0; i < b.length(); i++) {
if (b.charAt(i) == '1') cntb++;
}
if (cnt >= cntb) out.println("YES");
else out.println("NO");
}
}
class Parser
{
private BufferedReader din;
private StringTokenizer tokenizer;
public Parser(InputStream in)
{
din = new BufferedReader(new InputStreamReader(in));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(din.readLine());
} catch (Exception e) {
throw new UnknownError();
}
}
return tokenizer.nextToken();
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 8
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
e90f55fcc84a3a786e3e7e29b3696af5
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.util.*;
import java.io.*;
import java.math.*;
public class A{
class Node implements Comparable<Node>{
int id;
long st;
public Node(int id,long st){
this.id=id;
}
public int compareTo(Node c){
return Long.compare(this.st,c.st);
}
}
void solve(){
char s1[]=ns().toCharArray();
char s2[]=ns().toCharArray();
int c1=0,c2=0;
for(int i=0;i<s1.length;i++) if(s1[i]=='1') c1++;
for(int i=0;i<s2.length;i++){
if(s2[i]=='1') c2++;
}
if(c1%2!=0) c1++;
if(c1>=c2)pw.println("YES"); else pw.println("NO");
}
InputStream is;
PrintWriter pw;
String INPUT = "";
void run() throws Exception {
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
pw = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
pw.flush();
if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new A().run(); }
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte() {
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m) {
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n) {
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni() {
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl() {
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 8
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
11caf61e8e5877c17a1c49fbd8ed7001
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String a=br.readLine();
String b=br.readLine();
int aones=0;
int bones=0;
for(int i=0;i<a.length();i++){
if(a.charAt(i)=='1')
aones++;
}
for(int i=0;i<b.length();i++){
if(b.charAt(i)=='1')
bones++;
}
if((aones&1)==1)
aones++;
if(aones>=bones)
System.out.println("YES");
else
System.out.println("NO");
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
4b20a4de81937515e877555c82140df5
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.text.*;
public class cf297A_parityGame {
static BufferedReader br;
static Scanner sc;
static PrintWriter out;
public static void initA() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
//br = new BufferedReader(new FileReader("input.txt"));
sc = new Scanner(System.in);
//out = new PrintWriter("output.txt");
out = new PrintWriter(System.out);
} catch (Exception e) {
}
}
static boolean next_permutation(Integer[] p) {
for (int a = p.length - 2; a >= 0; --a) {
if (p[a] < p[a + 1]) {
for (int b = p.length - 1;; --b) {
if (p[b] > p[a]) {
int t = p[a];
p[a] = p[b];
p[b] = t;
for (++a, b = p.length - 1; a < b; ++a, --b) {
t = p[a];
p[a] = p[b];
p[b] = t;
}
return true;
}
}
}
}
return false;
}
public static void initB() {
try {
br = new BufferedReader(new FileReader("input.txt"));
sc = new Scanner(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
} catch (Exception e) {
}
}
public static String getString() {
try {
return br.readLine();
} catch (Exception e) {
}
return "";
}
public static Integer getInt() {
try {
return Integer.parseInt(br.readLine());
} catch (Exception e) {
}
return 0;
}
public static Integer[] getIntArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
Integer temp2[] = new Integer[n];
for (int i = 0; i < n; i++) {
temp2[i] = Integer.parseInt(temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static Long[] getLongArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
Long temp2[] = new Long[n];
for (int i = 0; i < n; i++) {
temp2[i] = Long.parseLong(temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static String[] getStringArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
String temp2[] = new String[n];
for (int i = 0; i < n; i++) {
temp2[i] = (temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static int getMax(Integer[] ar) {
int t = ar[0];
for (int i = 0; i < ar.length; i++) {
if (ar[i] > t) {
t = ar[i];
}
}
return t;
}
public static void print(Object a) {
System.out.println(a);
}
public static void print(String s, Object... a) {
System.out.printf(s, a);
}
public static int nextInt() {
return sc.nextInt();
}
public static double nextDouble() {
return sc.nextDouble();
}
public static void main(String[] ar) {
initA();
solve();
out.flush();
}
public static void solve2() {
}
public static void solve() {
char a[] = getString().toCharArray();
char b[] = getString().toCharArray();
int ct =0 ,ct2=0;
for(int i=0;i<a.length;i++){
if(a[i]=='1')ct++;
}
for(int i=0;i<b.length;i++){
if(b[i]=='1')ct2++;
}
if(ct2==0){
print("YES");
return;
}
if((ct2 - ct ==1 && ct %2 ==1) || ct >= ct2){
print("YES");
}else{
print("NO");
}
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
43fa147552384ccb0b2a4dd2db4ff382
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.util.*;
public class cf297a {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = 0, b = 0;
for(char c : in.next().trim().toCharArray())
if(c == '1')
a++;
for(char c : in.next().trim().toCharArray())
if(c == '1')
b++;
if(a + (a%2) >= b)
System.out.println("YES");
else
System.out.println("NO");
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
513831ac8fc5b4368a7bc1e338e2947f
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.math.*;
public class A implements Runnable {
public void run() {
long startTime = System.nanoTime();
char[] p = nextToken().toCharArray();
char[] q = nextToken().toCharArray();
println(count(p) + count(p) % 2 >= count(q) ? "YES" : "NO");
if (fileIOMode) {
System.out.println((System.nanoTime() - startTime) / 1e9);
}
out.close();
}
private static int count(char[] p) {
int s = 0;
for (char c : p) {
s += c - '0';
}
return s;
}
//-----------------------------------------------------------------------------------
private static boolean fileIOMode;
private static String problemName = "a";
private static BufferedReader in;
private static PrintWriter out;
private static StringTokenizer tokenizer;
public static void main(String[] args) throws Exception {
fileIOMode = args.length > 0 && args[0].equals("!");
if (fileIOMode) {
in = new BufferedReader(new FileReader(problemName + ".in"));
out = new PrintWriter(problemName + ".out");
} else {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
tokenizer = new StringTokenizer("");
new Thread(new A()).start();
}
private static String nextLine() {
try {
return in.readLine();
} catch (IOException e) {
return null;
}
}
private static String nextToken() {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(nextLine());
}
return tokenizer.nextToken();
}
private static int nextInt() {
return Integer.parseInt(nextToken());
}
private static long nextLong() {
return Long.parseLong(nextToken());
}
private static double nextDouble() {
return Double.parseDouble(nextToken());
}
private static BigInteger nextBigInteger() {
return new BigInteger(nextToken());
}
private static void print(Object o) {
if (fileIOMode) {
System.out.print(o);
}
out.print(o);
}
private static void println(Object o) {
if (fileIOMode) {
System.out.println(o);
}
out.println(o);
}
private static void printf(String s, Object... o) {
if (fileIOMode) {
System.out.printf(s, o);
}
out.printf(s, o);
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
60b5fff68a581f94e296d626718a1b91
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
/*
br = new BufferedReader(new FileReader("input.txt"));
pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
*/
public class Main {
private static BufferedReader br;
private static StringTokenizer st;
private static PrintWriter pw;
static final long MOD = 1000000007;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
//int qq = 1;
int qq = Integer.MAX_VALUE;
//int qq = readInt();
for(int casenum = 1; casenum <= qq; casenum++) {
String a = nextToken();
String b = nextToken();
a += count(a)%2;
if(count(a) >= count(b)) {
pw.println("YES");
}
else {
pw.println("NO");
}
}
pw.close();
}
public static int count(String str) {
int ret = 0;
for(int i = 0; i < str.length(); i++) {
if(str.charAt(i) == '1') {
ret++;
}
}
return ret;
}
private static void exitImmediately() {
pw.close();
System.exit(0);
}
private static long readLong() throws IOException {
return Long.parseLong(nextToken());
}
private static double readDouble() throws IOException {
return Double.parseDouble(nextToken());
}
private static int readInt() throws IOException {
return Integer.parseInt(nextToken());
}
private static String nextToken() throws IOException {
while(st == null || !st.hasMoreTokens()) {
if(!br.ready()) {
exitImmediately();
}
st = new StringTokenizer(br.readLine().trim());
}
return st.nextToken();
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
0217590d377de41628ecd78bae1b2f95
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Contest180C {
public static void main(String[] args)throws IOException {
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
String a = rd.readLine();
String b = rd.readLine();
int one = 0;
for (int i = 0; i < a.length(); i++) {
if(a.charAt(i) == '1') one ++;
}
if(one % 2 == 1) one ++;
int two = 0;
for (int i = 0; i < b.length(); i++) {
if(b.charAt(i) == '1') two ++;
}
if(one >= two) System.out.println("YES");
else System.out.println("NO");
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
2c4385c69a1d3c4c91f9394fcd2626ae
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
/**
* Created with IntelliJ IDEA.
* User: yuantian
* Date: 4/19/13
* Time: 12:01 PM
* Copyright (c) 2013 All Right Reserved, http://github.com/tyuan73
*/
import java.util.*;
public class ParityGame {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String a = in.next();
String b = in.next();
int c1 = 0, c2 = 0;
for (int i = 0; i < a.length(); i++)
if (a.charAt(i) == '1')
c1++;
for (int i = 0; i < b.length(); i++)
if (b.charAt(i) == '1')
c2++;
c1 += c1 & 1;
if (c1 >= c2)
System.out.println("YES");
else
System.out.println("NO");
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
756306ab11b91b15fa202974d5a3df56
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Main {
// static Scanner in;
static PrintWriter out;
// static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}
static BufferedReader in;
public static void main(String[] args) throws Exception {
// in = new Scanner(System.in);
out = new PrintWriter(System.out);
// in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
in = new BufferedReader(new InputStreamReader(System.in));
char[] c = in.readLine().toCharArray();
char[] d = in.readLine().toCharArray();
int x = 0;
for (char cc : c) if (cc == '1') x++;
int y = 0;
for (char cc : d) if (cc == '1') y++;
if ((x & 1) == 1) x++;
if (x >= y) out.println("YES");
else out.println("NO");
out.close();
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
1856d9413e3b3a7baca1bcc87067182b
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class parity {
static String a, b;
static int count[];
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader in = new BufferedReader(new FileReader("parity.in"));
count = new int[2];
a = in.readLine();
b = in.readLine();
for (int i = 0; i < a.length(); i++) count[0] += Integer.parseInt(a.substring(i, i+1));
for (int i = 0; i < b.length(); i++) count[1] += Integer.parseInt(b.substring(i, i+1));
count[0] += (count[0]%2);
if (count[0] >= count[1]) System.out.println("YES");
else System.out.println("NO");
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
7e888af294e4e4fcfa5a452e65884b13
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class a {
public static void main(String[] args) throws IOException
{
input.init(System.in);
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
String s1 = input.next(), s2 = input.next();
int a = 0, b = 0;
for(int i = 0; i<s1.length(); i++) if(s1.charAt(i)=='1') a++;
for(int i = 0; i<s2.length(); i++) if(s2.charAt(i)=='1') b++;
boolean possible = true;
if(b-a>1 || b>a && b%2 == 1) possible = false;
out.println(possible?"YES":"NO");
out.close();
}
static class input {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
static String nextLine() throws IOException {
return reader.readLine();
}
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
96769fe13c4ac8ce4818c65e89368075
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class A {
static class Scanner{
BufferedReader br=null;
StringTokenizer tk=null;
public Scanner(){
br=new BufferedReader(new InputStreamReader(System.in));
}
public String next() throws IOException{
while(tk==null || !tk.hasMoreTokens())
tk=new StringTokenizer(br.readLine());
return tk.nextToken();
}
public int nextInt() throws NumberFormatException, IOException{
return Integer.valueOf(next());
}
public double nextDouble() throws NumberFormatException, IOException{
return Double.valueOf(next());
}
public long nextLong() throws NumberFormatException, IOException{
return Long.valueOf(next());
}
}
public static void main(String args[]) throws NumberFormatException, IOException{
Scanner sc = new Scanner();
char[] a1 = sc.next().toCharArray();
char[] a2 = sc.next().toCharArray();
int uno = 0;
for(int i = 0; i < a1.length; i++)
if (a1[i] == '1')
uno++;
int dos = 0;
for(int i = 0; i < a2.length; i++)
if (a2[i] == '1')
dos++;
if (uno % 2 == 1)
uno++;
if (uno >= dos)
System.out.println("YES");
else
System.out.println("NO");
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
b649b9b24e73478a30d515995b7650db
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.util.Scanner;
public class Prob297A {
public static void main(String[] Args) {
Scanner scan = new Scanner(System.in);
String s1 = scan.next();
char[] c1 = s1.toCharArray();
int ones1 = numOnes(c1);
String s2 = scan.next();
char[] c2 = s2.toCharArray();
int ones2 = numOnes(c2);
if ((((ones1 + 1) / 2) * 2) < ones2)
System.out.println("NO");
else
System.out.println("YES");
}
public static int numOnes(char[] c) {
int count = 0;
for (int i = 0; i < c.length; i++)
if (c[i] == '1')
count++;
return count;
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
886c09ebf13b1e799762549515fee3f2
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author coderbd
*/
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);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, InputReader in, OutputWriter out) {
char[] a = in.readLine().toCharArray();
char[] b = in.readLine().toCharArray();
int aones = 1;
for (char c : a)
if (c == '1')
aones++;
aones ^= 1;
int bones = 0;
for (char c : b)
if (c == '1')
bones++;
out.printLine(aones >= bones ? "YES" : "NO");
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
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++];
}
private String readLine0() {
StringBuffer buf = new StringBuffer();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r')
buf.appendCodePoint(c);
c = read();
}
return buf.toString();
}
public String readLine() {
String s = readLine0();
while (s.trim().length() == 0)
s = readLine0();
return s;
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
9e9ced3af34214b570f33d1f5a12455a
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.next();
String b = sc.next();
int na = 0;
int nb = 0;
for (int i = 0; i < a.length(); i++) {
if (a.charAt(i) == '1') {
na++;
}
}
if (na % 2 == 1) {
na++;
}
for (int j = 0; j < b.length(); j++) {
if (b.charAt(j) == '1') {
nb++;
}
}
System.out.println(na >= nb ? "YES" : "NO");
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
e9a73360d88717ca309fb8e9846a241b
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class A {
MyScanner in;
PrintWriter out;
public static void main(String[] args) throws Exception {
new A().run();
}
public void run() throws Exception {
in = new MyScanner();
out = new PrintWriter(System.out);
solve();
out.close();
}
char[] a, b;
int ones(char[] s) {
int ans = 0;
for (int i = 0; i < s.length; i++) {
if (s[i] == '1') {
ans++;
}
}
return ans;
}
public void solve() throws Exception {
a = in.next().toCharArray();
b = in.next().toCharArray();
int a1 = ones(a);
int b1 = ones(b);
out.println(((a1 + (a1 & 1)) >= b1) ? "YES" : "NO");
}
class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() throws Exception {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() throws Exception {
while ((st == null) || (!st.hasMoreTokens())) {
String t = br.readLine();
if (t == null) {
return null;
}
st = new StringTokenizer(t);
}
return st.nextToken();
}
int nextInt() throws Exception {
return Integer.parseInt(next());
}
double nextDouble() throws Exception {
return Double.parseDouble(next());
}
boolean nextBoolean() throws Exception {
return Boolean.parseBoolean(next());
}
long nextLong() throws Exception {
return Long.parseLong(next());
}
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
8ad30343091856eec4f9c0a2123c92d9
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.math.*;
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
String s1 = cin.next();
String s2 = cin.next();
int z1 = 0, z2 = 0;
for (int i = 0; i < s1.length(); i++)
if (s1.charAt(i) == '1') z1++;
if (z1 % 2 == 1) z1++;
for (int i = 0; i < s2.length(); i++)
if (s2.charAt(i) == '1') z2++;
//System.out.printf("%d %d\n", z1, z2);
if (z1 >= z2) System.out.println("YES");
else System.out.println("NO");
}
}
/*cjefffrqmesfheriterleekkebcpcodeptcnrtjjptgcedkpht*/
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
1d952e488258f9a56be34f52f837a014
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
public class ProblemA {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
String a = in.readLine();
String b = in.readLine();
int al = 0;
for (int i = 0 ; i < a.length() ; i++) {
al += a.charAt(i) - '0';
}
int bl = 0;
for (int i = 0 ; i < b.length() ; i++) {
bl += b.charAt(i) - '0';
}
if (al % 2 == 1) {
al++;
}
out.println((al >= bl) ? "YES" : "NO");
out.flush();
}
public static void debug(Object... o) {
System.err.println(Arrays.deepToString(o));
}
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
2595f70deda6d48d0fdb8d0fad279f31
|
train_001.jsonl
|
1366385400
|
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
|
256 megabytes
|
//package round180;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class A {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
char[] a = ns(1001);
int oa = 0;
for(char c : a){
if(c == '1'){
oa++;
}
}
char[] b = ns(1001);
int ob = 0;
for(char c : b){
if(c == '1'){
ob++;
}
}
oa += oa & 1;
if(oa >= ob){
out.println("YES");
}else{
out.println("NO");
}
}
void run() throws Exception
{
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new A().run(); }
private byte[] inbuf = new byte[1024];
private int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
|
Java
|
["01011\n0110", "0011\n1110"]
|
1 second
|
["YES", "NO"]
|
NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110
|
Java 6
|
standard input
|
[
"constructive algorithms"
] |
cf86add6c92fa8a72b8e23efbdb38613
|
The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
| 1,700 |
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
|
standard output
| |
PASSED
|
2d01be3de6bca72beb388c79961282a9
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[]=new int[n];
int b[]=new int[n];
for(int i=0;i<a.length;i++)
{ a[i]=sc.nextInt();
b[i]=sc.nextInt();}
for(int i=0;i<a.length;i++)
{
for(int j=0;j<b.length;j++)
{
if(a[i]==b[j] && i!=j)
{ n--;
break;
}
}
}
System.out.println(n);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
39f2f21ddc9c3d8332a83ab1a441351b
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.Scanner;
public class SerejaAndBottles {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
int n = input.nextInt();
int [] a = new int [n];
int [] b = new int [n];
for (int i = 0 ; i < n ; i++) {
a[i] = input.nextInt();
b[i] = input.nextInt();
}
int ans = n;
//System.out.println(ans);
for (int i = 0 ; i < n ; i++)
{
boolean bb = false;
for (int j = 0 ; j < n ; j++)
{
if(a[i] == b[j] && i != j)
{
bb = true;
break;
}
}
//System.out.println(a[i] + " " + bb);
if(!bb)
ans--;
}
System.out.println(n - ans);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
f49a379180efaed546192551b6545d22
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
//package Competitive;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException{
String[] arr= {"a"};
code3 obj=new code3();
obj.main(arr);
}
}
class code3{
static int ans;
public static void main(String[] args) throws IOException{
//Reader sc=new Reader();
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
HashSet<Integer> set1=new HashSet<>();
HashMap<Integer,Integer> map=new HashMap<>();
ArrayList<Integer> ar=new ArrayList<>();
HashSet<Integer> set=new HashSet<>();
for(int i=0;i<n;i++) {
int val1=sc.nextInt();
int val2=sc.nextInt();
if(val1!=val2) set.add(val2);
if(val1==val2) {
if(set1.contains(val1)) set.add(val1);
set1.add(val1);
map.put(val1, i);
}
ar.add(val1);
}
int count=0;
for(int i=0;i<ar.size();i++) {
if(set.contains(ar.get(i))) continue;
if(map.containsKey(ar.get(i)) && map.get(ar.get(i))!=i) continue;
ans++;
}
System.out.println(ans);
}
}
class Reader{
BufferedReader reader;
Reader(){
reader=new BufferedReader(new InputStreamReader(System.in));
}
int nextInt() throws IOException{
String in=reader.readLine().trim();
return Integer.parseInt(in);
}
long nextLong() throws IOException{
String in=reader.readLine().trim();
return Long.parseLong(in);
}
String next() throws IOException{
return reader.readLine().trim();
}
String[] stringArray() throws IOException{
return reader.readLine().trim().split("\\s+");
}
int[] intArray() throws IOException{
String[] inp=this.stringArray();
int[] arr=new int[inp.length];
int i=0;
for(String s:inp) {
arr[i++]=Integer.parseInt(s);
}
return arr;
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
9b7e4195ba24740e52086a1c2d3675cf
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.*;
public class A315
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int []f=new int[n];
int []s=new int[n];
for (int i = 0; i < n; i++) {
f[i]=sc.nextInt();
s[i]=sc.nextInt();
}
int cnt=n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if(f[i]==s[j] && i!=j){
cnt--;
break;
}
}
}
System.out.println(cnt);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
dce89be079bba2d72832317fd0fdbb2e
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.*;
public class bottles
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[]=new int[n];
int b[]=new int[n];
for(int i=0;i<a.length;i++)
{ a[i]=sc.nextInt();
// for(int i=0;i<b.length;i++)
b[i]=sc.nextInt();}
for(int i=0;i<a.length;i++)
{
for(int j=0;j<b.length;j++)
{
if(a[i]==b[j] && i!=j)
{ n--;
break;
}
}
}
System.out.println(n);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
beba8bc30d62e3bb1644fff88bd93ce0
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.Scanner;
public class SerejaAndBottles {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int n=in.nextInt();int[] a=new int[n];int[] b=new int[n];
for(int i=0;i<n;i++){
a[i]=in.nextInt();b[i]=in.nextInt();
}
for(int i=0;i<a.length;i++){
for(int j=0;j<b.length;j++){
if(a[i]==b[j]&&i!=j) {n--;break;}
}
}
System.out.println(n);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
038bc4d95294b28a33641d6e88087c0d
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class CF315A {
static class Info{
int ai;
int bi;
Info(int ai,int bi){
this.ai = ai;
this.bi = bi;
}
}
public static void main(String[] args) {
FastReader input = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
int n = input.nextInt();
ArrayList<Info> list = new ArrayList<Info>();
for(int i = 1;i <= n;i++){
int ai = input.nextInt();
int bi = input.nextInt();
list.add(new Info(ai,bi));
}
boolean[] opened = new boolean[n+1];
for(int i = 0;i < list.size();i++){
int bi = list.get(i).bi;
// pw.println("bi " + bi);
for(int j = 0;j < list.size();j++){
if(j != i){
if(list.get(j).ai == bi){
opened[(j+1)] = true;
}
}
}
}
int count = 0;
for(int i = 1;i <= n;i++){
// pw.print(opened[i] + " ");
if(opened[i]){
count++;
}
}
pw.println(n - count);
// ****If sorting is required, use ArrayList
pw.flush();
pw.close();
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
e37f30e16fb492174413fe16133f9f4d
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class tbuttons {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int cnt=0;
int t=in.nextInt();
Set<Integer> vis=new HashSet<>();
int[][] a=new int[2][t];
for (int i = 0; i < t; i++) {
a[0][i]=in.nextInt();
a[1][i]=in.nextInt();
}
Set<Integer>s=new HashSet<>();
int store;
for (int i = 0; i < t; i++) {
store=a[1][i];
for (int j = 0; j < t; j++) {
if(store==a[0][j] && j!=i && !s.contains(j)){
s.add(j);
cnt++;
}
}
}
System.out.println(t-cnt);
}
}
/*
5
1 4
6 6
4 3
3 4
4 758
*/
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
eccfecb7d4bfd58e12095dc80510ea23
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
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 a[]=new int[n], b[]=new int[n];
int ans=0,i,j;
for(i=0;i<n;i++)
{
a[i]=input.nextInt();
b[i]=input.nextInt();
}
for(i=0;i<n;i++){
int k=0;
for (j=0;j<n;j++)
if(i!=j && a[i]==b[j])
{
k=1;
break;
}
if(k==0)
ans++;
}
System.out.println(ans);
input.close();
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
0c19d8d478273a867fc3f944b4ac03d8
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.Scanner;
public class SerejaAndBottles {
private static Scanner input;
public static void main(String[] args) {
input = new Scanner(System.in);
int bottleN, openableBottles = 0;
bottleN = input.nextInt();
int[] mainBottle = new int[bottleN];
int[] openableBottle = new int[bottleN];
for (int i = 0; i < bottleN; i++) {
mainBottle[i] = input.nextInt();
openableBottle[i] = input.nextInt();
}
for (int i = 0; i < bottleN; i++) {
boolean opened = false;
for (int j = 0; j < bottleN && !opened; j++) {
if (i != j && mainBottle[i] == openableBottle[j]) {
openableBottles++;
opened = true;
}
}
}
System.out.println(bottleN - openableBottles);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
ba80f5b4064ed9451b9bdbe75b6365ea
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.io.*;
import java.util.StringTokenizer;
//solution classes here
public class Code {
//main solution here
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
int n=sc.nextInt();
int a[] = new int[n];
int b[] = new int[n];
for(int i=0;i<n;i++) {
a[i] = sc.nextInt();
b[i] = sc.nextInt();
}
int check[] = new int[1001];
int count=0;
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
if(j==i) continue;
if(check[j]!=1) {
if (b[i] == a[j]) {
check[j] = 1;
count++;
}
}
}
}
out.println(n-count);
out.flush();
out.close();
}
/*
* ******************************************************************************************************************************
* ******************************************************************************************************************************
* ******************************************************************************************************************************
* ######### ####### ###### ######## ## ### ## ## ## ####### ## ## ####### ## ## ####### ########
* ## ### ## ## ######## ## ## # ## ## ## ## ## ## ## ## ## ## ## ##
* ## ### ####### ###### ## ## ## # ## ## ####### ## ## ## #### ####### ########
* ## ### ## ## ## ## ## ### ## ## ## ## ## ## ## ## ## ##
* ######### ####### ###### ## ## ## ## ## ## ######## ####### ## ## ####### ## ##
*******************************************************************************************************************************
*******************************************************************************************************************************
*******************************************************************************************************************************
*/
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader fileReader) {
br = new BufferedReader(fileReader);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
/* *****************************************************************************************************************************
* I'M NOT IN DANGER, I'M THE DANGER!!!
* *****************************************************************************************************************************
*/
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
3c966c2d4ac7b454a0a12c4164c42e38
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.Arrays;
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner pew = new Scanner(System.in);
int n = pew.nextInt();
int a[] = new int[n];
int b[] = new int[n];
for(int i = 0 ; i<n; i++){
a[i] = pew.nextInt();
b[i] = pew.nextInt();
}
int c = 0;
for(int i = 0; i<n; i++)
for(int j = 0; j<n; j++)
if(a[i] == b[j] && i!=j){
c++;
break;
}
System.out.println(n - c);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
7f44a7450d2ac145ad535f662368da0b
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.Scanner;
public class SerejaBottles {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int a[] = new int[n];
int b[] = new int[n];
int open[] = new int[1001];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
b[i] = in.nextInt();
open[b[i]]++;
}
int ans = n;
for (int i = 0; i < n; i++) {
if (a[i] == b[i]) {
if (open[a[i]] > 1) {
ans--;
}
} else {
if (open[a[i]] > 0) {
ans--;
}
}
}
System.out.println(ans);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
5e0258524b18360c815e3e1539409064
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.*;
public class Sol1
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int n,i,j,count;
count=n=in.nextInt();
int a[]=new int[n];
int b[]=new int[n];
boolean visited[]=new boolean[n];
for(i=0;i<n;i++)
{
a[i]=in.nextInt();
b[i]=in.nextInt();
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(b[i]==a[j]&&!visited[j]&&j!=i)
{
count--;
visited[j]=true;
}
}
}
System.out.println(count);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
15a466ca18f3678c82f8d8d952429ce8
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class cfvc13_temp
{
static BufferedReader reader;
static StringTokenizer tokenizer;
static void init(InputStream input)
{
reader = new BufferedReader( new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
static String next() throws IOException
{
while ( ! tokenizer.hasMoreTokens() )
{
tokenizer = new StringTokenizer(reader.readLine() );
}
return tokenizer.nextToken();
}
static long nextInt() throws IOException
{
return Long.parseLong( next() );
}
static PrintWriter writer;
static void outit(OutputStream outputStream)
{
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
static void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
static void println(Object...objects) {
print(objects);
writer.println();
}
static void close() {
writer.close();
}
static void flush() {
writer.flush();
}
public static void main(String [] args) throws IOException
{
init(System.in) ;
outit(System.out) ;
// int t = (int) nextInt() ;
// for(int i =0 ; i<t ; i++)
output() ;
flush();
close();
}
static long mod = 1000000007 ;
public static void output() throws IOException
{
int n = (int) nextInt() ;
int [] a = new int [n] ;
int [] b = new int [n] ;
for(int i = 0 ; i<n ; i++)
{
a[i] = (int) nextInt() ;
b[i] = (int) nextInt() ;
}
int [] check = new int [1001] ;
for(int i = 0 ; i<n ; i++)
{
check[i] = 0;
}
for(int i = 0 ;i<n ; i++)
{
for(int j = 0; j<n ; j++)
{
if(j!=i)
{
if(b[j]==a[i])
{
check[i] = 1 ;
}
}
}
}
int ctr = 0 ;
for(int i = 0 ; i<n ; i++)
{
if(check[i]==0)
{
ctr++ ;
}
}
println(ctr) ;
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
33140eb7fb37d0b8137158d291aa4077
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
// package Practice.CF315;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
public class CF315A {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
HashMap<Integer, ArrayList<Integer>> map = new HashMap<>();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
int a = s.nextInt();
int b = s.nextInt();
ArrayList<Integer> list = map.getOrDefault(a, new ArrayList<>());
arr[i] = b;
list.add(i);
map.put(a, list);
}
int ans = n;
for (int i = 0; i < n; i++) {
if(map.containsKey(arr[i])){
ArrayList<Integer> list = map.get(arr[i]);
ArrayList<Integer> ans1 = new ArrayList<>();
for (int j = 0; j < list.size(); j++) {
if(list.get(j) != i){
ans1.add(list.get(j));
ans--;
}
}
if(list.equals(ans1)){
map.remove(arr[i]);
}else{
list.removeAll(ans1);
map.put(arr[i], list);
}
}
}
System.out.println(ans);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 8
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
ac01b58ab3a157d3181833284262cba7
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class CodeForce187A {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
StringTokenizer token;
int n = Integer.parseInt(in.readLine());
int[] a = new int[n];
int[] b = new int[n];
for(int i=0;i<n;i++) {
token = new StringTokenizer(in.readLine());
a[i] = Integer.parseInt(token.nextToken());
b[i] = Integer.parseInt(token.nextToken());
}
int count=0;
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
if(j!=i&&a[i]==b[j]){
count++;
break;
}
}
}
System.out.println(n-count);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 6
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
553bebc950cae3b3f09fee0bd67f75fa
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(in);
int n = Integer.parseInt(reader.readLine());
int[] openable = new int[1001];
int[] bottles = new int[1001];
boolean[] self = new boolean[1001];
for (int i = 0; i < n; i++) {
String[] tokens = reader.readLine().split(" ");
int a = Integer.parseInt(tokens[0]);
int b = Integer.parseInt(tokens[1]);
openable[b]++;
bottles[a]++;
if (a == b)
self[a] = true;
}
int unopenable = 0;
for (int i = 1; i < 1001; i++) {
if (openable[i] == 0)
unopenable += bottles[i];
else if (self[i] && openable[i] == 1)
unopenable++;
}
System.out.println(unopenable);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 6
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
3b73c8a87326c1e8a712434a738c5767
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner lectura = new Scanner(System.in);
int[] type;
int[] canopen;
int[] opened;
while(lectura.hasNext())
{
int number = lectura.nextInt();
type = new int[number];
canopen = new int[number];
opened = new int[number];
for(int i=0;i<number;i++)
{
type[i]= lectura.nextInt();
canopen[i]= lectura.nextInt();
opened[i] = 0;
}
for(int i=0;i<number;i++)
{
for(int j=0;j<number;j++)
{
if(type[j]==canopen[i]&&j!=i)
{
opened[j]=1;
}
}
}
int counter =0;
for(int i=0;i<number;i++){
if(opened[i]==0)
{
counter++;
}
}
System.out.println(counter);
}
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 6
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
e71817261a0ffcaf7c610d8f03777e76
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class P315A {
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine().trim()); //1-100
int status[] = new int[n];
int brandA[] = new int[n];
int brandB[] = new int[n];
for (int i=0; i<n; i++) {
String line = br.readLine();
String[] strs = line.trim().split("\\s+");
int currentA = Integer.parseInt(strs[0]);
int currentB = Integer.parseInt(strs[1]);
brandA[i] = currentA;
brandB[i] = currentB;
status[i] = 0;
for (int j=0; j<i; j++) {
if (currentB==brandA[j]) {
status[j]=1;
}
if (brandB[j]==currentA) {
status[i]=1;
}
}
}
int count=0;
for (int i=0; i<n; i++) {
if (status[i]==0) {
count++;
}
}
System.out.println(count);
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 6
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
d46fa03db9e1274a42decf8d95378ea9
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class C187D2A {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
List<Integer> bottles = new ArrayList<Integer>();
int[] a = new int[1001];
for (int i = 0; i < n; i++) {
int ai = in.nextInt(), bi = in.nextInt();
bottles.add(ai);
a[bottles.size()-1] = bi;
}
int res = n;
for (int i = 0; i < bottles.size(); i++) {
int b = bottles.get(i);
for (int j = 0; j < 1001; j++) {
if (j != i && a[j] == b) {
res--;
break;
}
}
}
out.println(res);
out.flush();
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 6
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
49ed5b4d8f82fed30e76b888eb427ef7
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.Scanner;
public class SerejaAndBottles {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int a[] = new int[n];
int b[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = scanner.nextInt();
b[i] = scanner.nextInt();
}
int closed = n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if(b[i] == a[j] && i != j ) {
// System.out.println(b[i] + " " + a[j]);
closed --;
a[j] = -1;
}
}
}
System.out.println(closed);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 6
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
9143c8f1a364b52c02eb92b1d2e27bb3
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;
public class ProblemA {
public static void main(String[] args) {
ProblemA problem = new ProblemA();
problem.solve(System.in, System.out);
}
public void solve(InputStream in, PrintStream out) {
Scanner scan = new Scanner(in);
int n = scan.nextInt();
int[] a = new int[n];
int[] b = new int[n];
for ( int i = 0; i < n; i++) {
a[i] = scan.nextInt();
b[i] = scan.nextInt();
}
int answer = n;
for ( int i = 0; i < n; i++) {
boolean opened = false;
for ( int j = 0; j < n; j++) {
if ( i == j ) continue;
opened |= b[j] == a[i];
}
if ( opened ) answer--;
}
out.println(answer);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 6
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
20ed282f430b8c7c2288042f63c41a11
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] x = new int[n];
int[] y = new int[n];
int[] b = new int[1005];
for (int i = 0; i < n; i++) {
x[i] = s.nextInt();
y[i] = s.nextInt();
b[y[i]]++;
}
int ans = 0;
for (int i = 0; i < n; i++) {
if (b[x[i]] == 0)
ans++;
else if (b[x[i]] == 1 && y[i] == x[i])
ans++;
}
System.out.println(ans);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 6
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
68591b43f537358d5e7668be4cb9c2fc
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class SerejaAndBottles {
public int solve(int[][] input) {
Set<Integer> cur = new HashSet<Integer>();
int count = 0 ;
for(int i = 0 ; i < input.length ; i++){
for(int j = 0 ; j < input.length ; j++){
if(input[i][1] == input[j][0] && j!=i && !cur.contains(j)){
count++;
cur.add(j);
}
}
}
return input.length - count;
}
public static void main(String [] args){
Scanner s = new Scanner(System.in);
if(s.hasNext()){
int num = Integer.parseInt(s.nextLine());
int [][] input = new int[num][2];
for(int i = 0 ; i < num ; i++){
input[i][0] = s.nextInt();
input[i][1] = s.nextInt();
}
System.out.println(new SerejaAndBottles().solve(input));
}
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 6
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
82f511b79187b5a33c5fc2935d64874a
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.*;
public class cf315a {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] a = new int[n];
int[] b = new int[n];
int[] v = new int[n];
Arrays.fill(v, 1);
for(int i=0; i<n; i++) {
a[i] = in.nextInt();
b[i] = in.nextInt();
}
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
if(i != j && a[i] == b[j])
v[i] = 0;
int sum = 0;
for(int i=0; i<n; i++)
sum += v[i];
System.out.println(sum);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 6
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
e98bfd1a1ca203a5f0935972823b05fa
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
/*
br = new BufferedReader(new FileReader("input.txt"));
pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
*/
public class Main {
private static BufferedReader br;
private static StringTokenizer st;
private static PrintWriter pw;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int qq = 1;
//int qq = Integer.MAX_VALUE;
//int qq = readInt();
for(int casenum = 1; casenum <= qq; casenum++) {
int n = readInt();
int[] a = new int[n];
int[] b = new int[n];
for(int i = 0; i < n; i++) {
a[i] = readInt();
b[i] = readInt();
}
boolean[] can = new boolean[n];
for(int j = 0; j < n; j++) {
for(int i = 0; i < n; i++) {
if(i != j && b[i] == a[j]) {
can[j] = true;
}
}
}
int ret = 0;
for(boolean out: can) {
if(out) {
ret++;
}
}
pw.println(n-ret);
}
pw.close();
}
private static void exitImmediately() {
pw.close();
System.exit(0);
}
private static long readLong() throws IOException {
return Long.parseLong(nextToken());
}
private static double readDouble() throws IOException {
return Double.parseDouble(nextToken());
}
private static int readInt() throws IOException {
return Integer.parseInt(nextToken());
}
private static String nextToken() throws IOException {
while(st == null || !st.hasMoreTokens()) {
if(!br.ready()) {
exitImmediately();
}
st = new StringTokenizer(br.readLine().trim());
}
return st.nextToken();
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 6
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
3d3c7480af074237ec2d5341194b4273
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Main {
BufferedReader in;
StringTokenizer str = null;
PrintWriter out;
private String next() throws Exception{
if (str == null || !str.hasMoreElements())
str = new StringTokenizer(in.readLine());
return str.nextToken();
}
private int nextInt() throws Exception{
return Integer.parseInt(next());
}
private long nextLong() throws Exception{
return Long.parseLong(next());
}
private double nextDouble() throws Exception{
return Double.parseDouble(next());
}
public void run() throws Exception{
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
int n = nextInt();
int a[] = new int[n];
int b[] = new int[n];
Set<Integer> s = new HashSet<Integer>();
for(int i=0;i<n;i++) {
a[i] = nextInt();
b[i] = nextInt();
s.add(a[i]);
}
boolean used[] = new boolean[n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++) if (i != j){
if (b[i] == a[j]){
used[j] = true;
}
}
}
int r = 0;
for(int i=0;i<n;i++){
if (!used[i]){
r++;
}
}
out.println(r);
out.close();
}
public static void main(String[] args) throws Exception{
new Main().run();
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 6
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
59c394f24333cf9fc5d39111c5cdb01d
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.Scanner;
public class A {
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
int n=sc.nextInt();
int v[][]=new int [n][2];
for (int i = 0; i < n; i++) {
v[i][0]=sc.nextInt();
v[i][1]=sc.nextInt();
}
int res[]=new int[n];
int r=n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (j!=i) {
if (v[j][0]==v[i][1]&& res[j]==0) {
res[j]=1;
r--;
}
}
}
}
System.out.println(r);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 6
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
35495c9eac4fd420ba8bc5f712e9a603
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import java.io.*;
import java.math.*;
import java.util.*;
@SuppressWarnings("unused")
public class A {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] A = new int[n];
int[] B = new int[n];
for (int i = 0; i < n; i++) {
A[i] = in.nextInt();
B[i] = in.nextInt();
}
boolean[] opened = new boolean[n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i != j && B[i] == A[j]) {
opened[j] = true;
}
}
}
int count = 0;
for (boolean b : opened) {
count += b == false ? 1 : 0;
}
System.out.println(count);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 6
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
a9a973d603406545c3bd89da05a34e4b
|
train_001.jsonl
|
1370619000
|
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
256 megabytes
|
import java.util.Scanner;
public class probA {
public static void main (String []args)
{
Scanner bahy = new Scanner(System.in);
int n=bahy.nextInt();
int [][]a=new int[n][2];
boolean []b=new boolean[n];
for(int i=0;i<n;i++)
{
a[i][0]=bahy.nextInt();
a[i][1]=bahy.nextInt();
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i!=j)
{
if(a[i][1]==a[j][0])
{
//System.out.println(a[i][1]);
//System.out.println(a[j][0]);
b[j]=true;
}
}
}
}
int count=0;
for(int i=0;i<n;i++)
{
if(b[i]==false)
count++;
}
System.out.println(count);
}
}
|
Java
|
["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1"]
|
2 seconds
|
["4", "0"]
| null |
Java 6
|
standard input
|
[
"brute force"
] |
84bd49becca69e126606d5a2f764dd91
|
The first line contains integer n (1ββ€βnββ€β100) β the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai,βbi (1ββ€βai,βbiββ€β1000) β the description of the i-th bottle.
| 1,400 |
In a single line print a single integer β the answer to the problem.
|
standard output
| |
PASSED
|
ad984c04206f6c688a11768245ab743b
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
Solution solver = new Solution();
solver.solve(in, out);
out.close();
}
static class Solution {
public void solve(InputReader in, PrintWriter out) {
int n = in.nextInt();
out.println("2");
for (long i = 2; i <= n; i++) {
long ans = (i * (i + 1) * (i + 1) - (i - 1));
out.println(ans);
}
}
}
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
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
aa91e7ed6e9a0f7362dac5a1e0c938de
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class A {
public static void solution(BufferedReader reader, PrintWriter out)
throws IOException {
In in = new In(reader);
BigInteger N = new BigInteger(in.next());
BigInteger num = new BigInteger("2");
BigInteger i = BigInteger.ONE;
for (; i.compareTo(N) <= 0; i = i.add(BigInteger.ONE)) {
BigInteger rst = i.multiply(i.add(BigInteger.ONE));
out.println(rst.multiply(rst).subtract(num).divide(i).toString());
num = rst;
}
}
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(
new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(
new BufferedWriter(new OutputStreamWriter(System.out)));
solution(reader, out);
out.close();
}
protected static class In {
private BufferedReader reader;
private StringTokenizer tokenizer = new StringTokenizer("");
public In(BufferedReader reader) {
this.reader = reader;
}
public String next() throws IOException {
while (!tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
return tokenizer.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
4b5bc27fc4bb64a0032b385ef1b15fa6
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
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);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
long[] res = new long[(int) (1e6 + 10)];
res[1] = 2;
for (int i = 2; i < 1e6 + 10; i++) {
res[i] = (i + 1);
res[i] = res[i] * res[i] * i - i + 1;
//out.println(res[i]);
}
int n = in.nextInt();
for (int i = 1; i <= n; i++) {
out.println(res[i]);
}
}
}
static class InputReader {
public byte[] buf = new byte[8000];
public int index;
public int total;
public InputStream in;
public InputReader(InputStream stream) {
in = stream;
}
public int scan() {
if (total == -1)
throw new InputMismatchException();
if (index >= total) {
index = 0;
try {
total = in.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (total <= 0)
return -1;
}
return buf[index++];
}
public int nextInt() {
int integer = 0;
int n = scan();
while (isWhiteSpace(n))
n = scan();
int neg = 1;
if (n == '-') {
neg = -1;
n = scan();
}
while (!isWhiteSpace(n)) {
if (n >= '0' && n <= '9') {
integer *= 10;
integer += n - '0';
n = scan();
} else
throw new InputMismatchException();
}
return neg * integer;
}
public boolean isWhiteSpace(int n) {
if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
return true;
return false;
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
ecc5b25eb87ce5378b3e1d07bda4ac5d
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.util.Scanner;
/**
* Created by anna on 17.09.16.
*/
public class cf3 {
private static Scanner is = new Scanner(System.in);
public static long isSquare(long n) {
double sq = Math.sqrt(n);
if ((long)sq*(long)sq == n) return (long)sq;
else return -1;
}
public static void main(String[] args) {
int n = is.nextInt();
// System.out.print(isSquare(n));
long[] pluses = new long[n];
long onScreen = 2;
int k = 2;
pluses[0] = 2;
long nextsq = 2;
//
// while (k < n + 1) {
// long sq = isSquare(onScreen);
// if (sq != -1) {
// if (sq % (k+1) == 0) {
// onScreen = sq;
// k++;
// } else {
// pluses[k - 1]++;
// onScreen += k;
// }
// } else {
// pluses[k - 1]++;
// onScreen += k;
// }
// }
// while (k < n + 1) {
// pluses[k - 1] = (nextsq * nextsq - onScreen) / k;
// k++;
// onScreen = nextsq;
//// System.out.print(k+": " + onScreen+ "\n");
// long sq = isSquare(k);
// nextsq = k*(k+1);
// }
while (k < n + 1) {
pluses[k - 1] = ((long)(k+1))*(k+1)*k - (k-1);
k++;
onScreen = nextsq;// prev nextsq = (k - 1)*k
// System.out.print(k+": " + onScreen+ "\n");
long sq = isSquare(k);
nextsq = k*(k+1);
}
for (int i = 0; i < n; i++) {
System.out.println(Math.abs(pluses[i]));
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
0db70187a6b6726498bdfb2aa290c66c
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.util.Scanner;
/**
* Created by anna on 17.09.16.
*/
public class cf3 {
private static Scanner is = new Scanner(System.in);
public static long isSquare(long n) {
double sq = Math.sqrt(n);
if ((long)sq*(long)sq == n) return (long)sq;
else return -1;
}
public static void main(String[] args) {
int n = is.nextInt();
// System.out.print(isSquare(n));
long[] pluses = new long[n];
long onScreen = 2;
int k = 2;
pluses[0] = 2;
long nextsq = 6;
//
// while (k < n + 1) {
// long sq = isSquare(onScreen);
// if (sq != -1) {
// if (sq % (k+1) == 0) {
// onScreen = sq;
// k++;
// } else {
// pluses[k - 1]++;
// onScreen += k;
// }
// } else {
// pluses[k - 1]++;
// onScreen += k;
// }
// }
// while (k < n + 1) {
// pluses[k - 1] = (nextsq * nextsq - onScreen) / k;
// k++;
// onScreen = nextsq;
//// System.out.print(k+": " + onScreen+ "\n");
// long sq = isSquare(k);
// nextsq = k*(k+1);
// }
while (k < n + 1) {
pluses[k - 1] = nextsq*((long)(k+1)) - (long)(k-1);
k++;
onScreen = nextsq;// prev nextsq = (k - 1)*k
// System.out.print(k+": " + onScreen+ "\n");
long sq = isSquare(k);
nextsq = k*(k+1);
}
System.out.println(2);
for (long i = 2; i <= n; i++) {
System.out.println(i*(i+1)*(i+1) - (i-1));
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
c1c2695e795bf8b3f2e0f9f6f3d25c48
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
//package codeForces;
import java.util.*;
public class codeTest {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
long n = sc.nextInt();
System.out.println("2");
for(long i=2;i<=n;i++){
System.out.println(i*(i+1)*(i+1)-i+1);
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
d5bca24c91440cf365044c0799a0a009
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.*;
import java.math.*;
import java.util.*;
import static java.util.Arrays.*;
public class A {
private static final int mod = (int)1e9+7;
final Random random = new Random(0);
final IOFast io = new IOFast();
/// MAIN CODE
public void run() throws IOException {
// int TEST_CASE = Integer.parseInt(new String(io.nextLine()).trim());
int TEST_CASE = 1;
while(TEST_CASE-- != 0) {
int n = io.nextInt();
long cur = 2;
for(long i = 1; i <= n; i++) {
// if(cur % i != 0) throw new RuntimeException();
long x = i*(i+1)*(i+1) - cur/i;
io.out.println(x);
cur = i * (i + 1);
}
}
}
/// TEMPLATE
static int gcd(int n, int r) { return r == 0 ? n : gcd(r, n%r); }
static long gcd(long n, long r) { return r == 0 ? n : gcd(r, n%r); }
static <T> void swap(T[] x, int i, int j) { T t = x[i]; x[i] = x[j]; x[j] = t; }
static void swap(int[] x, int i, int j) { int t = x[i]; x[i] = x[j]; x[j] = t; }
void printArrayLn(int[] xs) { for(int i = 0; i < xs.length; i++) io.out.print(xs[i] + (i==xs.length-1?"\n":" ")); }
void printArrayLn(long[] xs) { for(int i = 0; i < xs.length; i++) io.out.print(xs[i] + (i==xs.length-1?"\n":" ")); }
static void dump(Object... o) { System.err.println(Arrays.deepToString(o)); }
void main() throws IOException {
// IOFast.setFileIO("rle-size.in", "rle-size.out");
try { run(); }
catch (EndOfFileRuntimeException e) { }
io.out.flush();
}
public static void main(String[] args) throws IOException { new A().main(); }
static class EndOfFileRuntimeException extends RuntimeException {
private static final long serialVersionUID = -8565341110209207657L; }
static
public class IOFast {
private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
private PrintWriter out = new PrintWriter(System.out);
void setFileIn(String ins) throws IOException { in.close(); in = new BufferedReader(new FileReader(ins)); }
void setFileOut(String outs) throws IOException { out.flush(); out.close(); out = new PrintWriter(new FileWriter(outs)); }
void setFileIO(String ins, String outs) throws IOException { setFileIn(ins); setFileOut(outs); }
private static int pos, readLen;
private static final char[] buffer = new char[1024 * 8];
private static char[] str = new char[500*8*2];
private static boolean[] isDigit = new boolean[256];
private static boolean[] isSpace = new boolean[256];
private static boolean[] isLineSep = new boolean[256];
static { for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; } isDigit['-'] = true; isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true; isLineSep['\r'] = isLineSep['\n'] = true; }
public int read() throws IOException { if(pos >= readLen) { pos = 0; readLen = in.read(buffer); if(readLen <= 0) { throw new EndOfFileRuntimeException(); } } return buffer[pos++]; }
public int nextInt() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; int ret = 0; if(str[0] == '-') { i = 1; } for(; i < len; i++) ret = ret * 10 + str[i] - '0'; if(str[0] == '-') { ret = -ret; } return ret; }
public long nextLong() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; long ret = 0; if(str[0] == '-') { i = 1; } for(; i < len; i++) ret = ret * 10 + str[i] - '0'; if(str[0] == '-') { ret = -ret; } return ret; }
public char nextChar() throws IOException { while(true) { final int c = read(); if(!isSpace[c]) { return (char)c; } } }
int reads(int len, boolean[] accept) throws IOException { try { while(true) { final int c = read(); if(accept[c]) { break; } if(str.length == len) { char[] rep = new char[str.length * 3 / 2]; System.arraycopy(str, 0, rep, 0, str.length); str = rep; } str[len++] = (char)c; } } catch(EndOfFileRuntimeException e) { ; } return len; }
int reads(char[] cs, int len, boolean[] accept) throws IOException { try { while(true) { final int c = read(); if(accept[c]) { break; } cs[len++] = (char)c; } } catch(EndOfFileRuntimeException e) { ; } return len; }
public char[] nextLine() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isLineSep); try { if(str[len-1] == '\r') { len--; read(); } } catch(EndOfFileRuntimeException e) { ; } return Arrays.copyOf(str, len); }
public String nextString() throws IOException { return new String(next()); }
public char[] next() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); return Arrays.copyOf(str, len); }
// public int next(char[] cs) throws IOException { int len = 0; cs[len++] = nextChar(); len = reads(cs, len, isSpace); return len; }
public double nextDouble() throws IOException { return Double.parseDouble(nextString()); }
public long[] nextLongArray(final int n) throws IOException { final long[] res = new long[n]; for(int i = 0; i < n; i++) { res[i] = nextLong(); } return res; }
public int[] nextIntArray(final int n) throws IOException { final int[] res = new int[n]; for(int i = 0; i < n; i++) { res[i] = nextInt(); } return res; }
public int[][] nextIntArray2D(final int n, final int k) throws IOException { final int[][] res = new int[n][]; for(int i = 0; i < n; i++) { res[i] = nextIntArray(k); } return res; }
public int[][] nextIntArray2DWithIndex(final int n, final int k) throws IOException { final int[][] res = new int[n][k+1]; for(int i = 0; i < n; i++) { for(int j = 0; j < k; j++) { res[i][j] = nextInt(); } res[i][k] = i; } return res; }
public double[] nextDoubleArray(final int n) throws IOException { final double[] res = new double[n]; for(int i = 0; i < n; i++) { res[i] = nextDouble(); } return res; }
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
ae494f1909d30164ca926c680437ebfa
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class mat
{
static class InputReader {
private InputStream stream;
private byte[] inbuf = new byte[1024];
private int start= 0;
private int end = 0;
public InputReader(InputStream stream) {
this.stream = stream;
}
private int readByte() {
if (start == -1) throw new UnknownError();
if (end >= start) {
end= 0;
try {
start= stream.read(inbuf);
} catch (IOException e) {
throw new UnknownError();
}
if (start<= 0) return -1;
}
return inbuf[end++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
public String next() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
public long nextLong() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
}
static BigInteger gcd(BigInteger a,BigInteger b)
{
if(b.compareTo(BigInteger.ZERO)==0)
return a;
else
return gcd(b,a.mod(b));
}
public static void main(String args[])
{
InputReader sc=new InputReader(System.in);
long n=sc.nextLong();
BigInteger a[]=new BigInteger[(int)n+1];
a[1]=new BigInteger(String.valueOf(2));
BigInteger l1,l2,l3,l4;
for(int i=2;i<=n;i++)
{
l1=new BigInteger(String.valueOf(i)).multiply(new BigInteger(String.valueOf(i+1)));
l2=l1.multiply(l1);
l3=l2.subtract((new BigInteger(String.valueOf(i-1))).multiply(new BigInteger(String.valueOf(i))));
a[i]=l3.divide(new BigInteger(String.valueOf(i)));
}
for(int i=1;i<=n;i++)
System.out.println(a[i]);
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
197c43e83e15c949da6d4331aecb4778
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
long n = in.nextInt();
long k = 1;
long val = 2;
while(k <= n) {
//long sqrt = (k+1)*(val % k);
BigInteger sqrt = BigInteger.valueOf((k+1) * (val % k));
BigInteger add = BigInteger.valueOf(k+1).multiply(BigInteger.valueOf(k));
BigInteger target = sqrt.multiply(sqrt);
BigInteger valBig = BigInteger.valueOf(val);
BigInteger kBig = BigInteger.valueOf(k);
//long target = sqrt*sqrt;
//System.out.println(sqrt);
while(target.compareTo(valBig) < 0) {
//sqrt += (k+1)*k;
//sqrt.add(val)
// (sqrt + a*(k+1)*k)^2 >= valBig
// (sqrt*sqrt + 2*sqrt*a*(k+1)*k + (a*(k+1)*k)^2 >= valBig
sqrt = sqrt.add(add);
target = sqrt.multiply(sqrt);
//target = sqrt*sqrt;
}
//System.out.println("val=" + val +", k=" + k + ", sqrt=" +sqrt + ", tar=" + target);
//System.out.println("distance = " + (target-val));
//System.out.println((target - val)/k);
out.println(target.subtract(valBig).divide(kBig));
val = sqrt.longValue();
k++;
}
out.close();
}
public static long lcm(long a, long b) {
return a/gcd(a,b) * b;
}
public static long gcd(long a, long b) {
if(b == 0) return a;
return gcd(b, a%b);
}
public static long sqrt(long n) {
long sqrt = Math.round(Math.sqrt(n));
if(sqrt*sqrt == n)
return sqrt;
return -1;
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
51a9d00dd20a3a733c4d05067c36b657
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;
@SuppressWarnings("unchecked")
public class P715A {
public void run() throws Exception {
BigInteger n = BigInteger.valueOf(nextInt()), v = BigInteger.valueOf(2);
for (BigInteger l = BigInteger.ONE; l.compareTo(n) <= 0; l = l.add(BigInteger.ONE)) {
BigInteger v1 = l.add(BigInteger.ONE).multiply(l);
println(v1.pow(2).subtract(v).divide(l));
v = v1;
}
}
public static void main(String... args) throws Exception {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedOutputStream(System.out));
new P715A().run();
br.close();
pw.close();
System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
}
static long startTime = System.currentTimeMillis();
static BufferedReader br;
static PrintWriter pw;
StringTokenizer stok;
String nextToken() throws IOException {
while (stok == null || !stok.hasMoreTokens()) {
String s = br.readLine();
if (s == null) { return null; }
stok = new StringTokenizer(s);
}
return stok.nextToken();
}
void print(byte b) { print("" + b); }
void print(int i) { print("" + i); }
void print(long l) { print("" + l); }
void print(double d) { print("" + d); }
void print(char c) { print("" + c); }
void print(Object o) {
if (o instanceof int[]) { print(Arrays.toString((int [])o));
} else if (o instanceof long[]) { print(Arrays.toString((long [])o));
} else if (o instanceof char[]) { print(Arrays.toString((char [])o));
} else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
} else if (o instanceof short[]) { print(Arrays.toString((short [])o));
} else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
} else if (o instanceof float[]) { print(Arrays.toString((float [])o));
} else if (o instanceof double[]) { print(Arrays.toString((double [])o));
} else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
} else { print("" + o); }
}
void print(String s) { pw.print(s); }
void println() { println(""); }
void println(byte b) { println("" + b); }
void println(int i) { println("" + i); }
void println(long l) { println("" + l); }
void println(double d) { println("" + d); }
void println(char c) { println("" + c); }
void println(Object o) { print(o); println(); }
void println(String s) { pw.println(s); }
int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
long nextLong() throws IOException { return Long.parseLong(nextToken()); }
double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
char nextChar() throws IOException { return (char) (br.read()); }
String next() throws IOException { return nextToken(); }
String nextLine() throws IOException { return br.readLine(); }
int [] readInt(int size) throws IOException {
int [] array = new int [size];
for (int i = 0; i < size; i++) { array[i] = nextInt(); }
return array;
}
long [] readLong(int size) throws IOException {
long [] array = new long [size];
for (int i = 0; i < size; i++) { array[i] = nextLong(); }
return array;
}
double [] readDouble(int size) throws IOException {
double [] array = new double [size];
for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
return array;
}
String [] readLines(int size) throws IOException {
String [] array = new String [size];
for (int i = 0; i < size; i++) { array[i] = nextLine(); }
return array;
}
int gcd(int a, int b) {
return ((b > 0) ? gcd(b, a % b) : a);
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
eac1758890fa72d0b24ff7971a594f92
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/* 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);
long n = in.nextLong();
BigInteger m = BigInteger.valueOf(n);
BigInteger temp = new BigInteger("2");
BigInteger jwb,temp2;
for (BigInteger i=BigInteger.valueOf(1L);i.compareTo(m)<=0;i = i.add(BigInteger.valueOf(1L)))
{
temp2 = i.add(BigInteger.valueOf(1L));
jwb = i.multiply(temp2.multiply(temp2));
temp2 = temp.divide(i);
jwb = jwb.subtract(temp2);
System.out.println(jwb);
temp = i.multiply(i.add(BigInteger.valueOf(1L)));
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
b6e3bb9d33ce63d933cd2076b631a184
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class C {
private static final boolean TEST_CASES = false;
private static class Solver {
void solve(int testCaseNo) {
int n = IO.nextInt();
for (int i = 1; i <= n; ++i) {
if (i == 1) IO.writer.println("2");
else {
long t = i;
t = t * t;
long r = 2 * t;
r += i * t + 1;
IO.writer.println(r);
}
}
}
}
private static class IO {
private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
static final PrintWriter writer = new PrintWriter(System.out);
private static StringTokenizer tokenizer = null;
static String nextToken() {
checkTokenizer();
return tokenizer.nextToken();
}
static long nextLong() {
return Long.parseLong(nextToken());
}
static int nextInt() {
return Integer.parseInt(nextToken());
}
static void close() {
writer.flush();
}
private static boolean isTokenizerEmpty() {
return tokenizer == null || !tokenizer.hasMoreTokens();
}
private static void checkTokenizer() {
while (isTokenizerEmpty()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
private static void go() {
int testCases = TEST_CASES ? IO.nextInt() : 1;
Solver solver = new Solver();
for (int testCase = 0; testCase < testCases; testCase++) {
solver.solve(testCase);
}
}
public static void main(String[] args) {
try {
go();
} finally {
IO.close();
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
bc88a61ffb4a062c09f7adc402c519b1
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.*;
import java.math.*;
import java.util.*;
/**
*
* @author Saju
*
*/
public class Main {
private static int dx[] = { 1, 0, -1, 0 };
private static int dy[] = { 0, -1, 0, 1 };
private static final long INF = (long) Math.pow(10, 16);
private static final int INT_INF = Integer.MAX_VALUE;
private static final long NEG_INF = Long.MIN_VALUE;
private static final int NEG_INT_INF = Integer.MIN_VALUE;
private static final double EPSILON = 1e-10;
private static final long MAX = (long) 1e12;
private static final long MOD = 1000000007;
private static final int MAXN = 200001;
private static final int MAXA = 1000007;
private static final int MAXLOG = 22;
private static final double PI = Math.acos(-1);
public static void main(String[] args) throws IOException {
InputReader in = new InputReader(System.in);
// Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
// InputReader in = new InputReader(new FileInputStream("src/test.in"));
// PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("src/test.out")));
/*
*/
int n = in.nextInt() + 1;
BigInteger prevBig = BigInteger.valueOf(2);
for(long i = 2; i <= n; i++) {
long bottom = (i - 1) * i;
BigInteger bottomBig = BigInteger.valueOf(bottom);
BigInteger sq = bottomBig.pow(2);
BigInteger diffBig = sq.subtract(prevBig);
BigInteger valBig = diffBig.divide(BigInteger.valueOf(i - 1));
out.println(valBig);
prevBig = bottomBig;
}
in.close();
out.flush();
out.close();
System.exit(0);
}
/*
* return the number of elements in list that are less than or equal to the val
*/
private static long upperBound(List<Long> list, long val) {
int start = 0;
int len = list.size();
int end = len - 1;
int mid = 0;
while (true) {
if (start > end) {
break;
}
mid = (start + end) / 2;
long v = list.get(mid);
if (v == val) {
start = mid;
while(start < end) {
mid = (start + end) / 2;
if(list.get(mid) == val) {
if(mid + 1 < len && list.get(mid + 1) == val) {
start = mid + 1;
}
else {
return mid + 1;
}
}
else {
end = mid - 1;
}
}
return start + 1;
}
if (v > val) {
end = mid - 1;
} else {
start = mid + 1;
}
}
if (list.get(mid) < val) {
return mid + 1;
}
return mid;
}
private static boolean isPalindrome(String str) {
StringBuilder sb = new StringBuilder();
sb.append(str);
String str1 = sb.reverse().toString();
return str.equals(str1);
}
private static String getBinaryStr(long n, int j) {
String str = Long.toBinaryString(n);
int k = str.length();
for (int i = 1; i <= j - k; i++) {
str = "0" + str;
}
return str;
}
private static long modInverse(long r) {
return bigMod(r, MOD - 2, MOD);
}
private static long bigMod(long n, long k, long m) {
long ans = 1;
while (k > 0) {
if ((k & 1) == 1) {
ans = (ans * n) % m;
}
n = (n * n) % m;
k >>= 1;
}
return ans;
}
private static long ceil(long n, long x) {
long div = n / x;
if(div * x != n) {
div++;
}
return div;
}
private static int ceil(int n, int x) {
int div = n / x;
if(div * x != n) {
div++;
}
return div;
}
private static int abs(int x) {
if (x < 0) {
return -x;
}
return x;
}
private static double abs(double x) {
if (x < 0) {
return -x;
}
return x;
}
private static long abs(long x) {
if(x < 0) {
return -x;
}
return x;
}
private static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
private static int lcm(int a, int b) {
return (a * b) / gcd(a, b);
}
private static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
private static long gcd(long a, long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
private static int log(long x, int base) {
return (int) (Math.log(x) / Math.log(base));
}
private static int log(long x, long base) {
return (int) (Math.log(x) / Math.log(base));
}
private static long min(long a, long b) {
if (a < b) {
return a;
}
return b;
}
private static int min(int a, int b) {
if (a < b) {
return a;
}
return b;
}
private static long max(long a, long b) {
if (a < b) {
return b;
}
return a;
}
private static int max(int a, int b) {
if (a < b) {
return b;
}
return a;
}
private static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
try {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
} catch (IOException e) {
return null;
}
return tokenizer.nextToken();
}
public String nextLine() {
String line = null;
try {
tokenizer = null;
line = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return line;
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public boolean hasNext() {
try {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
} catch (Exception e) {
return false;
}
return true;
}
public int[] nextIntArr(int n) {
int arr[] = new int[n];
for(int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArr(int n) {
long arr[] = new long[n];
for(int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
public int[] nextIntArr1(int n) {
int arr[] = new int[n + 1];
for(int i = 1; i <= n; i++) {
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArr1(int n) {
long arr[] = new long[n + 1];
for(int i = 1; i <= n; i++) {
arr[i] = nextLong();
}
return arr;
}
public void close() {
try {
if(reader != null) {
reader.close();
}
}
catch(Exception e) {
}
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
bc49592ab4815ad2cabe2add442572a3
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.util.Scanner;
import java.math.*;
public class Main {
public static void main(String[] args) {
Scanner sin = new Scanner(System.in);
int n = sin.nextInt();
BigInteger plus;
System.out.println(2);
for(int i = 2; i < n + 1; i++){
plus = BigInteger.valueOf(i + 1);
plus = plus.multiply(plus);
plus = plus.multiply(BigInteger.valueOf(i));
plus = plus.subtract(BigInteger.valueOf(i - 1));
System.out.println(plus);
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
02c66c8bb8fab8ee96731e08a8eb74d9
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.awt.Point;
import java.awt.geom.Line2D;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.security.GuardedObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.io.InputStream;
import java.math.BigInteger;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in;
PrintWriter out;
in=new FastScanner(System.in);
out=new PrintWriter(System.out);
//in=new FastScanner(new FileInputStream(new File("C://Users//KANDARP//Desktop//coding_contest_creation (1).txt")));
TaskC solver = new TaskC();
long var=System.currentTimeMillis();
solver.solve(1, in, out);
/*if(System.getProperty("ONLINE_JUDGE")==null){
out.println("["+(double)(System.currentTimeMillis()-var)/1000+"]");
}*/
out.close();
}
}
class Pair {
long x,y,index;
long r1,r2;
Pair(long x,long y,int index){
this.x=x;
this.y=y;
this.index=index;
}
public String toString(){
return this.x+" "+this.y+" ";
}
}
class Edge implements Comparable<Edge>{
int u;
int v;
int time;
long cost;
long wcost;
public Edge(int u,int v,long cost,long wcost){
this.u=u;
this.v=v;
this.cost=cost;
this.wcost=wcost;
time=Integer.MAX_VALUE;
}
public int other(int x){
if(u==x)return v;
return u;
}
@Override
public int compareTo(Edge o) {
// TODO Auto-generated method stub
return Long.compare(cost, o.cost);
}
}
class queary{
int type;
int l;
int r;
int index;
queary(int type,int l,int r,int index){
this.type=type;
this.l=l;
this.r=r;
this.index=index;
}
}
class TaskC {
static long mod=1000000007;
/* static int prime_len=1000010;
static int prime[]=new int[prime_len];
static long n_prime[]=new long[prime_len];
static ArrayList<Integer> primes=new ArrayList<>();
static{
for(int i=2;i<=Math.sqrt(prime.length);i++){
for(int j=i*i;j<prime.length;j+=i){
prime[j]=i;
}
}
for(int i=2;i<prime.length;i++){
n_prime[i]=n_prime[i-1];
if(prime[i]==0){
n_prime[i]++;
}
}
// System.out.println("end");
// prime[0]=true;
// prime[1]=1;
}
/*
* long pp[]=new long[10000001];
pp[0]=0;
pp[1]=1;
for(int i=2;i<pp.length;i++){
if(prime[i]!=0){
int gcd=(int)greatestCommonDivisor(i/prime[i], prime[i]);
pp[i]=(pp[i/prime[i]]*pp[prime[i]]*gcd)/pp[(int)gcd];
}
else
pp[i]=i-1;
}
}
* */
class TrieNode{
int value;
TrieNode children[];
public TrieNode(int value,TrieNode children[] ){
this.value=value;
this.children=children;
}
}
class Trie{
TrieNode root;
int count;
public Trie(TrieNode root,int count){
this.root=root;
this.count=count;
}
}
public void insert(Trie t,char key[]){
t.count++;
int length=key.length;
int level=0;
TrieNode current=t.root;
if(current==null){
t.root=new TrieNode(0, new TrieNode[26]);
current=t.root;
}
for(level=0;level<length;level++){
int index=key[level]-'a';
if(current.children[index]==null){
current.children[index]=new TrieNode(0,new TrieNode[26]);
}
current=current.children[index];
}
current.value=t.count;
}
public int search(Trie t,char key[]){
TrieNode current=t.root;
if(current==null){
return 0;
}
int length=key.length;
int level=0;
for(level=0;level<length;level++){
int index=key[level]-'a';
if(current.children[index]==null){
return 0;
}
current=current.children[index];
}
return current.value;
}
class point{
int x;
int y;
}
int orientation(point p, point q, point r)
{
int val = (q.y - p.y) * (r.x - q.x) -
(q.x - p.x) * (r.y - q.y);
if (val == 0) return 0; // colinear
return (val > 0)? 1: 2; // clock or counterclock wise
}
//int arr[]=new int[1000000000];
public void solve(int testNumber, FastScanner in, PrintWriter out) throws IOException {
int n=in.nextInt();
long current=2;
for(int i=1;i<=n;i++){
long x=(long)(i)*(long)(i+1);
long y=x*x;
if(i!=1)
out.println(((long)i*(long)(i+1)*(long)(i+1)-(i-1)));
else
out.println(2);
current=x;
}
}
public long[] fun(long n,int k,int a){
long arr[]=new long[k];
for(int i=0;i<k;i++){
arr[(int)(pow(i, a, k)%k)]+=((n/k)%mod+ ((i!=0 && i<=n%k)? 1: 0))%mod;
}
return arr;
}
public long getAns(int d[],int n){
if(d[0]<0 && d[n-1]>0){
return Math.min(-2*d[0]+d[n-1], 2*d[n-1]-d[0]);
}
else{
if(d[0]<0){
return d[0]*-1;
}
else{
return(d[n-1]*1);
}
}
// return 0;
}
public boolean isTriangle(int x,int y,int z){
if(x+y>z && x+z>y && y+z>x){
return true;
}
return false;
}
public long optimize(long x){
long y=x;
if(x%10<5){
x=x-x%10;
}
else{
x=x+(10-x%10);
}
return y-x;
}
public static long[][] matrixexpo(long m[][],String n,long mod){
if(n.equals("1")){
return m.clone();
}
if(n.equals("10")){
return mulmatrix(m, m , mod);
}
else{
long temp [][]=matrixexpo(m,n.substring(0,n.length()-1),mod);
temp=mulmatrix(temp, temp, mod);
if(n.charAt(n.length()-1)=='0')return temp;
else return mulmatrix(temp, m,mod);
}
}
public static long[] mul(long[] a, long[] b)
{
int n = Math.max(a.length, b.length);
int h = Integer.highestOneBit(n);
if(n > h)h *= 2;
if(a.length < h)a = Arrays.copyOf(a, h);
if(b.length < h)b = Arrays.copyOf(b, h);
return mul2(a, b, 0, h, 0, h);
}
public static long[] mul2(long[] a, long[] b, int al, int ar, int bl, int br)
{
int n = ar-al;
if((n&n-1) != 0)throw new RuntimeException();
if(n <= 1<<6){
long[] res = muln(a, b, al, ar, bl, br);
return res;
}
long[] c0 = mul2(a, b, al+0, al+n/2, bl+0, bl+n/2);
long[] c2 = mul2(a, b, al+n/2, al+n, bl+n/2, bl+n);
long[] ab0 = new long[n/2];
long[] ab1 = new long[n/2];
for(int i = 0;i < n/2;i++){
ab0[i] = a[al+i] + a[al+i+n/2];
ab1[i] = b[bl+i] + b[bl+i+n/2];
if(ab0[i] >= mod)ab0[i] -= mod;
if(ab1[i] >= mod)ab1[i] -= mod;
}
int e = n+c2.length;
long[] ret = new long[e];
for(int i = 0;i < c0.length;i++){
ret[i] += c0[i];
if(ret[i] >= mod)ret[i] -= mod;
}
for(int i = 0;i < c2.length;i++){
ret[i+n] += c2[i];
if(ret[i+n] >= mod)ret[i+n] -= mod;
}
long[] c1 = mul2(ab0, ab1, 0, n/2, 0, n/2);
for(int i = 0;i < c1.length;i++){
c1[i] -= c0[i] + c2[i];
if(c1[i] < 0)c1[i] += mod;
if(c1[i] < 0)c1[i] += mod;
}
for(int i = 0;i < c1.length;i++){
ret[i+n/2] += c1[i];
if(ret[i+n/2] >= mod)ret[i+n/2] -= mod;
}
return ret;
}
public static long[] muln(long[] a, long[] b, int al, int ar, int bl, int br)
{
int n = ar - al;
long[] ret = new long[2*n];
for(int i = 0;i < 2*n;i++){
long tot = 0;
for(int j = Math.max(i-n+1, 0);j <= i && j < n;j++){
tot += a[al+j] * b[bl+i-j];
}
ret[i] = tot % mod;
}
return ret;
}
public static long[][] mulmatrix(long m1[][],long m2[][],long mod){
long ans[][]=new long[m1.length][m2[0].length];
for(int i=0;i<m1.length;i++){
for(int j=0;j<m2[0].length;j++){
for(int k=0;k<m1.length;k++){
ans[i][j]+=(m1[i][k]*m2[k][j]);
ans[i][j]%=mod;
}
}
}
return ans;
}
long pow(long x,long y,long mod){
if(y<=0){
return 1;
}
if(y==1){
return x%mod;
}
long temp=pow(x,y/2,mod);
if(y%2==0){
return (temp*temp)%mod;
}
else{
return (((temp*temp)%mod)*x)%mod;
}
}
static long greatestCommonDivisor (long m, long n){
long x;
long y;
while(m%n != 0){
x = n;
y = m%n;
m = x;
n = y;
}
return n;
}
static void dfs(List<Integer>[] graph, boolean[] used, List<Integer> res, int u,int parent,List<Integer> collection) {
used[u] = true;
Integer uu=new Integer(u);
collection.add(uu);
for (int v : graph[u]){
if (!used[v]){
dfs(graph, used, res, v,u,collection);
}
else if(collection.contains(v)){
System.out.println("Impossible");
System.exit(0);
}
}
collection.remove(uu);
res.add(u);
}
public static List<Integer> topologicalSort(List<Integer>[] graph) {
int n = graph.length;
boolean[] used = new boolean[n];
List<Integer> res = new ArrayList<>();
for (int i = 0; i < n; i++)
if (!used[i])
dfs(graph, used, res, i,-1,new ArrayList<Integer>());
Collections.reverse(res);
return res;
}
}
class LcaSparseTable {
int len;
int[][] up;
int[][] max;
int[] tin;
int[] tout;
int time;
int []lvel;
void dfs(List<Integer>[] tree, int u, int p) {
tin[u] = time++;
lvel[u]=lvel[p]+1;
up[0][u] = p;
if(u!=p)
//max[0][u]=weight(u,p);
for (int i = 1; i < len; i++)
{
up[i][u] = up[i - 1][up[i - 1][u]];
max[i][u]=Math.max(max[i-1][u],max[i-1][up[i-1][u]]);
}
for (int v : tree[u])
if (v != p)
dfs(tree, v, u);
tout[u] = time++;
}
public LcaSparseTable(List<Integer>[] tree, int root) {
int n = tree.length;
len = 1;
while ((1 << len) <= n) ++len;
up = new int[len][n];
max=new int[len][n];
tin = new int[n];
tout = new int[n];
lvel=new int[n];
lvel[root]=0;
dfs(tree, root, root);
}
boolean isParent(int parent, int child) {
return tin[parent] <= tin[child] && tout[child] <= tout[parent];
}
public int lca(int a, int b) {
if (isParent(a, b))
return a;
if (isParent(b, a))
return b;
for (int i = len - 1; i >= 0; i--)
if (!isParent(up[i][a], b))
a = up[i][a];
return up[0][a];
}
public long max(int a,int b){
int lca=lca(a,b);
// System.out.println("LCA "+lca);
long ans=0;
int h=lvel[a]-lvel[lca];
// System.out.println("Height "+h);
int index=0;
while(h!=0){
if(h%2==1){
ans=Math.max(ans,max[index][a]);
a=up[index][a];
}
h/=2;
index++;
}
h=lvel[b]-lvel[lca];
// System.out.println("Height "+h);
index=0;
while(h!=0){
if(h%2==1){
ans=Math.max(ans,max[index][b]);
b=up[index][b];
}
h/=2;
index++;
}
return ans;
}
static void dfs1(List<Integer>[] graph, boolean[] used, List<Integer> res, int u) {
used[u] = true;
for (int v : graph[u])
if (!used[v])
dfs1(graph, used, res, v);
res.add(u);
}
int phi(int n) {
int res = n;
for (int i = 2; i * i <= n; ++i) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
}
res -= res / i;
}
}
if (n != 1) {
res -= res / n;
}
return res;
}
public static long[][] mulmatrix(long m1[][],long m2[][],long mod){
long ans[][]=new long[m1.length][m2[0].length];
for(int i=0;i<m1.length;i++){
for(int j=0;j<m2[0].length;j++){
for(int k=0;k<m1.length;k++){
ans[i][j]+=(m1[i][k]*m2[k][j]);
ans[i][j]%=mod;
}
}
}
return ans;
}
public static long[][] matrixexpo(long m[][],String n,long mod){
if(n.equals("1")){
return m.clone();
}
if(n.equals("10")){
return mulmatrix(m, m , mod);
}
else{
long temp [][]=matrixexpo(m,n.substring(0,n.length()-1),mod);
temp=mulmatrix(temp, temp, mod);
if(n.charAt(n.length()-1)=='0')return temp;
else return mulmatrix(temp, m,mod);
}
}
public static boolean isCompatible(long x[],long y[]){
for(int i=0;i<x.length-1;i++){
if(x[i]==y[i] && x[i+1]==y[i+1] && x[i]==x[i+1] && y[i]==y[i+1]){
return false;
}
}
return true;
}
long pow(long x,long y,long mod){
if(y<=0){
return 1;
}
if(y==1){
return x%mod;
}
long temp=pow(x,y/2,mod);
if(y%2==0){
return (temp*temp)%mod;
}
else{
return (((temp*temp)%mod)*x)%mod;
}
}
long no_of_primes(long m,long n,long k){
long count=0,i,j;
int primes []=new int[(int)(n-m+2)];
if(m==1) primes[0] = 1;
for(i=2; i<=Math.sqrt(n); i++)
{
j = (m/i); j *= i;
if(j<m)
j+=i;
for(; j<=n; j+=i)
{
if(j!=i)
primes[(int)(j-m)] = 1;
}
}
for(i=0; i<=n-m; i++)
if(primes[(int)i]==0 && (i-1)%k==0)
count++;
return count;
}
}
class SegTree {
int n;
static long constt=Long.parseLong("111111111111111111111111111111",2);
long t[];
long mod=(long)(1000000007);
SegTree(int n,long t[]){
this.n=n;
this.t=t;
build();
}
void build() { // build the tree
for (int i = n - 1; i >= 0; --i){
t[i]=(t[i<<1]&t[i<<1|1]);
}
}
void modify(int p, long value) { // set value at position p
for (t[p += n]=value; p > 1; p >>= 1) t[p>>1] = (t[p]&t[p^1]);
// System.out.println(Arrays.toString(t));
}
long query(int l, int r) { // sum on interval [l, r)
long res=constt;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if ((l&1)!=0) res=res&t[l++];
if ((r&1)!=0) res=res&t[--r];
}
return res;
}
//
//
//
}
class FastScanner
{
private InputStream stream;
private byte[] buf = new byte[8192];
private int curChar;
private int snumChars;
private SpaceCharFilter filter;
public FastScanner(InputStream stream) {
this.stream = stream;
}
public int snext() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = snext();
while (isSpaceChar(c))
c = snext();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = snext();
while (isSpaceChar(c))
c = snext();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = snext();
while (isSpaceChar(c))
c = snext();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} 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 interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class UF {
private int[] parent; // parent[i] = parent of i
private byte[] rank; // rank[i] = rank of subtree rooted at i (never more than 31)
private int count; // number of components
public UF(int N) {
if (N < 0) throw new IllegalArgumentException();
count = N;
parent = new int[N];
rank = new byte[N];
for (int i = 0; i < N; i++) {
parent[i] = i;
rank[i] = 0;
}
}
public int find(int p) {
if (p < 0 || p >= parent.length) throw new IndexOutOfBoundsException();
while (p != parent[p]) {
parent[p] = parent[parent[p]]; // path compression by halving
p = parent[p];
}
return p;
}
public int count() {
return count;
}
public boolean connected(int p, int q) {
return find(p) == find(q);
}
public boolean union(int p, int q) {
int rootP = find(p);
int rootQ = find(q);
if (rootP == rootQ) return false;
// make root of smaller rank point to root of larger rank
if (rank[rootP] < rank[rootQ]) parent[rootP] = rootQ;
else if (rank[rootP] > rank[rootQ]) parent[rootQ] = rootP;
else {
parent[rootQ] = rootP;
rank[rootP]++;
}
count--;
return true;
}
}
class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
2b821714f2c1880769308c6f553531ab
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class CF715A {
public static void main(String []args) {
MyScanner in = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
//Start your solution from here.
int n = in.nextInt();
out.println("2");
for (long i = 3; i <= n+1; i++)
out.println((i*i-1)*(i-1) + 1);
//End your solution here.
out.close();
}
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
char nextChar() {
return next().charAt(0);
}
int [] nextIntAr(int [] ar){
for(int i=0;i<ar.length;++i){
ar[i] = Integer.parseInt(next());
}
return ar;
}
long [] nextLongAr(long [] ar){
for(int i=0;i<ar.length;++i){
ar[i] = Long.parseLong(next());
}
return ar;
}
double [] nextDoubleAr(double [] ar){
for(int i=0;i<ar.length;++i){
ar[i] = Double.parseDouble(next());
}
return ar;
}
String [] nextStringAr(String [] ar){
for(int i=0;i<ar.length;++i){
ar[i] = next();
}
return ar;
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
32a5c8104f5b9538a5e2e5bc6c56c3aa
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.util.*;
import java.io.*;
import java.math.*;
public class CF_A {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static void newST() throws IOException {st = new StringTokenizer(in.readLine());}
static int stInt() {return Integer.parseInt(st.nextToken());}
static long stLong() {return Long.parseLong(st.nextToken());}
static String stStr() {return st.nextToken();}
static int[] getInts(int n) throws IOException {newST(); int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = stInt(); return arr;}
static int readInt() throws IOException {return Integer.parseInt(in.readLine());}
static long readLong() throws IOException {return Long.parseLong(in.readLine());}
static void println(Object o) {System.out.println(o);}
static void println() {System.out.println();}
static void print(Object o) {System.out.print(o);}
static void printarr(int[] a) {StringBuilder sb = new StringBuilder(); for (int i = 0; i < a.length; i++)sb.append(a[i] + (i == a.length-1 ? "\n":" "));print(sb);}
public static void main(String[] args) throws Exception {
int n = readInt();
StringBuilder sb = new StringBuilder();
BigInteger s = new BigInteger("2");
for (int i = 1; i <= n; i++) {
BigInteger ds = (new BigInteger(Integer.toString(i))).multiply(new BigInteger(Integer.toString(i+1)));
BigInteger ds2 = ds.multiply(ds);
sb.append(ds2.subtract(s).divide(new BigInteger(Integer.toString(i)))+"\n");
s = ds;
}
print(sb);
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
a34dff9cd5cd4ba8e1609dc4e039b89f
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.util.*;
public class PlusAndSquareRoot{
public static void main (String[] args) {
Scanner kbd = new Scanner (System.in);
long x = kbd.nextLong();
for(long i = 1; i <= x; i++){
if(i == 1){
System.out.println("2");
}else{
System.out.println((i+1)*(i+1)*i-(i-1));
}
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
1f89d9f611f036207a0bc1c03ff92540
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.*;
import java.math.*;
import java.util.*;
public class A {
private Scanner in = new Scanner(System.in);
private PrintWriter out = new PrintWriter(System.out);
long f(int k) {
long res = 1;
for (int i = 2; i * i <= k; ++i) {
int i2 = i * i;
while (k % i2 == 0) {
res *= i;
k /= i2;
}
if (k % i == 0) {
k /= i;
res *= i;
}
}
res *= k;
return res;
}
public static void main(String[] args) {
new A().run();
}
private static BigInteger sqrt(BigInteger x) {
BigInteger left = BigInteger.ONE;
BigInteger right = x;
while (left.add(BigInteger.ONE).compareTo(right) < 0) {
BigInteger m = left.add(right).divide(BigInteger.valueOf(2));
if (m.multiply(m).compareTo(x) <= 0) {
left = m;
} else {
right = m;
}
}
return left;
}
void run() {
int n = in.nextInt();
BigInteger x = BigInteger.valueOf(2);
for (int k = 1; k <= n; ++k) {
// System.err.println(k);
BigInteger y = sqrt(x);
BigInteger z = BigInteger.valueOf(f(k) * (k + 1));
if (!y.mod(z).equals(BigInteger.ZERO)) {
y = y.add(z.subtract(y.mod(z)));
}
// dbg("k %d x %lld y %lld\n", k, x, y);
// assert(y * y >= x);
// assert((y * y - x) % k == 0);
BigInteger A = y.multiply(y).subtract(x).divide(BigInteger.valueOf(k));
out.println(A);
// out.flush();
x = y;
//assert(x % (k + 1) == 0);
}
out.flush();
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
5effa162d4c412f46ff2a125bb6bc5f8
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
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
*/
public class Main {
public static void main(String[] args) throws Exception {
Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
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);
APlusAndSquareRoot solver = new APlusAndSquareRoot();
solver.solve(1, in, out);
out.close();
}
}
static class APlusAndSquareRoot {
public void solve(int testNumber, FastInput in, FastOutput out) {
int n = in.readInt();
long[] ans = new long[n + 1];
long x = 2;
for (int i = 1; i <= n; i++) {
long k = (long) i * (i + 1) * (i + 1) - x;
ans[i] = k;
out.println(k);
x = i;
}
//check(n, ans);
//check(n, new long[]{0, 14, 16, 46});
}
}
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) {
bufLen = -1;
}
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, Appendable {
private StringBuilder cache = new StringBuilder(10 << 20);
private final Writer os;
public FastOutput append(CharSequence csq) {
cache.append(csq);
return this;
}
public FastOutput append(CharSequence csq, int start, int end) {
cache.append(csq, start, end);
return this;
}
public FastOutput(Writer os) {
this.os = os;
}
public FastOutput(OutputStream os) {
this(new OutputStreamWriter(os));
}
public FastOutput append(char c) {
cache.append(c);
return this;
}
public FastOutput append(long c) {
cache.append(c);
return this;
}
public FastOutput println(long c) {
return append(c).println();
}
public FastOutput println() {
cache.append(System.lineSeparator());
return this;
}
public FastOutput flush() {
try {
os.append(cache);
os.flush();
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);
}
}
public String toString() {
return cache.toString();
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
9c1ed2c02df09ed90364e42a6f05ce31
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.math.*;
public class A implements Runnable {
public void run() {
long startTime = System.nanoTime();
int n = nextInt();
for (int i = 1; i <= n; i++) {
println(i == 1 ? 2 : 1L * i * (i + 1) * (i + 1) - (i - 1));
}
if (fileIOMode) {
System.out.println((System.nanoTime() - startTime) / 1e9);
}
out.close();
}
//-----------------------------------------------------------------------------------
private static boolean fileIOMode;
private static BufferedReader in;
private static PrintWriter out;
private static StringTokenizer tokenizer;
public static void main(String[] args) throws Exception {
fileIOMode = args.length > 0 && args[0].equals("!");
if (fileIOMode) {
in = new BufferedReader(new FileReader("a.in"));
out = new PrintWriter("a.out");
} else {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
tokenizer = new StringTokenizer("");
new Thread(new A()).start();
}
private static String nextLine() {
try {
return in.readLine();
} catch (IOException e) {
return null;
}
}
private static String nextToken() {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(nextLine());
}
return tokenizer.nextToken();
}
private static int nextInt() {
return Integer.parseInt(nextToken());
}
private static long nextLong() {
return Long.parseLong(nextToken());
}
private static double nextDouble() {
return Double.parseDouble(nextToken());
}
private static BigInteger nextBigInteger() {
return new BigInteger(nextToken());
}
private static void print(Object o) {
if (fileIOMode) {
System.out.print(o);
}
out.print(o);
}
private static void println(Object o) {
if (fileIOMode) {
System.out.println(o);
}
out.println(o);
}
private static void printf(String s, Object... o) {
if (fileIOMode) {
System.out.printf(s, o);
}
out.printf(s, o);
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
68691fe69ff4c3ec7f4f0c71dc55e12b
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main {
FastScanner in;
PrintWriter out;
static final String FILE = "";
void solve() {
int n = in.nextInt();
long cur = 2;
for (long k = 1; k < n + 1; k++) {
out.println(k * (k + 1) * (k + 1) - cur / k);
cur = k * k + k;
}
}
public void run() {
if (FILE.equals("")) {
in = new FastScanner(System.in);
out = new PrintWriter(System.out);
} else {
try {
in = new FastScanner(new FileInputStream(FILE +
".in"));
out = new PrintWriter(new FileOutputStream(FILE +
".out"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
solve();
out.close();
}
public static void main(String[] args) {
(new Main()).run();
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public String nextLine() {
st = null;
try {
return br.readLine();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public float nextFloat() {
return Float.parseFloat(next());
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
9883670f4504cbb5656bf3032e4e9a95
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.math.BigInteger;
public class C {
public static void main(String[] args) {
FS r = new FS();
// write reader
int n = r.nextInt();
solver(n);
}
public static void solver(int n) {
BigInteger answer = new BigInteger(String.valueOf(0));
BigInteger num = new BigInteger(String.valueOf(2));
for(int i=0; i<n; i++) {
answer = new BigInteger(String.valueOf(i+1));
answer = answer.multiply(new BigInteger(String.valueOf(i+1)));
answer = answer.multiply(new BigInteger(String.valueOf(i+2)));
answer = answer.multiply(new BigInteger(String.valueOf(i+2)));
answer = answer.subtract(num);
answer = answer.divide(new BigInteger(String.valueOf(i+1)));
num = new BigInteger(String.valueOf(i+1));
num = num.multiply(new BigInteger(String.valueOf(i+2)));
System.out.println(answer);
}
}
// Read Class
static class FS {
private final InputStream in = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
} else {
ptr = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
public boolean hasNext() { skipUnprintable(); return hasNextByte();}
public String next() {
if (!hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while(isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
return (int)nextLong();
}
public long nextLong() {
if (!hasNext()) throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while(true) {
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
} else if(b == -1 || !isPrintableChar(b)) {
return minus ? -n : n;
} else {
throw new NumberFormatException();
}
b = readByte();
}
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
c79022027095d8d778e5a790deb9d54c
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.util.Scanner;
public class Problem_715A
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
long n = input.nextInt();
for(long i = 1; i < n + 1; i++)
{
if(i == 1)
{
System.out.println(2);
}
else
{
System.out.println(i * (i + 1) * (i + 1) - (i - 1));
}
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
cda0890c64bea924adc60742fdd69bff
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.math.*;
public class A {
public static void main(String[] args) throws IOException {
/**/
Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
/*/
Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream("src/a.in"))));
/**/
int n = sc.nextInt();
StringBuilder ans = new StringBuilder();
ans.append("2\n");
for (long i = 2; i <= n; i++) {
ans.append((i*i*i+2*i*i+1)+"\n");
}
System.out.print(ans);
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
706030854fbfa1075b2633c4c6baa664
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Solution {
static MyScanner sc;
private static PrintWriter out;
static long M2 = 1_000_000_000L + 7;
public static void main(String[] s) throws Exception {
StringBuilder stringBuilder = new StringBuilder();
// stringBuilder.append("100000 1000000000 10001 100000 ");
// for (int i = 1; i < 100000; i++) {
// stringBuilder.append(" 10000 100000 ");
// }
if (stringBuilder.length() == 0) {
sc = new MyScanner(System.in);
} else {
sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString())));
}
out = new PrintWriter(new OutputStreamWriter(System.out));
initData();
solve();
out.flush();
}
private static void initData() {
}
private static void solve() throws IOException {
int n = sc.nextInt();
long cur = 2;
for (long i = 1; i <= n; i++) {
long t1 = i * i;
long m1 = (i + 1) * (i + 1);
// out.println("cur " + cur);
// out.println("level " + i);
// out.println("tar " + BigInteger.valueOf(t1)
// .multiply(BigInteger.valueOf(m1)));
BigInteger ans = BigInteger.valueOf(t1)
.multiply(BigInteger.valueOf(m1))
.subtract(BigInteger.valueOf(cur))
.divide(BigInteger.valueOf(i));
out.println(ans);
cur = i * (i + 1);
}
}
private static void solveT() throws IOException {
int t = sc.nextInt();
while (t-- > 0) {
solve();
}
}
private static long gcd(long l, long l1) {
if (l > l1) return gcd(l1, l);
if (l == 0) return l1;
return gcd(l1 % l, l);
}
private static long pow(long a, long b, long m) {
if (b == 0) return 1;
if (b == 1) return a;
long pp = pow(a, b / 2, m);
pp *= pp;
pp %= m;
return (pp * (b % 2 == 0 ? 1 : a)) % m;
}
static class MyScanner {
BufferedReader br;
StringTokenizer st;
MyScanner(BufferedReader br) {
this.br = br;
}
public MyScanner(InputStream in) {
this(new BufferedReader(new InputStreamReader(in)));
}
void findToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
String next() {
findToken();
return st.nextToken();
}
Integer[] nab(int n) {
Integer[] k = new Integer[n];
for (int i = 0; i < n; i++) {
k[i] = sc.fi();
}
return k;
}
int[] na(int n) {
int[] k = new int[n];
for (int i = 0; i < n; i++) {
k[i] = sc.fi();
}
return k;
}
long[] nl(int n) {
long[] k = new long[n];
for (int i = 0; i < n; i++) {
k[i] = sc.nextLong();
}
return k;
}
int nextInt() {
return Integer.parseInt(next());
}
int fi() {
String t = next();
int cur = 0;
boolean n = t.charAt(0) == '-';
for (int a = n ? 1 : 0; a < t.length(); a++) {
cur = cur * 10 + t.charAt(a) - '0';
}
return n ? -cur : cur;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
37a942d0769b9de264f532b2ccf2f530
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int n;
n = new Scanner(System.in).nextInt();
BigInteger num = new BigInteger("2");
BigInteger diff = new BigInteger("1");
BigInteger it = new BigInteger("1");
BigInteger itN = new BigInteger("2");
BigInteger temp = new BigInteger("1");
Integer q = 1;
int h = 0, z = 2, k = 0;
while (n > 0) {
temp = new BigInteger("1");
temp = temp.multiply(it);
temp = temp.multiply(it);
temp = temp.multiply(itN);
temp = temp.multiply(itN);
diff = temp.subtract(num);
diff = diff.divide(new BigInteger(q.toString()));
q++;
num = new BigInteger(temp.toString());
num = num.divide(it);
num = num.divide(itN);
it = new BigInteger(q.toString());
q++;
itN = new BigInteger(q.toString());
q--;
n--;
// System.out.println(diff + " " + num);
System.out.println(diff);
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
0648adc7c778ca4be33a9b8abe0a7ada
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.math.BigInteger;
import java.util.Scanner;
public class EUQWxC {
public static void main(String [] args){
Scanner scan=new Scanner(System.in);
long input=scan.nextLong();
BigInteger screen=new BigInteger ("2");
BigInteger level=new BigInteger ("1");
BigInteger target=new BigInteger("1");
BigInteger one=new BigInteger("1");
BigInteger answer= new BigInteger("1");
for (int i=0;i<input;i++){
target= ((level.multiply(level.add(one))).multiply(level.add(one))).multiply(level);
answer = (target.subtract(screen)).divide(level);
System.out.println(answer);
screen=level.multiply(level.add(one));
level=level.add(one);
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
0fcd08732e517e66f53469bbc86ac7c5
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;import java.math.BigInteger;
import java.io.OutputStreamWriter;
/* Name of the class has to be "Main" only if the class is public. */
public class bbg
{
public static int result;
public static ArrayList<Integer> [] graph;
public static int[]cats;
public static int vizitat[];
public static int x;
//public static HashMap<String, Integer> map2;
public static void main (String[] args) throws IOException {
Scanner input = new Scanner(System.in);
HashMap<Integer, Integer> contor1= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> contor2= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> map= new HashMap<Integer, Integer>();
HashMap<String, Integer> curatare= new HashMap<String, Integer>();
HashMap<String, Integer> combinari= new HashMap<String, Integer>();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
BigInteger bi1, bi2, bi3,k;
bi1 = new BigInteger("1");
bi2 = new BigInteger("-123");
// assign difference of bi1 and bi2 to bi3
bi3 = bi1.subtract(bi2);
long n=input.nextLong();
BigInteger nr=new BigInteger("4");
BigInteger rez=new BigInteger("4");
BigInteger patrat=new BigInteger("1");
BigInteger level=new BigInteger("2");
BigInteger levelinter=new BigInteger("0");
// Long k=0l;
if(n==1l) {
System.out.println(14);
}
else {
System.out.println(14);
for(int i=2;i<=n;i++){
levelinter=level;
BigInteger unu=new BigInteger("1");
patrat=bi1;
patrat=patrat.multiply(level);
patrat=patrat.multiply(level);
//levelinter=levelinter.add(level);
levelinter=levelinter.add(unu);
patrat=patrat.multiply(levelinter);
patrat=patrat.multiply(levelinter);
// System.out.println("level="+level+" nr="+nr+" patrat="+patrat);
// k=new BigInteger("1");
k = patrat.subtract(nr);
// System.out.println("k="+k);
rez=k.divide(level);
nr=level.multiply(levelinter);
System.out.println(rez);
level=level.add(bi1);
}
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
9214a3b510baba0b21a8bee06d6a7660
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.util.*;
public class CF715A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println("2");
for (long i = 3; i <= n+1; i++)
System.out.println((i*i-1)*(i-1) + 1);
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
189e118b2b1e41960b8eec6234657a81
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
for (long i=1; i<=n; i++) {
if (i==1) System.out.println(2);
else System.out.println((i+1)*(i+1)*i-(i-1));
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
7b9f94f3e14048b5da3cb270616c680c
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner kbd = new Scanner(System.in);
long n = kbd.nextLong();
for (long i=1; i<=n; i++) {
if (i==1) {
System.out.println(2);
} else System.out.println((i+1)*(i+1)*i-(i-1));
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
2c2879be58eb2cba0b390ec60ad4ab77
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
for (long i=1; i<=n; i++) {
if (i==1) {
System.out.println(2);
} else System.out.println((i+1)*(i+1)*i-(i-1));
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
443b68adf54cd6e664374d189b63ca27
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
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);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.ni();
long prev = 2L;
long lev = 1L;
for (int i = 0; i < n; ++i) {
long x = (lev + 1L) * (lev + 1L) * lev - ((prev) / lev);
out.println(x);
prev = (lev + 1L) * lev;
lev = lev + 1L;
}
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int ni() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
b91d31ada33c21abf165ac98a04f9b51
|
train_001.jsonl
|
1474119900
|
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes xβ+βk. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes kβ+β1. This button can only be pressed when x is a perfect square, i.e. xβ=βm2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β he wants to reach level nβ+β1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the 'β+β' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level nβ+β1, but not necessarily a sequence minimizing the number of presses.
|
256 megabytes
|
// package Mathematical;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
public class PlusAndSquareRoot {
public static void main(String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
StringBuilder print=new StringBuilder();
BigInteger score=new BigInteger("2");
for(int i=1;i<=n;i++){
BigInteger reqd=BigInteger.valueOf(i).multiply(BigInteger.valueOf(i+1));
BigInteger square=reqd.multiply(reqd);
BigInteger add=square.subtract(score);
add=add.divide(BigInteger.valueOf(i));
print.append(add.toString()+"\n");
score=reqd;
}
System.out.println(print.toString());
}
}
|
Java
|
["3", "2", "4"]
|
2 seconds
|
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
|
NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the number becomes 4β+β16Β·2β=β36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the 'β+β' button 46 times, so the number becomes 6β+β46Β·3β=β144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the 'β+β' button 10 times on the third level before levelling up does not work, because the number becomes 6β+β10Β·3β=β36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the 'β+β' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2β+β999999999999999998Β·1β=β1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 44500000000 times, so the number becomes 109β+β44500000000Β·2β=β9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
|
Java 8
|
standard input
|
[
"constructive algorithms",
"math"
] |
6264405c66b2690ada9f8cc6cff55f0b
|
The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1.
| 1,600 |
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
|
standard output
| |
PASSED
|
582e0d8b5874a96634a06c106fc4279f
|
train_001.jsonl
|
1327215600
|
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has sequence a consisting of n integers.The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements.Two sequences are considered different if index sets of numbers included in them are different. That is, the values βof the elements βdo not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence).A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times).Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109β+β7).
|
256 megabytes
|
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Collection;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
/**
* 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);
TaskE solver = new TaskE();
solver.solve(1, in, out);
out.close();
}
}
class TaskE {
final int Mod = (int) (1e9 + 7);
int[] fact;
public void solve(int testNumber, InputReader in, PrintWriter out) {
int N = in.nextInt(), K = in.nextInt();
HashMap<Integer, Integer> count = new HashMap<>();
fact = new int[N + 1];
fact[0] = 1;
int cntp = 0;
for (int i = 1; i <= N; ++i) {
fact[i] = (int) (1L * fact[i - 1] * i % Mod);
int x = in.nextInt();
if (lucky(x)) {
if (!count.containsKey(x)) count.put(x, 1);
else count.put(x, count.get(x) + 1);
} else ++cntp;
}
int[] values = new int[count.size()];
int pos = 0;
for (int p: count.values())
values[pos++] = p;
N = values.length;
int ans = Comb(cntp, K);
int[] dp = new int[N + 1];
Arrays.fill(dp, 1);
for (int i = 1; i <= K; ++i) {
int[] ndp = new int[N + 1];
for (int j = i; j <= N; ++j)
ndp[j] = (int) ((1L * dp[j - 1] * values[j - 1] + ndp[j - 1]) % Mod);
dp = ndp;
ans = (int) ((ans + 1L * Comb(cntp, K - i) * dp[N]) % Mod);
}
out.println(ans);
}
private int Pow(int x, int y) {
int ret = 1;
for (; y > 0; y >>= 1) {
if ((y & 1) != 0) ret = (int) (1L * ret * x % Mod);
x = (int) (1L * x * x % Mod);
}
return ret;
}
private int invmod(int x) {
return Pow(x, Mod - 2);
}
private int Comb(int n, int k) {
if (k < 0 || k > n) return 0;
return (int) (1L * fact[n] * invmod((int) (1L * fact[k] * fact[n - k] % Mod)) % Mod);
}
private boolean lucky(int x) {
while (x > 0) {
if (x % 10 != 4 && x % 10 != 7) return false;
x /= 10;
}
return true;
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
return Integer.parseInt(next());
}
public String next() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuffer res = new StringBuffer();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
|
Java
|
["3 2\n10 10 10", "4 2\n4 4 7 7"]
|
2 seconds
|
["3", "4"]
|
NoteIn the first sample all 3 subsequences of the needed length are considered lucky.In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1,β3}, {1,β4}, {2,β3} and {2,β4}.
|
Java 8
|
standard input
|
[
"dp",
"combinatorics"
] |
c421f47149e70240a02903d9d47de429
|
The first line contains two integers n and k (1ββ€βkββ€βnββ€β105). The next line contains n integers ai (1ββ€βaiββ€β109) β the sequence a.
| 2,100 |
On the single line print the single number β the answer to the problem modulo prime number 1000000007 (109β+β7).
|
standard output
| |
PASSED
|
3d4ecc4eda5d9103a553202587217b25
|
train_001.jsonl
|
1327215600
|
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has sequence a consisting of n integers.The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements.Two sequences are considered different if index sets of numbers included in them are different. That is, the values βof the elements βdo not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence).A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times).Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109β+β7).
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.StringTokenizer;
public class Abood2D {
static int occ[];
static int[][] memo;
static final int MOD = (int) 1e9 + 7;
static int[] fac;
static int pow(int x, long p) {
if(p == 0)
return 1;
int ans = 1;
if(p % 2 == 1)
ans *= x;
int c = pow(x, p / 2);
ans = (int) ((1l * ((1l * ans * c) % MOD) * c) % MOD);
return ans;
}
static int solve(int i, int r) {
if(r == 0)
return 1;
if(i == occ.length)
return 0;
if(memo[i][r] != -1)
return memo[i][r];
int ans = (int) ((1l * occ[i] * solve(i + 1, r - 1) + 1l * solve(i + 1, r)) % MOD);
return memo[i][r] = ans;
}
static int nCk(int n, int k) {
return (int) (((1l * fac[n] * pow(fac[k], MOD - 2)) % MOD) * pow(fac[n - k], MOD - 2) % MOD);
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
fac = new int[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = (int) ((1l * i * fac[i - 1]) % MOD);
int k = sc.nextInt();
HashMap<Integer, Integer> map = new HashMap<>();
int unL = 0;
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
boolean l = true;
String s = x + "";
for (int j = 0; j < s.length(); j++)
if(s.charAt(j) != '4' && s.charAt(j) != '7')
l = false;
if(l) {
if(!map.containsKey(x))
map.put(x, 0);
map.put(x, map.get(x) + 1);
}else
unL++;
}
int L = map.size();
occ = new int[L];
int i = 0;
for (Entry<Integer, Integer> x : map.entrySet())
occ[i++] = x.getValue();
int ans = 0;
memo = new int[L + 1][L + 1];
for(int[] a : memo)
Arrays.fill(a, -1);
for (int j = 0; j <= Math.min(k, unL); j++) {
if(k - j > L)
continue;
ans = (int) ((1l * ans + (1l * nCk(unL, j) * solve(0, k - j)) % MOD) % MOD);
}
out.println(ans);
out.flush();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public double nextDouble() throws IOException
{
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if(x.charAt(0) == '-')
{
neg = true;
start++;
}
for(int i = start; i < x.length(); i++)
if(x.charAt(i) == '.')
{
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
}
else
{
sb.append(x.charAt(i));
if(dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg?-1:1);
}
public boolean ready() throws IOException {return br.ready();}
}
}
|
Java
|
["3 2\n10 10 10", "4 2\n4 4 7 7"]
|
2 seconds
|
["3", "4"]
|
NoteIn the first sample all 3 subsequences of the needed length are considered lucky.In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1,β3}, {1,β4}, {2,β3} and {2,β4}.
|
Java 8
|
standard input
|
[
"dp",
"combinatorics"
] |
c421f47149e70240a02903d9d47de429
|
The first line contains two integers n and k (1ββ€βkββ€βnββ€β105). The next line contains n integers ai (1ββ€βaiββ€β109) β the sequence a.
| 2,100 |
On the single line print the single number β the answer to the problem modulo prime number 1000000007 (109β+β7).
|
standard output
| |
PASSED
|
da49b7884b7e34d093068fd9324edb5c
|
train_001.jsonl
|
1327215600
|
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has sequence a consisting of n integers.The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements.Two sequences are considered different if index sets of numbers included in them are different. That is, the values βof the elements βdo not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence).A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times).Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109β+β7).
|
256 megabytes
|
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Map.Entry;
public class E {
static int[] a;
static int[] sh;
static int n, k;
static int mod = 1000000007;
static int[] freq;
static int cnt;
static long[][] dp;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
n = in.nextInt();
k = in.nextInt();
sh = new int[n];
a = new int[n];
for (int i = 0; i < a.length; i++)
a[i] = in.nextInt();
cnt = 0;
HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
int p = 0;
for (int i = 0; i < a.length; i++) {
if (isLucky(a[i])) {
if (hm.containsKey(a[i]))
hm.put(a[i], hm.get(a[i]) + 1);
else {
hm.put(a[i], 1);
p++;
}
} else
cnt++;
}
freq = new int[hm.size()];
int t = 0;
for (Entry<Integer, Integer> e : hm.entrySet())
freq[t++] = e.getValue();
dp = new long[freq.length + 10][freq.length + 10];
for (int i = 0; i < dp.length; i++)
Arrays.fill(dp[i], -1);
if (cnt + p < k)
System.out.println(0);
else {
init();
long res = solve(0, 0);
System.out.println(res % mod);
}
}
public static long solve(int at, int used) {
if (used > k)
return 0;
if (at == freq.length) {
if (used == k)
return 1;
if (cnt < k - used)
return 0;
return nCr(cnt, k - used);
}
if (dp[at][used] != -1)
return dp[at][used];
long res = 0;
res += freq[at] * solve(at + 1, used + 1);
res += solve(at + 1, used);
res %= mod;
return dp[at][used] = res;
}
static long[] fact = new long[100002];
static long[] factInv = new long[100002];
public static void init() {
fact[0] = 1;
for (int i = 1; i < fact.length; i++)
fact[i] = (fact[i - 1] * (long) i) % mod;
factInv[0] = 1;
for (int i = 1; i < fact.length; i++)
factInv[i] = BigInteger
.valueOf(fact[i])
.modPow(BigInteger.valueOf(mod - 2),
BigInteger.valueOf(mod)).longValue();
}
public static long nCr(int n, int r) {
long res = fact[n] * factInv[r];
res %= mod;
res *= factInv[n - r];
return res % mod;
}
public static boolean isLucky(int a) {
int t;
while (a != 0) {
t = a % 10;
if (t != 4 && t != 7)
return false;
a /= 10;
}
return true;
}
}
|
Java
|
["3 2\n10 10 10", "4 2\n4 4 7 7"]
|
2 seconds
|
["3", "4"]
|
NoteIn the first sample all 3 subsequences of the needed length are considered lucky.In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1,β3}, {1,β4}, {2,β3} and {2,β4}.
|
Java 6
|
standard input
|
[
"dp",
"combinatorics"
] |
c421f47149e70240a02903d9d47de429
|
The first line contains two integers n and k (1ββ€βkββ€βnββ€β105). The next line contains n integers ai (1ββ€βaiββ€β109) β the sequence a.
| 2,100 |
On the single line print the single number β the answer to the problem modulo prime number 1000000007 (109β+β7).
|
standard output
| |
PASSED
|
1f44138e33f0960da315b27b3b24de30
|
train_001.jsonl
|
1327215600
|
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has sequence a consisting of n integers.The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements.Two sequences are considered different if index sets of numbers included in them are different. That is, the values βof the elements βdo not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence).A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times).Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109β+β7).
|
256 megabytes
|
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Map.Entry;
public class E {
static int[] a;
static int[] sh;
static int n, k;
static int mod = 1000000007;
static int[] freq;
static int cnt;
static long[][] dp;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
n = in.nextInt();
k = in.nextInt();
sh = new int[n];
a = new int[n];
for (int i = 0; i < a.length; i++)
a[i] = in.nextInt();
cnt = 0;
HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
int p = 0;
for (int i = 0; i < a.length; i++) {
if (isLucky(a[i])) {
if (hm.containsKey(a[i]))
hm.put(a[i], hm.get(a[i]) + 1);
else {
hm.put(a[i], 1);
p++;
}
} else
cnt++;
}
freq = new int[hm.size()];
int t = 0;
for (Entry<Integer, Integer> e : hm.entrySet())
freq[t++] = e.getValue();
dp = new long[freq.length + 10][freq.length + 10];
for (int i = 0; i < dp.length; i++)
Arrays.fill(dp[i], -1);
if (cnt + p < k)
System.out.println(0);
else {
init();
long res = solve(0, 0);
System.out.println(res % mod);
}
}
public static long solve(int at, int used) {
if (used > k)
return 0;
if (at == freq.length) {
if (used == k)
return 1;
if (cnt < k - used)
return 0;
return nCr(cnt, k - used);
}
if (dp[at][used] != -1)
return dp[at][used];
long res = 0;
res += freq[at] * solve(at + 1, used + 1);
res += solve(at + 1, used);
res %= mod;
return dp[at][used] = res;
}
static long[] fact = new long[100002];
static long[] factInv = new long[100002];
public static void init() {
fact[0] = 1;
for (int i = 1; i < fact.length; i++)
fact[i] = (fact[i - 1] * (long) i) % mod;
factInv[0] = 1;
for (int i = 1; i < fact.length; i++)
factInv[i] = BigInteger.valueOf(fact[i]).modInverse(
BigInteger.valueOf(mod)).longValue();
}
public static long nCr(int n, int r) {
long res = fact[n] * factInv[r];
res %= mod;
res *= factInv[n - r];
return res % mod;
}
public static boolean isLucky(int a) {
int t;
while (a != 0) {
t = a % 10;
if (t != 4 && t != 7)
return false;
a /= 10;
}
return true;
}
}
|
Java
|
["3 2\n10 10 10", "4 2\n4 4 7 7"]
|
2 seconds
|
["3", "4"]
|
NoteIn the first sample all 3 subsequences of the needed length are considered lucky.In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1,β3}, {1,β4}, {2,β3} and {2,β4}.
|
Java 6
|
standard input
|
[
"dp",
"combinatorics"
] |
c421f47149e70240a02903d9d47de429
|
The first line contains two integers n and k (1ββ€βkββ€βnββ€β105). The next line contains n integers ai (1ββ€βaiββ€β109) β the sequence a.
| 2,100 |
On the single line print the single number β the answer to the problem modulo prime number 1000000007 (109β+β7).
|
standard output
| |
PASSED
|
965756c4664b15bd04b337a22e69d6f8
|
train_001.jsonl
|
1327215600
|
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has sequence a consisting of n integers.The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements.Two sequences are considered different if index sets of numbers included in them are different. That is, the values βof the elements βdo not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence).A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times).Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109β+β7).
|
256 megabytes
|
import java.io.*;
import java.lang.Math;
import java.util.*;
import java.math.BigInteger;
public class Main
{
public BufferedReader in;
public PrintStream out;
public int index(int x)
{
int res = 0;
while (x>0)
{
res *= 3;
switch (x % 10)
{
case 4:
res += 1;
break;
case 7:
res += 2;
break;
default:
return 0;
}
x /= 10;
}
return res;
}
long mod = 1000000007;
public void test()
{
int n = readInt();
int k = readInt();
int[] a = readIntArray(n);
long[] cnt = new long[20000];
int i,j;
for (i=1; i<20000;i++)
{
cnt[i] = 0;
}
int good_count = 0;
int[] goods = new int[2000];
int good_total = 0;
for (i=0; i<n; i++)
{
j = index(a[i]);
if (j>0)
{
good_total++;
if (cnt[j]==0)
{
goods[++good_count] = j;
}
cnt[j]++;
}
}
long[][] res = new long[good_count+1][good_count+1];
res[0][0] = 1;
for (i=1; i<=good_count;i++)
{
res[0][i] = 0;
res[i][0] = 1;
}
for (i=1; i<=good_count;i++)
{
for (j=1;j<=good_count;j++)
{
res[i][j] = (res[i-1][j] + res[i-1][j-1]*cnt[goods[i]]) % mod;
}
}
n = n - good_total;
long[] cnk = new long[k+1];
cnk[0] = 1;
for (i=1; i<=k; i++)
{
if (i>n)
{
cnk[i] = 0;
}
else
{
cnk[i] = cnk[i-1]*((long)(n-i+1))% mod * BigInteger.valueOf(i).modInverse(BigInteger.valueOf(mod)).longValue() % mod;
}
}
long s = 0;
for (i=0; (i<=good_count)&&(i<=k); i++)
{
/* out.print(">>>>>>>>> ");
out.println(i);
out.println(res[good_count][i]);
out.println(cnk[k-i]);*/
s += res[good_count][i]*cnk[k-i] % mod;
s %= mod;
}
out.println(s);
}
public void run()
{
try
{
in = new BufferedReader(new InputStreamReader(System.in));
out = System.out;
//in = new BufferedReader(new FileReader("in.txt"));
//out = new PrintStream(new File("out.txt"));
}
catch (Exception e)
{
return;
}
//while (true)
{
//int t = readInt(); for (int i=0; i<t; i++)
{
test();
}
}
}
public static void main(String args[])
{
new Main().run();
}
private StringTokenizer tokenizer = null;
public int readInt()
{
return Integer.parseInt(readToken());
}
public long readLong()
{
return Long.parseLong(readToken());
}
public double readDouble()
{
return Double.parseDouble(readToken());
}
public String readLn()
{
try
{
String s;
while ((s = in.readLine()).length()==0);
return s;
}
catch (Exception e)
{
return "";
}
}
public String readToken()
{
try
{
while (tokenizer == null || !tokenizer.hasMoreTokens())
{
tokenizer = new StringTokenizer(in.readLine());
}
return tokenizer.nextToken();
}
catch (Exception e)
{
return "";
}
}
public int[] readIntArray(int n)
{
int[] x = new int[n];
readIntArray(x, n);
return x;
}
public void readIntArray(int[] x, int n)
{
for (int i=0; i<n; i++)
{
x[i] = readInt();
}
}
}
|
Java
|
["3 2\n10 10 10", "4 2\n4 4 7 7"]
|
2 seconds
|
["3", "4"]
|
NoteIn the first sample all 3 subsequences of the needed length are considered lucky.In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1,β3}, {1,β4}, {2,β3} and {2,β4}.
|
Java 6
|
standard input
|
[
"dp",
"combinatorics"
] |
c421f47149e70240a02903d9d47de429
|
The first line contains two integers n and k (1ββ€βkββ€βnββ€β105). The next line contains n integers ai (1ββ€βaiββ€β109) β the sequence a.
| 2,100 |
On the single line print the single number β the answer to the problem modulo prime number 1000000007 (109β+β7).
|
standard output
| |
PASSED
|
8b8e1cf4801c314812eb5cec937b71d8
|
train_001.jsonl
|
1327215600
|
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has sequence a consisting of n integers.The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements.Two sequences are considered different if index sets of numbers included in them are different. That is, the values βof the elements βdo not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence).A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times).Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109β+β7).
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.*;
public class E
{
BufferedReader in;
PrintStream out;
StringTokenizer tok;
public E() throws NumberFormatException, IOException
{
in = new BufferedReader(new InputStreamReader(System.in));
//in = new BufferedReader(new FileReader("in.txt"));
out = System.out;
run();
}
long[] fact;
boolean islucky(int n)
{
while(n>0)
{
if(n%10 != 4 && n%10 != 7) return false;
n/=10;
}
return true;
}
long modpow(long a, long b, int p)
{
if(b==0) return 1;
long q = modpow(a,b/2,p);
q = (q*q)%p;
if(b%2==1) q = (q*a)%p;
return q;
}
private long inv(long a,int p)
{
if(a==p-1) return p-1;
return modpow(a, p - 2,p);
}
long modcomb(int a, int b, int p)
{
if(a<b) return 0;
if(a==b) return 1;
if(b==0) return 1;
long ans = fact[a];
ans = (ans*inv(fact[b],p))%p;
ans = (ans*inv(fact[a-b],p))%p;
return ans%p;
}
void run() throws NumberFormatException, IOException
{
int p = 1000000007;
fact = new long[100001];
fact[0] = 0;
fact[1] = 1;
for(int i = 2; i <= 100000; i++)
fact[i] = (fact[i-1]*i)%p;
int n = nextInt();
int k = nextInt();
TreeMap<Integer,Integer> map = new TreeMap<Integer,Integer>();
int luckys = 0;
int difluckys = 0;
int[] luck = new int[1024];
for(int i = 0; i < n; i++)
{
int a = nextInt();
if(islucky(a))
{
if(map.containsKey(a))
map.put(a, map.get(a)+1);
else
{
luck[difluckys++] = a;
map.put(a, 1);
}
luckys++;
}
}
long[][] dp = new long[difluckys+1][difluckys];
if(difluckys>0)
{
dp[1][0] = map.get(luck[0]);
for(int i = 1; i < difluckys; i++)
dp[1][i] = (dp[1][i-1] + map.get(luck[i]))%p;
for(int j = 2; j <= difluckys && j <= k; j++)
{
for(int i = j-1; i < difluckys; i++)
dp[j][i] = (dp[j][i-1] + dp[j-1][i-1]*map.get(luck[i]))%p;
}
}
long ans = modcomb(n-luckys,k,p);
for(int i = 1; i <= Math.min(difluckys,k); i++)
{
ans += dp[i][difluckys-1]*modcomb(n-luckys,k-i,p);
ans%=p;
}
out.println(ans);
}
public static void main(String[] args) throws NumberFormatException, IOException
{
new E();
}
String nextToken() throws IOException
{
if(tok ==null || !tok.hasMoreTokens()) tok = new StringTokenizer(in.readLine());
return tok.nextToken();
}
int nextInt() throws NumberFormatException, IOException
{
return Integer.parseInt(nextToken());
}
long nextLong() throws NumberFormatException, IOException
{
return Long.parseLong(nextToken());
}
double nextDouble() throws NumberFormatException, IOException
{
return Double.parseDouble(nextToken());
}
}
|
Java
|
["3 2\n10 10 10", "4 2\n4 4 7 7"]
|
2 seconds
|
["3", "4"]
|
NoteIn the first sample all 3 subsequences of the needed length are considered lucky.In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1,β3}, {1,β4}, {2,β3} and {2,β4}.
|
Java 6
|
standard input
|
[
"dp",
"combinatorics"
] |
c421f47149e70240a02903d9d47de429
|
The first line contains two integers n and k (1ββ€βkββ€βnββ€β105). The next line contains n integers ai (1ββ€βaiββ€β109) β the sequence a.
| 2,100 |
On the single line print the single number β the answer to the problem modulo prime number 1000000007 (109β+β7).
|
standard output
| |
PASSED
|
46d355b9f3af6dea359e911f65778dd5
|
train_001.jsonl
|
1327215600
|
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has sequence a consisting of n integers.The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements.Two sequences are considered different if index sets of numbers included in them are different. That is, the values βof the elements βdo not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence).A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times).Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109β+β7).
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Map;
import java.util.TreeMap;
public class E {
static StreamTokenizer st;
static int mod = (int) (1e9+7);
static int[]fac;
public static void main(String[] args) throws IOException{
st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = nextInt();
int k = nextInt();
int unluckly = 0;
Map<Integer, Integer> map = new TreeMap<Integer, Integer>();
for (int i = 1; i <= n; i++) {
int a = nextInt();
if (isluckly(a)) {
if (!map.containsKey(a))
map.put(a, 1);
else
map.put(a, map.get(a)+1);
}
else
unluckly++;
}
int t = 0;
int[]cnt = new int[map.size()+1];
for (int i : map.keySet()) {
cnt[++t] = map.get(i);
}
int[][]dp = new int[t+1][t+1];
for (int i = 0; i <= t; i++) {
dp[i][0] = 1;
}
for (int i = 1; i <= t; i++) {
for (int j = 1; j <= t; j++) {
dp[i][j] = (dp[i-1][j] + (int)((long)dp[i-1][j-1]*cnt[i] % mod)) % mod;
}
}
fac = new int[n+1];
fac[0] = 1;
for (int i = 1; i <= n; i++) {
fac[i] = (int)((long)fac[i-1]*i % mod);
}
int ans = 0;
for (int i = 0; i <= k; i++) {
if (i <= t)
ans = (ans + (int)((long)dp[t][i] * C_n_k(unluckly, k-i) % mod)) % mod;
}
System.out.println(ans);
}
private static int C_n_k(int n, int k) {
if (k > n)
return 0;
int res = fac[n];
res = (int)((long)res*inver_in_modul(fac[k]) % mod);
res = (int)((long)res*inver_in_modul(fac[n-k]) % mod);
return res;
}
private static long inver_in_modul(int a) {
int n = mod-2;
int res = 1;
while (n > 0) {
if ((n & 1)==1)
res = (int) ((long)res*a % mod);
n >>= 1;
a = (int)((long)a*a % mod);
}
return res;
}
private static boolean isluckly(int a) {
while (a > 0) {
int k = a % 10;
if (k != 4 && k != 7)
return false;
a /= 10;
}
return true;
}
private static int nextInt() throws IOException{
st.nextToken();
return (int)st.nval;
}
}
|
Java
|
["3 2\n10 10 10", "4 2\n4 4 7 7"]
|
2 seconds
|
["3", "4"]
|
NoteIn the first sample all 3 subsequences of the needed length are considered lucky.In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1,β3}, {1,β4}, {2,β3} and {2,β4}.
|
Java 6
|
standard input
|
[
"dp",
"combinatorics"
] |
c421f47149e70240a02903d9d47de429
|
The first line contains two integers n and k (1ββ€βkββ€βnββ€β105). The next line contains n integers ai (1ββ€βaiββ€β109) β the sequence a.
| 2,100 |
On the single line print the single number β the answer to the problem modulo prime number 1000000007 (109β+β7).
|
standard output
| |
PASSED
|
145830f0748a0123c5445313dcecfc3e
|
train_001.jsonl
|
1327215600
|
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has sequence a consisting of n integers.The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements.Two sequences are considered different if index sets of numbers included in them are different. That is, the values βof the elements βdo not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence).A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times).Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109β+β7).
|
256 megabytes
|
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
/**
* @author Roman Elizarov
*/
public class Round_104_E {
private static final int MOD = 1000000007;
public static void main(String[] args) {
new Round_104_E().go();
}
int n;
int k;
int m;
int t;
int[] a;
int[] dup;
int[][] mem;
int[] fac;
int[] c;
private void go() {
Scanner in = new Scanner(System.in);
PrintStream out = System.out;
n = in.nextInt();
k = in.nextInt();
a = new int[n];
for (int i = 0; i < n; i++)
a[i] = in.nextInt();
out.println(solve());
}
int solve() {
Arrays.sort(a);
dup = new int[n];
m = 0;
boolean washappy = false;
for (int i = 0; i < n; i++) {
int x = a[i];
boolean same = i > 0 && x == a[i - 1];
if (same && washappy) {
dup[m - 1]++;
} else {
dup[m++] = 1;
}
washappy = same ? washappy : happy(x);
}
Arrays.sort(dup, 0, m);
t = 0;
while (t < m && dup[t] == 1)
t++;
mem = new int[m - t + 1][m - t + 1];
for (int[] ints : mem) {
Arrays.fill(ints, -1);
}
// precompute factorial table
fac = new int[t + 1];
fac[0] = 1;
for (int i = 1; i <= t; i++)
fac[i] = mul(fac[i - 1], i);
// compute binomials as needed
c = new int[t + 1];
Arrays.fill(c, -1);
return compute(t, 0);
}
private int compute(int i, int done) {
if (mem[i - t][done] >= 0)
return mem[i - t][done];
if (done >= k)
return mem[i - t][done] = 1;
if (i >= m)
return mem[i - t][done] = c(k - done);
return mem[i - t][done] = add(
compute(i + 1, done),
mul(compute(i + 1, done + 1), dup[i]));
}
private int mul(long a, long b) {
return (int)((a * b) % MOD);
}
private int add(long a, long b) {
return (int)((a + b) % MOD);
}
private int pow(long a, int p) {
int res = 1;
// a^p * res == original a^p
while (p > 0) {
if ((p & 1) != 0)
res = mul(res, a);
a = mul(a, a);
p >>= 1;
}
return res;
}
private int inv(long a) {
return pow(a, MOD - 2);
}
private int div(long a, long b) {
return mul(a, inv(b));
}
// choose k from t
private int c(int k) {
if (k > t)
return 0;
if (c[k] >= 0)
return c[k];
return c[k] = div(fac[t], mul(fac[k], fac[t - k]));
}
private boolean happy(int x) {
while (x != 0) {
int d = x % 10;
if (d != 4 && d != 7)
return false;
x /= 10;
}
return true;
}
}
|
Java
|
["3 2\n10 10 10", "4 2\n4 4 7 7"]
|
2 seconds
|
["3", "4"]
|
NoteIn the first sample all 3 subsequences of the needed length are considered lucky.In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1,β3}, {1,β4}, {2,β3} and {2,β4}.
|
Java 6
|
standard input
|
[
"dp",
"combinatorics"
] |
c421f47149e70240a02903d9d47de429
|
The first line contains two integers n and k (1ββ€βkββ€βnββ€β105). The next line contains n integers ai (1ββ€βaiββ€β109) β the sequence a.
| 2,100 |
On the single line print the single number β the answer to the problem modulo prime number 1000000007 (109β+β7).
|
standard output
| |
PASSED
|
91757b6c16ac4cf18ae99dc2457428e4
|
train_001.jsonl
|
1327215600
|
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has sequence a consisting of n integers.The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements.Two sequences are considered different if index sets of numbers included in them are different. That is, the values βof the elements βdo not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence).A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times).Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109β+β7).
|
256 megabytes
|
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.*;
public class Main implements Runnable{
static final Boolean fromFile = false;
static final Boolean isDebug = false;
static final String fileName = "input";
BufferedReader reader;
PrintWriter out;
FastScanner sc;
TreeSet<Long> set;
long mod = 1000000007l;
void fill(long s) {
if (s > 1000000000l)
return;
set.add(s);
fill(s * 10l + 4l);
fill(s * 10l + 7l);
}
long modFact(long n) {
if (n == 1l)
return 1l;
return (modFact(n - 1l) * n) % mod;
}
long c(int n, int k) {
if (k > n)
return 0l;
if (k == n || k == 0) {
return 1l;
}
return ((fact[n] * ob[k])%mod * ob[n - k]) % mod;
}
long binPow(long a, long b) {
if (b == 0)
return 1l;
if (b == 1)
return a % mod;
long tmp = binPow(a,b/2);
tmp = (tmp * tmp) % mod;
if (b%2==0)
return tmp % mod;
else
return (tmp * a) % mod;
}
boolean isLucky(long a) {
while (a > 0) {
if (!(a % 10 == 4 || a % 10 == 7))
return false;
a /= 10;
}
return true;
}
long[] fact;
long[] ob;
void solve() throws Exception {
/* set = new TreeSet<Long>();
fill(4);
fill(7);*/
int n = sc.nextInt();
int k = sc.nextInt();
fact = new long[n + 1];
ob = new long[n + 1];
fact[0] = 1l;
for (int i = 1;i <= n; ++ i)
fact[i] = (fact[i-1] * i)%mod;
for (int i = 1;i <= n; ++ i)
ob[i] = binPow(fact[i], mod - 2);
if (k == 1) {
out.println(n);
return;
}
HashMap<Long, Integer> map = new HashMap<Long, Integer>();
long[] col = new long[1024];
int notLucky = 0;
int index = 0;
for (int i = 0;i < n; ++ i) {
long tmp = sc.nextLong();
if (isLucky(tmp)) {
if (map.containsKey(tmp)) {
int j = map.get(tmp);
col[j] ++;
} else {
map.put(tmp, index);
col[index] = 1;
index ++;
}
} else {
notLucky ++;
}
}
long[][] dp = new long[index + 1][];
int kk = Math.min(index, k);
for (int i = 0;i <= index; ++ i) {
dp[i] = new long[kk + 1];
}
for (int i = 0;i <= index; ++ i) {
dp[i][0] = 1;
}
for (int i = 1; i <= index; ++ i) {
for (int cnt = 1;cnt <= i && cnt <= kk; ++ cnt) {
dp[i][cnt] = (dp[i - 1][cnt] + (col[i - 1] * dp[i - 1][cnt - 1]) % mod) % mod;
}
}
long ans = 0l;
for (int i = 0;i <= kk; ++ i) {
ans = (ans + (dp[index][i] * c(notLucky, k - i)) % mod) % mod;
}
out.println(ans);
}
public static void main(String[] args) throws Exception {
if (isDebug) {
new Main().runDebug();
} else {
new Thread(null, new Main(), "", 16 * 16 * 1024).run();
}
}
public void run() {
try {
if (fromFile) {
reader = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter(new FileWriter("output.txt"));
} else {
reader = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
sc = new FastScanner(reader);
solve();
}
catch (Exception exc) {
RuntimeException rexc = new RuntimeException(exc);
rexc.setStackTrace(exc.getStackTrace());
throw rexc;
}
finally {
if (out != null)
out.close();
}
}
public void runDebug() throws Exception {
if (fromFile) {
reader = new BufferedReader(new FileReader(fileName + ".in"));
out = new PrintWriter(new FileWriter(fileName + ".out"));
} else {
reader = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
sc = new FastScanner(reader);
solve();
out.close();
}
}
class FastScanner {
BufferedReader reader;
StringTokenizer strtok;
public FastScanner(BufferedReader reader) {
this.reader = reader;
}
String nextToken() throws IOException {
if (strtok == null || !strtok.hasMoreTokens()) {
strtok = new StringTokenizer(reader.readLine());
}
return strtok.nextToken();
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
}
|
Java
|
["3 2\n10 10 10", "4 2\n4 4 7 7"]
|
2 seconds
|
["3", "4"]
|
NoteIn the first sample all 3 subsequences of the needed length are considered lucky.In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1,β3}, {1,β4}, {2,β3} and {2,β4}.
|
Java 6
|
standard input
|
[
"dp",
"combinatorics"
] |
c421f47149e70240a02903d9d47de429
|
The first line contains two integers n and k (1ββ€βkββ€βnββ€β105). The next line contains n integers ai (1ββ€βaiββ€β109) β the sequence a.
| 2,100 |
On the single line print the single number β the answer to the problem modulo prime number 1000000007 (109β+β7).
|
standard output
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.