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 | 0561f1e3a901d6a382f901fee45e9734 | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes |
import java.util.Scanner;
public class army {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int a[] = new int[n-1];
for(int i=0;i<n-1;i++){
a[i]=s.nextInt();
}
int b =s.nextInt();
int c= s.nextInt();
int j=b-1;
int sum=0;
for(int i=b;i<c;i++){
sum+=a[j];
j++;
}
System.out.print(sum);
}
} | Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | 54d31e965b5b9d433c3222fa9ecb82fa | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes | import java.util.Scanner;
public class problem38A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
//int nm1= n-1;
int[] lvlRando = new int[n];
//int[] rango = new int[nm1];
lvlRando [0]= 0;
for (int i = 1; i < lvlRando.length; i++) {
lvlRando[i] = sc.nextInt();
}
//Arrays.sort(lvlRando);
int a = sc.nextInt();
int b = sc.nextInt();
int ab = b-a;
int resu = 0;
//System.out.println("asdasd"+ab);
for (int i = 0; i < lvlRando.length; i++) {
//System.out.println(i+" "+lvlRando[i]);
if(i>(a-1)){
// System.out.println("entro "+i);
if(i<b){
// System.out.println("entro");
resu+=lvlRando[i];
}
}
}
System.out.println(resu);
}
} | Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | c613e09ac1e5948ace3dda6169beeda7 | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Army {
public static void main(String[]args) throws Exception {
BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
int year = Integer.parseInt(b.readLine()) , sum = 0 , start , end;
args = b.readLine().split(" ");
String[] x = b.readLine().split(" ");
start = Integer.parseInt(x[0]) - 1;
end = Integer.parseInt(x[1]) - 1;
while(start < end) {
sum += Integer.parseInt(args[start++]);
}
System.out.println(sum);
}
} | Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | 3ce64424db20c3836c2e49901879ae2b | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes |
import java.util.Scanner;
import java.util.Stack;
import javax.swing.JOptionPane;
/**
*
* @author User
*/
public class Test {
public static void main(String[]args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int d[] = new int[n];
for (int i = 1; i <=n-1; i++) {
d[i] = in.nextInt();
}
int a = in.nextInt();
int b = in.nextInt();
int sum = 0 ;
while(a!=b){
sum+=d[a];
a++;
}
System.out.println(sum);
}}
| Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | ff1128286a2544a7ac454408dfb58422 | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes | import java.util.*;
public class Army {
public static void main(String[]args){
Scanner clv=new Scanner(System.in);
int a=clv.nextInt(); int somme=0;
int[]tabl=new int[a-1];int[] deux=new int[2];
for(int t=0;t<a-1;t++){
tabl[t]=clv.nextInt();
}
deux[0]=clv.nextInt();
deux[1]=clv.nextInt();
int pomme=deux[1]-deux[0];
for(int j=deux[0]-1;j<pomme+deux[0]-1;j++){
somme+=tabl[j];
}
System.out.println(somme);
}
} | Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | f6a895c5e7e8c97467170a6342541acf | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes |
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.lang.String;
import java.util.Locale;
public class JavaApplication4 {
public static void main(String[] args) {
Scanner ss=new Scanner(System.in);
int n=ss.nextInt();
int[] str=new int[n-1];
for(int i=0;i<n-1;i++)
str[i]=ss.nextInt();
int a=ss.nextInt();
int b=ss.nextInt();
int years=0;
for(int i=a;i<b;i++)
{years+=str[i-1];
}
System.out.println(years);
}
}
| Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | c28849ff6b35430a25c8327b1c6578e2 | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes | import java.util.*;
import java.math.*;
public class Me
{
public static void main(String[] args)
{
Scanner br=new Scanner(System.in);
int n=br.nextInt();
int[] arr=new int[n-1];
int s=0;
for(int i=0;i<n-1;i++)
{
arr[i]=br.nextInt();
}int a=br.nextInt();
int b=br.nextInt();
int c=b-a;
for(int i=a;i<b;i++)
{
s=s+arr[i-1];
}System.out.print(s);
}
}
| Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | d8894f169c7e14d1705b93d8bfa7f2bb | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes | import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
byte n = in.nextByte();
int count = 0;
byte arr[] = new byte[n-1];
for (int i = 0; i < arr.length; i++) {
arr[i] = in.nextByte();
}
byte a = in.nextByte();
byte b = in.nextByte();
for (int i = a-1; i < b-1; i++) {
count += arr[i] ;
}
System.out.println(count);
}
} | Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | 1995361ef7965b061888db88d47ef126 | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes | import java.util.Scanner;
import java.lang.*;
public class Code1 {
public static void main(String str[])
{
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b[] = new int[a-1];
for(int i=0;i<b.length;i++)
{
b[i]=sc.nextInt();
}
int a1,b1;
a1 = sc.nextInt();
b1 = sc.nextInt();
int c=0;
for (int i=a1;i<b1;i++)
{
c=c+b[i-1];
}
System.out.println(c);
}
}
| Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | a42f769346758fefa0d47a2156647386 | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
import java.lang.*;
public class mitul
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] arr = new int[n-1];
for(int i=0;i<n-1;i++)
{
arr[i]=scan.nextInt();
}
int a = scan.nextInt();
int b = scan.nextInt();
int c = b-a-1;
int sum=0;
for(int i=a-1;i<=a+c-1;i++)
{
sum=sum+arr[i];
}
System.out.println(sum);
}
} | Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | 1857bb31373ad6a5cdf899fe35786cfc | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes |
import java.util.Scanner;
public class Army {
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
int n,a,b,i,y=0;
n=input.nextInt();
int aray[]=new int[n-1];
for( i=0;i<n-1;i++)
{
aray[i]=input.nextInt();
}
a=input.nextInt();
b=input.nextInt();
int c=b-a;
for(i=0;i<c;i++)
{
y=y+aray[a-1];
a++;
}
System.out.println(y);
}
}
| Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | 5fa49f3d4be30b61f14467b1aa106197 | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes |
/*
* Author- Kishan_25
* BTech 2nd Year DAIICT
*/
import java.io.*;
import java.math.*;
import java.util.*;
import javax.print.attribute.SetOfIntegerSyntax;
public class code {
private static InputStream stream;
private static byte[] buf = new byte[1024];
private static int curChar;
private static int numChars;
private static SpaceCharFilter filter;
private static PrintWriter pw;
private static long count = 0,mod=1000000007;
private static TreeSet<Integer>ts[]=new TreeSet[200000];
private static HashSet hs=new HashSet();
public static void main(String args[]) throws Exception {
InputReader(System.in);
pw = new PrintWriter(System.out);
//ans();
soln();
//temp();
pw.close();
}
public static void temp(){
Scanner in = new Scanner(System.in);
String s = in.nextLine();
int ind = 0;
char a = s.charAt(0);
for(int i = 1;i<s.length();i++){
if(s.charAt(i) > a){
a = s.charAt(i);
ind = i;
}
}
String t = s.substring(ind);
String te = s.substring(0,ind);
s = t+te;
System.out.println(s);
}
public static long gcd(long x, long y) {
if (x == 0)
return y;
else
return gcd( y % x,x);
}
private static int BinarySearch(int a[], int low, int high, int target) {
if (low > high)
return -1;
int mid = low + (high - low) / 2;
if (a[mid] == target)
return mid;
if (a[mid] > target)
high = mid - 1;
if (a[mid] < target)
low = mid + 1;
return BinarySearch(a, low, high, target);
}
public static String reverseString(String s) {
StringBuilder sb = new StringBuilder(s);
sb.reverse();
return (sb.toString());
}
public static long pow(long n, long p) {
if(p==0)
return 1;
if(p==1)
return n%mod;
if(p%2==0){
long temp=pow(n, p/2);
return (temp*temp)%mod;
}else{
long temp=pow(n,p/2);
temp=(temp*temp)%mod;
return(temp*n)%mod;
}
}
public static int[] radixSort(int[] f) {
int[] to = new int[f.length];
{
int[] b = new int[65537];
for (int i = 0; i < f.length; i++)
b[1 + (f[i] & 0xffff)]++;
for (int i = 1; i <= 65536; i++)
b[i] += b[i - 1];
for (int i = 0; i < f.length; i++)
to[b[f[i] & 0xffff]++] = f[i];
int[] d = f;
f = to;
to = d;
}
{
int[] b = new int[65537];
for (int i = 0; i < f.length; i++)
b[1 + (f[i] >>> 16)]++;
for (int i = 1; i <= 65536; i++)
b[i] += b[i - 1];
for (int i = 0; i < f.length; i++)
to[b[f[i] >>> 16]++] = f[i];
int[] d = f;
f = to;
to = d;
}
return f;
}
public static int nextPowerOf2(final int a) {
int b = 1;
while (b < a) {
b = b << 1;
}
return b;
}
public static boolean PointInTriangle(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) {
int s = p2 * p5 - p1 * p6 + (p6 - p2) * p7 + (p1 - p5) * p8;
int t = p1 * p4 - p2 * p3 + (p2 - p4) * p7 + (p3 - p1) * p8;
if ((s < 0) != (t < 0))
return false;
int A = -p4 * p5 + p2 * (p5 - p3) + p1 * (p4 - p6) + p3 * p6;
if (A < 0.0) {
s = -s;
t = -t;
A = -A;
}
return s > 0 && t > 0 && (s + t) <= A;
}
public static float area(int x1, int y1, int x2, int y2, int x3, int y3) {
return (float) Math.abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0);
}
public static boolean isPrime(int n) {
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
//merge Sort
static long sort1(int a[])
{ int n=a.length;
int b[]=new int[n];
return mergeSort(a,b,0,n-1);}
static long mergeSort(int a[],int b[],long left,long right)
{ long c=0;if(left<right)
{ long mid=left+(right-left)/2;
c= mergeSort(a,b,left,mid);
c+=mergeSort(a,b,mid+1,right);
c+=merge(a,b,left,mid+1,right); }
return c; }
static long merge(int a[],int b[],long left,long mid,long right)
{long c=0;int i=(int)left;int j=(int)mid; int k=(int)left;
while(i<=(int)mid-1&&j<=(int)right)
{ if(a[i]>a[j]) {b[k++]=a[i++]; }
else { b[k++]=a[j++];c+=mid-i;}}
while (i <= (int)mid - 1) b[k++] = a[i++];
while (j <= (int)right) b[k++] = a[j++];
for (i=(int)left; i <= (int)right; i++)
a[i] = b[i]; return c; }
public static boolean isSubSequence(String large, String small, int largeLen, int smallLen) {
//base cases
if (largeLen == 0)
return false;
if (smallLen == 0)
return true;
// If last characters of two strings are matching
if (large.charAt(largeLen - 1) == small.charAt(smallLen - 1))
isSubSequence(large, small, largeLen - 1, smallLen - 1);
// If last characters are not matching
return isSubSequence(large, small, largeLen - 1, smallLen);
}
// To Get Input
// Some Buffer Methods
public static void InputReader(InputStream stream1) {
stream = stream1;
}
private static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private static boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
private static 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 static int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
private static long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
private static String nextToken() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
private static 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();
}
private static int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
private static int[][] next2dArray(int n, int m) {
int[][] arr = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = nextInt();
}
}
return arr;
}
private static char[][] nextCharArray(int n,int m){
char [][]c=new char[n][m];
for(int i=0;i<n;i++){
String s=nextLine();
for(int j=0;j<s.length();j++){
c[i][j]=s.charAt(j);
}
}
return c;
}
private static long[] nextLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
private static void pArray(int[] arr) {
for (int i = 0; i < arr.length; i++) {
pw.print(arr[i] + " ");
}
pw.println();
return;
}
private static void pArray(long[] arr) {
for (int i = 0; i < arr.length; i++) {
pw.print(arr[i] + " ");
}
pw.println();
return;
}
private static void pArray(boolean[] arr) {
for (int i = 0; i < arr.length; i++) {
pw.print(arr[i] + " ");
}
pw.println();
return;
}
private static boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhitespace(c);
}
private interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
public static int find(int parent[], int i)
{
if (parent[i] == -1)
return i;
return find(parent, parent[i]);
}
// A utility function to do union of two subsets
public static void Union(int parent[], int x, int y)
{
int xset = find(parent, x);
int yset = find(parent, y);
parent[xset] = yset;
}
//----------------------------------------My Code------------------------------------------------//
private static void soln() {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();
int arr[] = new int[n];
for(int i = 1;i<n;i++){
arr[i] = in.nextInt();
}
int a = in.nextInt();
int b = in.nextInt();
long sum = 0;
for(int i = a;i<=b-1;i++){
sum += arr[i];
}
pw.println(sum);
}//-----------------------------------------The End--------------------------------------------------------------------------//
public static int toDecimal(String str) {
int decimal = 0;
int base0 = (int)'0';
char ch;
for (int i = 0; i < str.length(); i++) {
ch = str.charAt(i);
if (charIsNotBinary(ch)) {
return 0;
}
decimal = decimal * 2 + ((int)str.charAt(i) - base0);
}
return decimal;
}
private static boolean charIsNotBinary(char ch) {
return '1' < ch || ch < '0';
}
}
class node{
int s;
int v;
}
class Pair implements Comparable<Pair>{
long id;
long w;
long h;
Pair(long id,long w,long h){
this.id=id;
this.w=w;
this.h=h;
}
@Override
public int compareTo(Pair o) {
// TODO Auto-generated method stub
// Sort in increasing order
if(w>o.w)
return 1;
else if(w<o.w)
return -1;
else{
if(h>o.h){
return 1;
}else if(o.h>h)
return -1;
else return 0;
}
}
}
class Graph{
private static int V,level[][],count=-1,lev_dfs[],degree=0,no_vert_conn_comp=0;
private Stack <Integer>st=new Stack();
private static LinkedList<Integer > adj[];
private boolean[][] Visite;
private static boolean [] Visited;
private static TreeSet<Integer> ts=new TreeSet();
Graph(int V){
V++;
this.V=(V);
adj=new LinkedList[V];
Visite=new boolean[100][100];
Visited=new boolean[V];
level=new int[100][100];
lev_dfs=new int[V];
for(int i=0;i<V;i++)
adj[i]=new LinkedList<Integer>();
}
void addEdge(int v,int w){
if(adj[v]==null){
adj[v]=new LinkedList();
}
if(adj[w] == null){
adj[w] = new LinkedList();
}
adj[v].add(w);
}
public static int conCop(int startVert){
Visited=new boolean[V];
int totalcon = 1;
Queue<Integer> q=new LinkedList<Integer>();
q.add(startVert);
Visited[startVert] = true;
while(!q.isEmpty()){
int top=q.poll();
Iterator<Integer> i= adj[top].listIterator();
while(i.hasNext()){
int n=i.next();
if(!Visited[n]){
q.add(n);
Visited[n]=true;
totalcon++;
}
}
}
q.clear();
return totalcon;
}
public static int NoConEdge(int startVert){
Visited=new boolean[V];
Queue<Integer> q=new LinkedList<Integer>();
q.add(startVert);
Visited[startVert] = true;
long ed = adj[startVert].size();
while(!q.isEmpty()){
int top=q.poll();
Iterator<Integer> i= adj[top].listIterator();
while(i.hasNext()){
int n=i.next();
if(!Visited[n]){
q.add(n);
Visited[n]=true;
ed+= adj[n].size();
}
}
}
q.clear();
return (int)ed/2;
}
public static int BFS2(int startVert){
Visited=new boolean[V];
for(int i=0;i<V;i++){
lev_dfs[i]=-1;
}
Queue<Integer> q=new LinkedList<Integer>();
q.add(startVert);
lev_dfs[startVert]=0;
while(!q.isEmpty()){
int top=q.poll();
Iterator<Integer> i= adj[top].listIterator();
while(i.hasNext()){
int n=i.next();
if(!Visited[n]){
q.add(n);
Visited[n]=true;
lev_dfs[n]=lev_dfs[top]+1;
//System.out.println(top + " " + n);
}
}
}
q.clear();
int mx = 0;
for(int i = 0;i<V;i++){
mx = Math.max(mx, lev_dfs[i]);
}
return mx;
}
public int getEd(){
return degree/2;
}
public void get(int from,int to){
int h=lev_dfs[from]-lev_dfs[to];
if(h<=0){
System.out.println(-1);
}else{
System.out.println(h-1);
}
}
private static boolean check(int x,int y,char c[][]){
if((x>=0 && y>=0) && (x<c.length && y<c[0].length) && c[x][y]!='#'){
return true;
}
return false;
}
public int BFS(int x,int y,int k,char[][] c)
{
LinkedList<Pair> queue = new LinkedList<Pair>();
//Visited[s]=true;
// queue.add(new Pair(x,y));
int count=0;
level[x][y]=-1;
c[x][y]='M';
while (!queue.isEmpty())
{
Pair temp = queue.poll();
//x=temp.idx;
//y=temp.val;
c[x][y]='M';
// System.out.println(x+" "+y+" ---"+count);
count++;
if(count==k)
{
for(int i=0;i<c.length;i++){
for(int j=0;j<c[0].length;j++){
if(c[i][j]=='M'){
System.out.print(".");
}
else if(c[i][j]=='.')
System.out.print("X");
else
System.out.print(c[i][j]);
}
System.out.println();
}
System.exit(0);
}
// System.out.println(x+" "+y);
// V--;
}
return V;
}
private void getAns(int startVertex){
for(int i=0;i<adj[startVertex].size();i++){
int ch=adj[startVertex].get(i);
for(int j=0;j<adj[ch].size();j++){
int ch2=adj[ch].get(j);
if(adj[ch2].contains(startVertex)){
System.out.println(startVertex+" "+ch+" "+ch2);
System.exit(0);
}
}
}
}
public long dfs(int startVertex){
// getAns(startVertex);
if(!Visited[startVertex]) {
return dfsUtil(startVertex,Visited);
//return getAns();
}
return 0;
}
private long dfsUtil(int startVertex, boolean[] Visited) {//0-Blue 1-Pink
int c=1;
long cout=0;
degree=0;
Visited[startVertex]=true;
lev_dfs[startVertex]=1;
st.push(startVertex);
while(!st.isEmpty()){
int top=st.pop();
int child=adj[top].size();
if(top!=startVertex)
child--;
ts.add(top);
Iterator<Integer> i=adj[top].listIterator();
degree+=adj[top].size();
while(i.hasNext()){
int n=i.next();
if( !Visited[n]){
Visited[n]=true;
st.push(n);
if(adj[n].size()-1>child)
cout++;
c++;
lev_dfs[n]=lev_dfs[top]+1;
}
}
}
return cout;
// System.out.println("NO");
// return c;
}
}
class Dsu{
private int rank[], parent[] ,n;
Dsu(int size){
this.n=size+1;
rank=new int[n];
parent=new int[n];
makeSet();
}
void makeSet(){
for(int i=0;i<n;i++){
parent[i]=i;
}
}
int find(int x){
if(parent[x]!=x){
parent[x]=find(parent[x]);
}
return parent[x];
}
void union(int x,int y){
int xRoot=find(x);
int yRoot=find(y);
if(xRoot==yRoot)
return;
if(rank[xRoot]<rank[yRoot]){
parent[xRoot]=yRoot;
}else if(rank[yRoot]<rank[xRoot]){
parent[yRoot]=xRoot;
}else{
parent[yRoot]=xRoot;
rank[xRoot]++;
}
}
}
class Heap{
public static void build_max_heap(long []a,int size){
for(int i=size/2;i>0;i--){
max_heapify(a, i,size);
}
}
private static void max_heapify(long[] a,int i,int size){
int left_child=2*i;
int right_child=(2*i+1);
int largest=0;
if(left_child<size && a[left_child]>a[i]){
largest=left_child;
}else{
largest=i;
}
if(right_child<size && a[right_child]>a[largest]){
largest=right_child;
}
if(largest!=i){
long temp=a[largest];
a[largest]=a[i];
a[i]=temp;
max_heapify(a, largest,size);
}
}
private static void min_heapify(int[] a,int i){
int left_child=2*i;
int right_child=(2*i+1);
int largest=0;
if(left_child<a.length && a[left_child]<a[i]){
largest=left_child;
}else{
largest=i;
}
if(right_child<a.length && a[right_child]<a[largest]){
largest=right_child;
}
if(largest!=i){
int temp=a[largest];
a[largest]=a[i];
a[i]=temp;
min_heapify(a, largest);
}
}
public static void extract_max(int size,long a[]){
if(a.length>1){
long max=a[1];
a[1]=a[a.length-1];
size--;
max_heapify(a, 1,a.length-1);
}
}
}
class no{
String s;
int i;
}
class MyComp implements Comparator<node>{
@Override
public int compare(node o1, node o2) {
if(o1.v>o2.v){
return 1;
}else if(o1.v<o2.v){
return -1;
}
return 0;
}
} | Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | 090df9abf284d10798846d550e0f88b8 | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int a[]=new int[n-1];
for(int i=0;i<(n-1);i++)
{
a[i]=in.nextInt();
}
int d=in.nextInt();
int b=in.nextInt();
int temp=b-d;
int res=0;
if(temp==(d-1))
{
res=a[temp];
}
else{
for(int i=d-1;i<(b-1);i++)
{
res=res+a[i];
}
}
System.out.println(res);
}
}
| Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | eda1ef235ef28f40216d332a888977e6 | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int n;
int[] years;
n = in.nextInt();
years = new int[n-1];
for (int i = 0; i < n-1; i++) {
years[i] = in.nextInt();
}
int a = in.nextInt();
int b = in.nextInt();
int sum = 0;
while(a < b){
sum += years[a-1];
a++;
}
System.out.println(sum);
}
} | Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | 72a5aece2f4a572f91d6fd333a72c5c6 | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes | import java.util.Scanner;
public class Army{
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
int numRanks = scan.nextInt();
int[]rankCost = new int[numRanks+2];
for(int i=2;i<=numRanks;i++){
rankCost[i] = scan.nextInt() + rankCost[i-1];
}
int startRank = scan.nextInt();
int finishRank = scan.nextInt();
System.out.println((rankCost[finishRank] - rankCost[startRank]));
}
} | Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | 637e082484b568559ecd05bfe0b6cfac | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Army {
public static void main(String[] args) throws IOException {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int []a=new int [n];
for(int i=1;i<n;i++)
a[i]=sc.nextInt();
int l=sc.nextInt();int r=sc.nextInt();int ans=0;
for(int i=l;i<r;i++)
ans+=a[i];
System.out.print(ans);
}
}
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\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | 23e705aae4296ee4d5410491382e8817 | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes | import java.util.*;
import javax.print.attribute.IntegerSyntax;
import java.io.*;
public class Problem {
public static void main(String[] args)throws IOException {
// BufferedReader br = new BufferedReader(new FileReader("input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
int [] promotions = new int[N];
StringTokenizer years = new StringTokenizer(br.readLine());
for(int i = 1; i < N; i++){
promotions[i] = Integer.parseInt(years.nextToken());
}
StringTokenizer yearDif = new StringTokenizer(br.readLine());
int a = Integer.parseInt(yearDif.nextToken());
int b = Integer.parseInt(yearDif.nextToken());
int total = 0;
for(int i = a; i < b; i++){
total += promotions[i];
}
// System.out.println(total);
out.println(total);
out.close();
}
} | Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | eeac644ed0f4c0b0badb7abe172f204c | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes | import java.util.*;
public class Army {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in) ;
int n = in.nextInt() ;
int [] d = new int [n] ;
int sum = 0 ;
for(int i =1 ; i<= n-1 ; i++){
d[i] = in.nextInt() ;
}
int a = in.nextInt() ;
int b = in.nextInt() ;
int c = Math.abs(a-b) ;
for(int j = a ; j < b ; j++){
sum = sum + d[j] ;
}
System.out.println(sum);
}
}
| Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | cda5642e3b456be576cc27f7d24a76b7 | train_002.jsonl | 1288440000 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank iβ+β1. Reaching a certain rank i having not reached all the previous iβ-β1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | 256 megabytes | /* Read input from STDIN. Print your output to STDOUT*/
import java.io.*;
import java.util.*;
public class demo38 {
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());
}
}
public static void main(String args[] ) throws Exception {
FastReader sc=new FastReader();
int n=sc.nextInt(),sum=0;
int[] a=new int[n-1];
for(int i=0;i<n-1;i++)
{
a[i]=sc.nextInt();
}
int a1=sc.nextInt();
int b=sc.nextInt();
for(int i=a1-1;i<a1+(b-a1)-1;i++)
{
sum+=a[i];
}
System.out.println(sum);
}
}
| Java | ["3\n5 6\n1 2", "3\n5 6\n1 3"] | 2 seconds | ["5", "11"] | null | Java 8 | standard input | [
"implementation"
] | 69850c2af99d60711bcff5870575e15e | The first input line contains an integer n (2ββ€βnββ€β100). The second line contains nβ-β1 integers di (1ββ€βdiββ€β100). The third input line contains two integers a and b (1ββ€βaβ<βbββ€βn). The numbers on the lines are space-separated. | 800 | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | standard output | |
PASSED | b4ba7e03105018b93e687a557a303d37 | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Stream;
public class Solution implements Runnable {
static final long MOD = Long.MAX_VALUE;
static final Reader in = new Reader();
static final PrintWriter out = new PrintWriter(System.out);
StringBuilder answer = new StringBuilder();
public static void main(String[] args) {
// long startt = System.nanoTime();
new Thread(null, new Solution(), "persefone", 1 << 28).start();
// out.println((System.nanoTime() - startt));
}
@Override
public void run() {
solve(in.next(), in.next());
printf();
}
void solve(String s, String w) {
int ls = s.length();
long[] hs = new long[ls + 1];
computeHashArray(hs, s, ls);
int lw = w.length();
long[] hw = new long[lw + 1];
computeHashArray(hw, w, lw);
long[] mod = new long[ls + 1];
computeModArray(mod, ls);
int i = 1;
boolean check = true;
for (; i <= lw; i++) {
if (getHash(hs, mod, 0, i) != getHash(hw, mod, 0, i)) {
check = false;
break;
}
}
int count = 1;
List<Integer> li = new ArrayList<>();
li.add(i);
if (check) {
count = 1;
char ch = s.charAt(lw);
for (i = lw - 1; i > -1; i--)
if (s.charAt(i) == ch && ch == w.charAt(i)) {
count++;
li.add(i + 1);
} else break;
Collections.reverse(li);
printf(count);
printf(li);
return;
}
long h1 = getHash(hs, mod, i, ls);
long h2 = getHash(hw, mod, i - 1, lw);
if (h1 == h2) {
char ch = s.charAt(i - 1);
for (int j = i - 2; j > -1; j--) {
if (ch == s.charAt(j) && ch == w.charAt(j)) {
count++;
li.add(j + 1);
} else break;
}
Collections.reverse(li);
for (int j = i; j < ls; j++)
if (ch == s.charAt(j) && ch == w.charAt(j)) {
count++;
li.add(j + 1);
} else break;
printf(count);
printf(li);
return;
}
printf(0);
}
void computeHashArray(long[] hash, String s, int n) {
for (int i = 1; i <= n; i++)
hash[i] = (31 * hash[i - 1] + s.charAt(i - 1) - 'a') % MOD;
}
void computeModArray(long[] mod, int n) {
mod[0] = 1;
for (int i = 1; i <= n; i++)
mod[i] = (mod[i - 1] * 31) % MOD;
}
long getHash(long[] hash, long[] mod, int i, int j) {
return (hash[j] - hash[i] * mod[j - i]) % MOD;
}
long getHash(String s) {
long hash = 0;
for (int i = 0; i < s.length(); i++)
hash = (hash * 31 + s.charAt(i) - 'a') % MOD;
return hash;
}
void printf() {
out.print(answer);
out.close();
}
void printf(Stream<?> str) {
str.forEach(o -> add(o, " "));
add("\n");
}
void printf(Object... obj) {
if (obj.getClass().isPrimitive()) {
add(obj, "\n");
return;
}
if (obj.length > 1) {
printf(Arrays.stream(obj));
return;
}
if (obj.length == 1) {
Object o = obj[0];
if (o instanceof int[])
printf(Arrays.stream((int[]) o).boxed());
else if (o instanceof char[])
printf(String.valueOf(o).chars());
else if (o instanceof long[])
printf(Arrays.stream((long[]) o).boxed());
else if (o instanceof double[])
printf(Arrays.stream((double[]) o).boxed());
else
add(o, "\n");
}
}
void printf(Collection<?> col) {
printf(col.stream());
}
<T, K> void add(T t, K k) {
if (t instanceof Collection<?>) {
((Collection<?>) t).forEach(i -> add(i, " "));
} else if (t instanceof Object[]) {
Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
} else
add(t);
add(k);
}
<T> void add(T t) {
answer.append(t);
}
static class Node {
private int x, y;
Node(int x, int y) {
this.x = x;
this.y = y;
}
int getX() {
return x;
}
int getY() {
return y;
}
@Override
public String toString() {
return x + " " + y;
}
}
static class Pair<K extends Comparable<? super K>, V extends Comparable<? super V>>
implements Comparable<Pair<K, V>> {
private K k;
private V v;
Pair() {
}
Pair(K k, V v) {
this.k = k;
this.v = v;
}
K getK() {
return k;
}
V getV() {
return v;
}
void setK(K k) {
this.k = k;
}
void setV(V v) {
this.v = v;
}
void setKV(K k, V v) {
this.k = k;
this.v = v;
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || !(o instanceof Pair))
return false;
Pair<K, V> p = (Pair<K, V>) o;
return k.compareTo(p.k) == 0 && v.compareTo(p.v) == 0;
}
@Override
public int hashCode() {
int hash = 31;
hash = hash * 89 + k.hashCode();
hash = hash * 89 + v.hashCode();
return hash;
}
@Override
public int compareTo(Pair<K, V> pair) {
return k.compareTo(pair.k) == 0 ? v.compareTo(pair.v) : k.compareTo(pair.k);
}
@Override
public Pair<K, V> clone() {
return new Pair<K, V>(this.k, this.v);
}
@Override
public String toString() {
return String.valueOf(k).concat(" ").concat(String.valueOf(v)).concat("\n");
}
}
static class Reader {
private BufferedReader br;
private StringTokenizer st;
Reader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
try {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = nextInt();
return arr;
}
long nextLong() {
return Long.parseLong(next());
}
String nextLine() {
String s = "";
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return s;
}
}
} | Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 7bd3b1f770c8a9378cdfd1fffd1bbcd4 | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
public class Main {
public static void main(String[] args) throws Exception{
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
// GCD && LCM
long gcd(long a ,long b){return b == 0 ? a : gcd(b , a % b);}
long lcm(long a , long b){return a*(b/gcd(a, b));}
// REverse a String
String rev(String s){
return new StringBuilder(s).reverse().toString();
}
/* SOLUTION IS RIGHT HERE */
public void solve(int testNumber, InputReader in, PrintWriter out){
// br = new BufferedReader(new InputStreamReader(System.in));
// Scanner sc = new Scanner(System.in);
char[] one = in.next().toCharArray(),
two = in.next().toCharArray();
int o = one.length , t = two.length;
int left = 0, right = 0;
int i = -1;
while(i < t-1 && one[++i] == two[i])left++;
i = 0;
while(i < t && one[o-(++i)] == two[t - i])right ++;
//out.println(left + " " + right);
if(left + right < t){
out.println(0);
return;
}
int base = max(o-right , 1) , res = min(left+1 , o);
out.println(res - base + 1);
for(i = 0; i <= res - base ; i++)
out.print(base+i+" ");
}
}
// ||||||| INPUT READER ||||||||
static class InputReader {
private byte[] buf = new byte[8000];
private int index;
private int total;
private InputStream in;
BufferedReader br = new BufferedReader(new InputStreamReader(System.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 long scanlong(){
long 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;
}
private int scanInt() {
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 double scandouble(){
double doubll = 0;
int n = scan();
int neg = 1;
while(isWhiteSpace(n))
n = scan();
if(n == '-'){
neg = -1;
n = scan();
}
while(!isWhiteSpace(n) && n != '.'){
if(n >= '0' && n <= '9'){
doubll *= 10;
doubll += n - '0';
n = scan();
}
}
if(n == '.'){
n = scan();
double temp = 1;
while(!isWhiteSpace(n)){
if(n >= '0' && n <= '9'){
temp /= 10;
doubll += (n - '0')*temp;
n = scan();
}
}
}
return neg*doubll;
}
private float scanfloat() {
float doubll = 0;
int n = scan();
int neg = 1;
while(isWhiteSpace(n))
n = scan();
if(n == '-'){
neg = -1;
n = scan();
}
while(!isWhiteSpace(n) && n != '.'){
if(n >= '0' && n <= '9'){
doubll *= 10;
doubll += n - '0';
n = scan();
}
}
if(n == '.'){
n = scan();
double temp = 1;
while(!isWhiteSpace(n)){
if(n >= '0' && n <= '9'){
temp /= 10;
doubll += (n - '0')*temp;
n = scan();
}
}
}
return neg*doubll;
}
public String scanstring(){
StringBuilder sb = new StringBuilder();
int n = scan();
while(isWhiteSpace(n))
n = scan();
while(!isWhiteSpace(n)){
sb.append((char)n);
n = scan();
}
return sb.toString();
}
public boolean isWhiteSpace(int n){
if(n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
return true;
return false;
}
/// Input module
public int nextInt(){
return scanInt();
}
public long nextLong(){
return scanlong();
}
public double nextDouble(){
return scandouble();
}
public float nextFloat(){
return scanfloat();
}
public String next(){
return scanstring();
}
public String nextLine(){
String S = "";
try {
S = br.readLine();
br.close();
} catch (IOException e) {
e.printStackTrace();
}
return S;
}
public int[] readIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = nextInt();
}
return array;
}
}
} | Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 797f6f3bd7cac30a17ab1e04f13a1fa6 | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import javax.annotation.processing.SupportedSourceVersion;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
public class Main {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = /*new InputReader(new FileReader("input.txt"));*/ new InputReader(inputStream);
PrintWriter out = /*new PrintWriter("output.txt"); */ new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(in, out);
out.close();
}
private static class TaskB {
static final long PRIME = 31;
static final long MAX = 1000000000000000000L;
static final double EPS = 0.0000001;
static final long MOD = 1000000007;
void solve(InputReader in, PrintWriter out) throws IOException {
char A[] = in.nextLine().toCharArray();
char B[] = in.nextLine().toCharArray();
long HA[] = new long[A.length];
long P = PRIME;
HA[0] = (A[0] - 'a') + 1;
for (int i = 1; i < A.length; i++) {
HA[i] = HA[i - 1] + (A[i] - 'a' + 1) * P;
P *= PRIME;
}
long HB = 0;
P = 1;
for (int i = 0; i < B.length; i++) {
HB += (B[i] - 'a' + 1) * P;
P *= 31;
}
int len = A.length;
Queue<Integer> Q = new LinkedList<>();
for (int i = 0; i < len; i++)
if ((i > 0 ? HA[i - 1] : 0) * PRIME + (HA[len - 1] - HA[i]) == HB * PRIME)
Q.add(i + 1);
if (Q.size() == 0) {
out.println(0);
} else {
out.println(Q.size());
out.print(Q.poll());
while (!Q.isEmpty()) out.print(" " + Q.poll());
}
}
long gcd(long A, long B) {
if (B == 0) return A;
return gcd(B, A % B);
}
boolean isPrime(long n) {
if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
return false;
for (long i = 5, j = 2; i * i <= n; i += j, j = 6 - j)
if (n % i == 0)
return false;
return true;
}
boolean isEqual(double A, double B) {
return Math.abs(A - B) < EPS;
}
double dist(double X1, double Y1, double X2, double Y2) {
return Math.sqrt((X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2));
}
boolean nextPer(int[] data) {
int i = data.length - 1;
while (i > 0 && data[i] < data[i - 1]) {
i--;
}
if (i == 0) {
return false;
}
int j = data.length - 1;
while (data[j] < data[i - 1]) {
j--;
}
int temp = data[i - 1];
data[i - 1] = data[j];
data[j] = temp;
Arrays.sort(data, i, data.length);
return true;
}
long pow(long A, long B, long MOD) {
if (B == 0) {
return 1;
}
if (B == 1) {
return A;
}
long val = pow(A, B / 2, MOD);
if (B % 2 == 0) {
return val * val % MOD;
} else {
return val * (val * A % MOD) % MOD;
}
}
}
private static class InputReader {
StringTokenizer st;
BufferedReader br;
public InputReader(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public InputReader(FileReader s) throws FileNotFoundException {
br = new BufferedReader(s);
}
public String next() {
while (st == null || !st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public double nextDouble() {
return Double.parseDouble(next());
}
public boolean ready() {
try {
return br.ready();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
} | Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 8d3170e03c2a36080f5510938622ecd8 | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class A {
public static void main(String[] args) throws IOException
{
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
String s = sc.next(), t = sc.next();
int maxP = 0, maxS = 0, n = t.length();
while(maxP < n && s.charAt(maxP) == t.charAt(maxP))
++maxP;
while(maxS < n && s.charAt(n - maxS) == t.charAt(n - maxS - 1))
++maxS;
out.println(Math.max(0, maxP + maxS - n + 1));
for(int i = n + 1 - maxS; i <= maxP + 1; ++i)
out.print(i + " ");
out.close();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public Scanner(FileReader r){ br = new BufferedReader(r);}
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 { return Double.parseDouble(next()); }
public boolean ready() throws IOException {return br.ready();}
}
} | Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 20909983a875e411e183b8c505e91542 | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class A {
public static void main(String[] args) throws IOException
{
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
String s = sc.next(), t = sc.next();
int maxP = 0, maxS = 0, n = t.length();
while(maxP < n && s.charAt(maxP) == t.charAt(maxP))
++maxP;
while(maxS < n && s.charAt(n - maxS) == t.charAt(n - maxS - 1))
++maxS;
out.println(Math.max(0, maxP + maxS - n + 1));
for(int i = 1; i <= n + 1; ++i)
if(i - 1 <= maxP && n + 1 - i <= maxS)
out.print(i + " ");
out.close();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public Scanner(FileReader r){ br = new BufferedReader(r);}
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 { return Double.parseDouble(next()); }
public boolean ready() throws IOException {return br.ready();}
}
} | Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | c6fb57f6268f2e6aa6c448f5dc85a0a4 | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.util.*;
import java.io.*;
// Solution
public class Main
{
public static void main (String[] argv)
{
new Main();
}
boolean test = false;
public Main() {
FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
//FastReader in = new FastReader(new BufferedReader(new FileReader("Main.in")));
//int n = in.nextInt();
//int m = in.nextInt();
String a = in.next();
String b = in.next();
int n = b.length();
int i = 0;
while (i < n && a.charAt(i) == b.charAt(i)) ++i;
StringBuilder sb = new StringBuilder();
if(test)System.out.println(i);
if(i==n) {
char c = a.charAt(n);
while (i >= 0 && a.charAt(i) == c) --i;
sb.append((n-i) + "\n");
for (++i; i <= n; ++i) sb.append((i+1) + " ");
System.out.println(sb);
return;
}
int j = i;
while (j < n && a.charAt(j+1) == b.charAt(j)) ++j;
if (j < n) {
System.out.println(0);
return;
}
char c = a.charAt(i);
j = i;
while (i >= 0 && a.charAt(i) == c) --i;
sb.append((j-i) + "\n");
for (++i; i <= j; ++i) sb.append((1+i) + " ");
System.out.println(sb);
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader(BufferedReader in)
{
br = in;
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
String line = br.readLine();
if (line == null || line.length() == 0) return "";
st = new StringTokenizer(line);
}
catch (IOException e)
{
return "";
//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)
{
return "";
//e.printStackTrace();
}
return str;
}
}
} | Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 94586d3d9f06323f4bf77231a90f17b8 | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes |
/*
* Author- Priyam Vora
* BTech 2nd Year DAIICT
*/
import java.io.*;
import java.math.*;
import java.net.NetworkInterface;
import java.util.*;
import javax.print.attribute.SetOfIntegerSyntax;
public class CodeMonk_Graph {
private static InputStream stream;
private static byte[] buf = new byte[1024];
private static int curChar;
private static int numChars;
private static SpaceCharFilter filter;
private static PrintWriter pw;
private static long count = 0,mod=1000000007;
private static TreeSet<Integer>ts[]=new TreeSet[200000];
private static HashSet hs=new HashSet();
public static void main(String args[]) throws Exception {
InputReader(System.in);
pw = new PrintWriter(System.out);
//ans();
soln();
pw.close();
}
public static long gcd(long x, long y) {
if (x == 0)
return y;
else
return gcd( y % x,x);
}
private static int BinarySearch(int a[], int low, int high, int target) {
if (low > high)
return -1;
int mid = low + (high - low) / 2;
if (a[mid] == target)
return mid;
if (a[mid] > target)
high = mid - 1;
if (a[mid] < target)
low = mid + 1;
return BinarySearch(a, low, high, target);
}
public static String reverseString(String s) {
StringBuilder sb = new StringBuilder(s);
sb.reverse();
return (sb.toString());
}
public static long pow(long n, long p) {
if(p==0)
return 1;
if(p==1)
return n%mod;
if(p%2==0){
long temp=pow(n, p/2);
return (temp*temp)%mod;
}else{
long temp=pow(n,p/2);
temp=(temp*temp)%mod;
return(temp*n)%mod;
}
}
public static int[] radixSort(int[] f) {
int[] to = new int[f.length];
{
int[] b = new int[65537];
for (int i = 0; i < f.length; i++)
b[1 + (f[i] & 0xffff)]++;
for (int i = 1; i <= 65536; i++)
b[i] += b[i - 1];
for (int i = 0; i < f.length; i++)
to[b[f[i] & 0xffff]++] = f[i];
int[] d = f;
f = to;
to = d;
}
{
int[] b = new int[65537];
for (int i = 0; i < f.length; i++)
b[1 + (f[i] >>> 16)]++;
for (int i = 1; i <= 65536; i++)
b[i] += b[i - 1];
for (int i = 0; i < f.length; i++)
to[b[f[i] >>> 16]++] = f[i];
int[] d = f;
f = to;
to = d;
}
return f;
}
public static int nextPowerOf2(final int a) {
int b = 1;
while (b < a) {
b = b << 1;
}
return b;
}
public static boolean PointInTriangle(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) {
int s = p2 * p5 - p1 * p6 + (p6 - p2) * p7 + (p1 - p5) * p8;
int t = p1 * p4 - p2 * p3 + (p2 - p4) * p7 + (p3 - p1) * p8;
if ((s < 0) != (t < 0))
return false;
int A = -p4 * p5 + p2 * (p5 - p3) + p1 * (p4 - p6) + p3 * p6;
if (A < 0.0) {
s = -s;
t = -t;
A = -A;
}
return s > 0 && t > 0 && (s + t) <= A;
}
public static float area(int x1, int y1, int x2, int y2, int x3, int y3) {
return (float) Math.abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0);
}
public static boolean isPrime(int n) {
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
//merge Sort
static long sort(int a[])
{ int n=a.length;
int b[]=new int[n];
return mergeSort(a,b,0,n-1);}
static long mergeSort(int a[],int b[],long left,long right)
{ long c=0;if(left<right)
{ long mid=left+(right-left)/2;
c= mergeSort(a,b,left,mid);
c+=mergeSort(a,b,mid+1,right);
c+=merge(a,b,left,mid+1,right); }
return c; }
static long merge(int a[],int b[],long left,long mid,long right)
{long c=0;int i=(int)left;int j=(int)mid; int k=(int)left;
while(i<=(int)mid-1&&j<=(int)right)
{ if(a[i]>a[j]) {b[k++]=a[i++]; }
else { b[k++]=a[j++];c+=mid-i;}}
while (i <= (int)mid - 1) b[k++] = a[i++];
while (j <= (int)right) b[k++] = a[j++];
for (i=(int)left; i <= (int)right; i++)
a[i] = b[i]; return c; }
public static boolean isSubSequence(String large, String small, int largeLen, int smallLen) {
//base cases
if (largeLen == 0)
return false;
if (smallLen == 0)
return true;
// If last characters of two strings are matching
if (large.charAt(largeLen - 1) == small.charAt(smallLen - 1))
isSubSequence(large, small, largeLen - 1, smallLen - 1);
// If last characters are not matching
return isSubSequence(large, small, largeLen - 1, smallLen);
}
// To Get Input
// Some Buffer Methods
public static void InputReader(InputStream stream1) {
stream = stream1;
}
private static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private static boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
private static 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 static int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
private static long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
private static String nextToken() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
private static 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();
}
private static int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
private static int[][] next2dArray(int n, int m) {
int[][] arr = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = nextInt();
}
}
return arr;
}
private static char[][] nextCharArray(int n,int m){
char [][]c=new char[n][m];
for(int i=0;i<n;i++){
String s=nextLine();
for(int j=0;j<s.length();j++){
c[i][j]=s.charAt(j);
}
}
return c;
}
private static long[] nextLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
private static void pArray(int[] arr) {
for (int i = 0; i < arr.length; i++) {
pw.print(arr[i] + " ");
}
pw.println();
return;
}
private static void pArray(long[] arr) {
for (int i = 0; i < arr.length; i++) {
pw.print(arr[i] + " ");
}
pw.println();
return;
}
private static void pArray(boolean[] arr) {
for (int i = 0; i < arr.length; i++) {
pw.print(arr[i] + " ");
}
pw.println();
return;
}
private static boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhitespace(c);
}
private interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
//----------------------------------------My Code------------------------------------------------//
private static void soln() {
String s=nextLine();
String s2=nextLine();
long c=0;
ArrayList<Integer> []a=new ArrayList[26];
for(int i=0;i<26;i++){
a[i]=new ArrayList<Integer>();
}
HashSet<Character> hs=new HashSet();
for(int i=0;i<s.length();i++){
hs.add(s.charAt(i));
}
//pw.println(hs.size());
StringBuilder sb=new StringBuilder();
int p1=0,p2=0;
int temp=-1;
int ch=-1;
while(p1<s.length() && p2<s2.length()){
hs.add(s.charAt(p1));
a[s.charAt(p1)-'a'].add(p1);
if(s.charAt(p1)!=s2.charAt(p2)){
temp=p1+1;
sb.append((p1+1));
c++;
p2--;
ch=(p1);
}
if(c>1){
System.out.println(0);
System.exit(0);
}
p1++;
p2++;
}
if(c==0){
if(hs.size()==1){
pw.println(s.length());
for(int i=1;i<=s.length();i++){
pw.print(i+" ");
}
}else{
ArrayList<Integer> ans=new ArrayList<Integer>();
ans.add(s.length());
sb.insert(0, (s.length()+" "));
c++;
for(int i=s.length()-2;i>=0;i--){
if(s.charAt(i)==s.charAt(i+1)){
c++;
ans.add(i+1);
sb.insert(0,(i+1)+" ");
}else{
break;
}
}
Collections.sort(ans);
pw.println(ans.size());
for(int i=0;i<ans.size();i++){
pw.print(ans.get(i)+" ");
}
}
}
else{
ArrayList<Integer> ans=new ArrayList<Integer>();
ans.add(temp);
int index=a[s.charAt(ch)-'a'].indexOf(ch);
for(int j=index-1;j>=0;j--){
if(a[s.charAt(ch)-'a'].get(j)==(a[s.charAt(ch)-'a'].get(j+1)-1)){
ans.add((a[s.charAt(ch)-'a'].get(j)+1));
//sb.insert(0,((a[s.charAt(ch)-'a'].get(j)+1)+" "));
c++;
}else{
break;
}
}
Collections.sort(ans);
pw.println(ans.size());
for(int i=0;i<ans.size();i++){
pw.print(ans.get(i)+" ");
}
}
//-----------------------------------------The End--------------------------------------------------------------------------//
}
}
class Pair implements Comparable<Pair>{
long id;
long w;
long h;
Pair(long id,long w,long h){
this.id=id;
this.w=w;
this.h=h;
}
@Override
public int compareTo(Pair o) {
// TODO Auto-generated method stub
// Sort in increasing order
if(w>o.w){
return 1;
}else if(w<o.w){
return -1;
}else{
if(h>o.h)
return 1;
else if(h<o.h)
return -1;
else
return 0;
}
}
}
class Graph{
private static int V,level[][],count=-1,lev_dfs[],degree=0,no_vert_conn_comp=0;
private Stack <Integer>st=new Stack();
private static LinkedList<Integer > adj[];
private boolean[][] Visite;
private static boolean [] Visited;
private static TreeSet<Integer> ts=new TreeSet();
Graph(int V){
V++;
this.V=(V);
adj=new LinkedList[V];
Visite=new boolean[100][100];
Visited=new boolean[V];
level=new int[100][100];
lev_dfs=new int[V];
for(int i=0;i<V;i++)
adj[i]=new LinkedList<Integer>();
}
void addEdge(int v,int w){
if(adj[v]==null){
adj[v]=new LinkedList();
}
adj[v].add(w);
}
public static int BFS2(int startVert,int dest){
Visited=new boolean[V];
for(int i=1;i<V;i++){
lev_dfs[i]=-1;
}
Queue<Integer> q=new LinkedList<Integer>();
q.add(startVert);
lev_dfs[startVert]=0;
while(!q.isEmpty()){
int top=q.poll();
Iterator<Integer> i= adj[top].listIterator();
while(i.hasNext()){
int n=i.next();
if(!Visited[n]){
q.add(n);
Visited[n]=true;
lev_dfs[n]=lev_dfs[top]+1;
if(n==dest){
q.clear();
return lev_dfs[n];
}
}
}
}
q.clear();
return -1;
}
public int getEd(){
return degree/2;
}
public void get(int from,int to){
int h=lev_dfs[from]-lev_dfs[to];
if(h<=0){
System.out.println(-1);
}else{
System.out.println(h-1);
}
}
private static boolean check(int x,int y,char c[][]){
if((x>=0 && y>=0) && (x<c.length && y<c[0].length) && c[x][y]!='#'){
return true;
}
return false;
}
public int BFS(int x,int y,int k,char[][] c)
{
LinkedList<Pair> queue = new LinkedList<Pair>();
//Visited[s]=true;
// queue.add(new Pair(x,y));
int count=0;
level[x][y]=-1;
c[x][y]='M';
while (!queue.isEmpty())
{
Pair temp = queue.poll();
//x=temp.idx;
//y=temp.val;
c[x][y]='M';
// System.out.println(x+" "+y+" ---"+count);
count++;
if(count==k)
{
for(int i=0;i<c.length;i++){
for(int j=0;j<c[0].length;j++){
if(c[i][j]=='M'){
System.out.print(".");
}
else if(c[i][j]=='.')
System.out.print("X");
else
System.out.print(c[i][j]);
}
System.out.println();
}
System.exit(0);
}
// System.out.println(x+" "+y);
// V--;
}
return V;
}
private void getAns(int startVertex){
for(int i=0;i<adj[startVertex].size();i++){
int ch=adj[startVertex].get(i);
for(int j=0;j<adj[ch].size();j++){
int ch2=adj[ch].get(j);
if(adj[ch2].contains(startVertex)){
System.out.println(startVertex+" "+ch+" "+ch2);
System.exit(0);
}
}
}
}
public long dfs(int startVertex){
// getAns(startVertex);
if(!Visited[startVertex]) {
return dfsUtil(startVertex,Visited);
//return getAns();
}
return 0;
}
private long dfsUtil(int startVertex, boolean[] Visited) {//0-Blue 1-Pink
//System.out.println(startVertex);
int c=1;
long cout=0;
degree=0;
Visited[startVertex]=true;
// lev_dfs[startVertex]=1;
st.push(startVertex);
while(!st.isEmpty()){
int top=st.pop();
Iterator<Integer> i=adj[top].listIterator();
degree+=adj[top].size();
while(i.hasNext()){
// System.out.println(top+" "+adj[top].size());
int n=i.next();
// System.out.print(n+" ");
if( !Visited[n]){
Visited[n]=true;
st.push(n);
// System.out.print(n+" ");
lev_dfs[n]=top;
}
}
// System.out.println("--------------------------------");
}
for(int i=1;i<V;i++){
if(lev_dfs[i]!=0){
System.out.print(lev_dfs[i]+" ");
}
}
return cout;
// System.out.println("NO");
// return c;
}
}
class Dsu{
private int rank[], parent[] ,n;
Dsu(int size){
this.n=size+1;
rank=new int[n];
parent=new int[n];
makeSet();
}
void makeSet(){
for(int i=0;i<n;i++){
parent[i]=i;
}
}
int find(int x){
if(parent[x]!=x){
parent[x]=find(parent[x]);
}
return parent[x];
}
void union(int x,int y){
int xRoot=find(x);
int yRoot=find(y);
if(xRoot==yRoot)
return;
if(rank[xRoot]<rank[yRoot]){
parent[xRoot]=yRoot;
}else if(rank[yRoot]<rank[xRoot]){
parent[yRoot]=xRoot;
}else{
parent[yRoot]=xRoot;
rank[xRoot]++;
}
}
}
class Heap{
public static void build_max_heap(long []a,int size){
for(int i=size/2;i>0;i--){
max_heapify(a, i,size);
}
}
private static void max_heapify(long[] a,int i,int size){
int left_child=2*i;
int right_child=(2*i+1);
int largest=0;
if(left_child<size && a[left_child]>a[i]){
largest=left_child;
}else{
largest=i;
}
if(right_child<size && a[right_child]>a[largest]){
largest=right_child;
}
if(largest!=i){
long temp=a[largest];
a[largest]=a[i];
a[i]=temp;
max_heapify(a, largest,size);
}
}
private static void min_heapify(int[] a,int i){
int left_child=2*i;
int right_child=(2*i+1);
int largest=0;
if(left_child<a.length && a[left_child]<a[i]){
largest=left_child;
}else{
largest=i;
}
if(right_child<a.length && a[right_child]<a[largest]){
largest=right_child;
}
if(largest!=i){
int temp=a[largest];
a[largest]=a[i];
a[i]=temp;
min_heapify(a, largest);
}
}
public static void extract_max(int size,long a[]){
if(a.length>1){
long max=a[1];
a[1]=a[a.length-1];
size--;
max_heapify(a, 1,a.length-1);
}
}
}
class MyComp implements Comparator<Long>{
@Override
public int compare(Long o1, Long o2) {
if(o1<o2){
return 1;
}else if(o1>o2){
return -1;
}
return 0;
}
}
| Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 411ece17be3e1a71baabefca35adc93c | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main1 {
public static InputReader in;
public static PrintWriter pw;
public static void main(String args[]) {
new Thread(null, new Runnable() {
public void run() {
try{
solve();
}
catch(Exception e){
e.printStackTrace();
}
}
}, "1", 1 << 26).start();
}
static TreeSet<Integer> set;
static ArrayList<Integer> g[];
static boolean visited[];
static long edje=0;
static boolean vis[];
static int parent[];
static int col[];
static boolean[] vis1;
static int Ans=0;
static int min=Integer.MAX_VALUE;
static int val[];
static int degree[];
static int a[];
static int f[];
static long total=0;
public static void solve(){
in = new InputReader(System.in);
pw = new PrintWriter(System.out);
//int n=in.nextInt();
HashMap<Integer,int []> hm=new HashMap<Integer,int []>();
String s1=in.readString();
String s2=in.readString();
char a[]=s1.toCharArray();
char b[]=s2.toCharArray();
HashSet<Character> ss1=new HashSet<Character>();
HashSet<Character> ss2=new HashSet<Character>();
for(int i=0;i<s1.length();i++)
{
ss1.add(s1.charAt(i));
}
for(int i=0;i<s2.length();i++)
{
ss1.add(s2.charAt(i));
}
if(ss1.size()==1&&ss2.size()==1)
{
StringBuilder fuck=new StringBuilder();
System.out.println(s1.length());
for(int i=0;i<s1.length();i++)
{
fuck.append((i+1)+" ");
}
System.out.println(fuck.toString());
System.exit(0);
}
boolean sip1[]=new boolean[s1.length()+1];
int c=0;
for(int i=0;i<s2.length();i++)
{
if(a[i]==b[i])
c++;
if(c==(i+1))
sip1[i]=true;
}
boolean sip2[]=new boolean[s1.length()+1];
c=0;
int cnt=1;
for(int i=s1.length()-1;i>0;i--)
{
// System.out.println(a[i]+" "+b[i-1]);
if(a[i]==b[i-1])
{
c++;
}
if(c==(cnt))
{
sip2[i]=true;
}
cnt++;
}
int count=0;
StringBuilder ans=new StringBuilder();
int fm=0;
for(int i=1;i<s1.length();i++)
{
if(a[i]==b[i-1])
count++;
}
if(count==s2.length()){
ans.append(1+" ");fm++;}
count=0;
for(int i=1;i<s2.length();i++)
{
if(sip1[i-1]&&sip2[i+1]){
ans.append((i+1)+" ");
count++;
fm++;
}
}
count=0;
for(int i=0;i<s2.length();i++)
{
if(a[i]==b[i])
count++;
}
if(count==s2.length()){
ans.append((s2.length()+1)+" ");fm++;}
System.out.println(fm);
System.out.println(ans);
}
public static void dfs1(int curr,int parent)
{
val[curr]=a[curr];
for(int x:g[curr])
{
if(x!=parent)
{
dfs1(x,curr);
val[curr]+=val[x];
}
}
}
public static void dfs2(int curr,int parent)
{
f[curr]=val[curr];
for(int x:g[curr])
{
if(x!=parent)
{
dfs2(x,curr);
f[curr]+=f[x];
}
}
}
public static long power(long a,long b)
{
long result=1;
while(b>0)
{
if(b%2==1)
result*=a;
a=a*a;
b/=2;
}
return result;
}
public static long pow(long n,long p,long m)
{
long result = 1;
if(p==0)
return 1;
if (p==1)
return n;
while(p!=0)
{
if(p%2==1)
result *= n;
if(result>=m)
result%=m;
p >>=1;
n*=n;
if(n>=m)
n%=m;
}
return result;
}
static class Pair implements Comparable<Pair>{
int ind;
long val;
Pair(int mr,long er){
ind=mr;
val=er;
}
@Override
public int compareTo(Pair o) {
return 1;
}
}
public static long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a%b);
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public InputReader(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 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 = 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);
}
}
} | Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 2f5249e5e9559081512e9bf5387b7d0a | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static InputReader in;
public static PrintWriter pw;
public static void main(String args[]) {
new Thread(null, new Runnable() {
public void run() {
try{
solve();
}
catch(Exception e){
e.printStackTrace();
}
}
}, "1", 1 << 26).start();
}
static TreeSet<Integer> set;
static ArrayList<Integer> g[];
static boolean visited[];
static long edje=0;
static boolean vis[];
static int parent[];
static int col[];
static boolean[] vis1;
static int Ans=0;
static int min=Integer.MAX_VALUE;
static int val[];
static int degree[];
static int a[];
static int f[];
static long total=0;
public static void solve(){
in = new InputReader(System.in);
pw = new PrintWriter(System.out);
//int n=in.nextInt();
HashMap<Integer,int []> hm=new HashMap<Integer,int []>();
String s1=in.readString();
String s2=in.readString();
char a[]=s1.toCharArray();
char b[]=s2.toCharArray();
HashSet<Character> ss1=new HashSet<Character>();
HashSet<Character> ss2=new HashSet<Character>();
for(int i=0;i<s1.length();i++)
{
ss1.add(s1.charAt(i));
}
for(int i=0;i<s2.length();i++)
{
ss1.add(s2.charAt(i));
}
if(ss1.size()==1&&ss2.size()==1)
{
StringBuilder fuck=new StringBuilder();
System.out.println(s1.length());
for(int i=0;i<s1.length();i++)
{
fuck.append((i+1)+" ");
}
System.out.println(fuck.toString());
System.exit(0);
}
boolean sip1[]=new boolean[s1.length()+1];
int c=0;
for(int i=0;i<s2.length();i++)
{
if(a[i]==b[i])
c++;
if(c==(i+1))
sip1[i]=true;
}
boolean sip2[]=new boolean[s1.length()+1];
c=0;
int cnt=1;
for(int i=s1.length()-1;i>0;i--)
{
// System.out.println(a[i]+" "+b[i-1]);
if(a[i]==b[i-1])
{
c++;
}
if(c==(cnt))
{
sip2[i]=true;
}
cnt++;
}
int count=0;
StringBuilder ans=new StringBuilder();
int fm=0;
for(int i=1;i<s1.length();i++)
{
if(a[i]==b[i-1])
count++;
}
if(count==s2.length()){
ans.append(1+" ");fm++;}
count=0;
for(int i=1;i<s2.length();i++)
{
if(sip1[i-1]&&sip2[i+1]){
ans.append((i+1)+" ");
count++;
fm++;
}
}
count=0;
for(int i=0;i<s2.length();i++)
{
if(a[i]==b[i])
count++;
}
if(count==s2.length()){
ans.append((s2.length()+1)+" ");fm++;}
System.out.println(fm);
System.out.println(ans);
}
public static void dfs1(int curr,int parent)
{
val[curr]=a[curr];
for(int x:g[curr])
{
if(x!=parent)
{
dfs1(x,curr);
val[curr]+=val[x];
}
}
}
public static void dfs2(int curr,int parent)
{
f[curr]=val[curr];
for(int x:g[curr])
{
if(x!=parent)
{
dfs2(x,curr);
f[curr]+=f[x];
}
}
}
/* public static void dfs2(int curr)
{
if(st[col[curr]].isEmpty())
{
ans[curr]=-1;
}
else
{
ans[curr]=st[col[curr]].peek();
}
st[col[curr]].push(curr);
for(int x:g[curr])
{
dfs2(x);
}
st[col[curr]].pop();
}
public static void dfs1(int curr)
{
visited[curr]=true;
for(int next:g[curr])
{
edje++;
if(!visited[next])
dfs1(next);
}
}
public static void dfs(int curr,int prev)
{
val[curr]=1;
for(int x:g[curr])
{
if(x!=prev)
{
dfs(x,curr);
val[curr]+=val[x];
}
}
}*/
public static long power(long a,long b)
{
long result=1;
while(b>0)
{
if(b%2==1)
result*=a;
a=a*a;
b/=2;
}
return result;
}
public static long pow(long n,long p,long m)
{
long result = 1;
if(p==0)
return 1;
if (p==1)
return n;
while(p!=0)
{
if(p%2==1)
result *= n;
if(result>=m)
result%=m;
p >>=1;
n*=n;
if(n>=m)
n%=m;
}
return result;
}
static class Pair implements Comparable<Pair>{
int ind;
long val;
Pair(int mr,long er){
ind=mr;
val=er;
}
@Override
public int compareTo(Pair o) {
return 1;
}
}
public static long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a%b);
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public InputReader(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 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 = 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);
}
}
}
| Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | f7623e2d9fc46cb20e391614467dfc7a | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import sun.reflect.generics.tree.Tree;
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;
public class Main implements Runnable {
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
public static void main(String args[]) throws Exception {
new Thread(null, new Main(), "Main", 1 << 26).start();
}
long modPow(long a, long p, long m) {
if (a == 1) return 1;
long ans = 1;
while (p > 0) {
if (p % 2 == 1) ans = (ans * a) % m;
a = (a * a) % m;
p >>= 1;
}
return ans;
}
long modInv(long a, long m) {
return modPow(a, m - 2, m);
}
long gcd(long a,long b){
if(b==0)return a;
return gcd(b,a%b);
}
PrintWriter out;
InputReader sc;
public void run() {
sc = new InputReader(System.in);
// Scanner sc=new Scanner(System.in);
// Random sc=new Random();
out = new PrintWriter(System.out);
String aa = sc.next();
String bb = sc.next();
char a[] = new char[aa.length() + 1];
char b[] = new char[bb.length() + 1];
for (int i = 0; i < aa.length(); i++) {
a[i + 1] = aa.charAt(i);
}
for (int i = 0; i < bb.length(); i++) {
b[i + 1] = bb.charAt(i );
}
int n = a.length - 1;
int m = b.length - 1;
long hashA[] = new long[n + 1];
long hashB[] = new long[m + 1];
long pow[] = new long[Math.max(n + 1, m + 1)];
long p = 1, mod = 1000000007;
for (int i = 0; i < Math.max(n + 1, m + 1); i++) {
pow[i] = p;
p = (p * 26) % mod;
}
for (int i = 1; i <= n; i++) {
hashA[i] = ((hashA[i - 1] * 26) + (a[i] - 'a')) % mod;
}
for (int i = 1; i <= m; i++) {
hashB[i] = ((hashB[i - 1] * 26) + (b[i] - 'a')) % mod;
}
ArrayList<Integer> l = new ArrayList<>();
for (int i = 1; i <= n; i++) {
long temp = (hashA[n]-(hashA[i]*pow[n-(i+1)+1])%mod + (hashA[i - 1] * pow[n - (i + 1) + 1]) % mod) % mod;
temp=(temp+mod)%mod;
if (temp == hashB[m]) {
l.add(i);
}
}
out.println(l.size());
for (int x : l) {
out.print(x + " ");
}
out.close();
}
} | Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | f689f569895f83485960bac077b3954c | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Quan2202
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
String s = in.next();
String s1 = in.next();
int count = 1;
int i = 0;
int TF = 1;
for (i = 0; i < s1.length(); i++) {
if (s1.charAt(i) != s.charAt(i)) {
if (i == 0) {
s = s.substring(1);
} else {
s = s.substring(0, i) + s.substring(i + 1);
}
if (!s.equals(s1)) {
TF = 0;
} else {
}
break;
} else {
if (s.charAt(i) == s.charAt(i + 1)) {
count++;
} else {
count = 1;
}
}
}
if (TF == 0) {
out.print(0);
} else {
out.println(count);
for (int j = i - count + 2; j <= i + 1; j++) {
out.print(j + " ");
}
}
out.flush();
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 3813f6b5d22a5189ec0f15e30f09d9df | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.io.*;
import java.util.*;
public class MyClass {
public static void main(String args[]) throws Exception{
//Scanner scanner = new Scanner(System.in);
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s1 = in.readLine();
String s2 = in.readLine();
in.close();
int start = 0, end = 0;
char lastchar = s1.charAt(0);
int idx = 0;
boolean ex = false;
for (int i = 0, j = 0; i < s1.length(); i++){
char c1 = s1.charAt(i);
if(j < s2.length() && c1 == s2.charAt(j)){
j++;
if(c1 != lastchar){
lastchar = c1;
idx = i;
}
}
else if (ex == false){
if(c1 != lastchar){
start = i;
end = i;
ex = true;
}
else{
start = idx;
end = i;
ex = true;
}
}
else{ // ex = true;
end = -1;
break;
}
}
if(end == -1){
System.out.println(0);
}
else{
System.out.println(end-start+1);
StringBuffer output = new StringBuffer();
for (; start <= end; start++){
output.append((start+1) + " ");
}
System.out.println(output);
}
}
}
| Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | b210307aa6141ae02bc3ac1d66a68fe7 | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.io.Writer;
import java.util.List;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Alex
*/
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);
TaskJ solver = new TaskJ();
solver.solve(1, in, out);
out.close();
}
}
class TaskJ {
public void solve(int testNumber, InputReader in, OutputWriter out){
String first = in.next(), second = in.next();
SimpleStringHash fsh1 = new SimpleStringHash(first), fsh2 = new SimpleStringHash(second);
ArrayList<Integer> res = new ArrayList<>();
for(int i = 0; i < first.length(); i++) {
if((i == 0 || fsh1.hash(0, i) == fsh2.hash(0, i)) && fsh1.hash(i + 1) == fsh2.hash(i)){
res.add(i);
}
}
out.printLine(res.size());
for(int i : res) out.print((i+1) + " ");
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c))
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void close() {
writer.close();
}
public void printLine(int i) {
writer.println(i);
}
}
class SimpleStringHash extends AbstractStringHash {
private static long[] firstReversePower = new long[0];
private static long[] secondReversePower = new long[0];
private final long[] firstHash;
private final long[] secondHash;
public SimpleStringHash(CharSequence string) {
int length = string.length();
ensureCapacity(length);
firstHash = new long[length + 1];
secondHash = new long[length + 1];
long firstPower = 1;
long secondPower = 1;
for (int i = 0; i < length; i++) {
firstHash[i + 1] = (firstHash[i] + string.charAt(i) * firstPower) % FIRST_MOD;
secondHash[i + 1] = (secondHash[i] + string.charAt(i) * secondPower) % SECOND_MOD;
firstPower *= MULTIPLIER;
firstPower %= FIRST_MOD;
secondPower *= MULTIPLIER;
secondPower %= SECOND_MOD;
}
}
private void ensureCapacity(int length) {
if (firstReversePower.length >= length)
return;
length = Math.max(length + 1, firstReversePower.length << 1);
long[] oldFirst = firstReversePower;
long[] oldSecond = secondReversePower;
firstReversePower = new long[length];
secondReversePower = new long[length];
System.arraycopy(oldFirst, 0, firstReversePower, 0, oldFirst.length);
System.arraycopy(oldSecond, 0, secondReversePower, 0, oldSecond.length);
firstReversePower[0] = secondReversePower[0] = 1;
for (int i = Math.max(oldFirst.length, 1); i < length; i++) {
firstReversePower[i] = firstReversePower[i - 1] * FIRST_REVERSE_MULTIPLIER % FIRST_MOD;
secondReversePower[i]= secondReversePower[i - 1] * SECOND_REVERSE_MULTIPLIER % SECOND_MOD;
}
}
public long hash(int from, int to) {
return (((firstHash[to] - firstHash[from] + FIRST_MOD) * firstReversePower[from] % FIRST_MOD) << 32) +
((secondHash[to] - secondHash[from] + SECOND_MOD) * secondReversePower[from] % SECOND_MOD);
}
public int length() {
return firstHash.length - 1;
}
}
abstract class AbstractStringHash implements StringHash {
public static final long MULTIPLIER;
protected static final long FIRST_REVERSE_MULTIPLIER;
protected static final long SECOND_REVERSE_MULTIPLIER;
public static final long FIRST_MOD;
public static final long SECOND_MOD;
static {
Random random = new Random(System.currentTimeMillis());
FIRST_MOD = IntegerUtils.nextPrime((long) (1e9 + random.nextInt((int) 1e9)));
SECOND_MOD = IntegerUtils.nextPrime((long) (1e9 + random.nextInt((int) 1e9)));
MULTIPLIER = random.nextInt((int) 1e9 - 257) + 257;
FIRST_REVERSE_MULTIPLIER = IntegerUtils.reverse(MULTIPLIER, FIRST_MOD);
SECOND_REVERSE_MULTIPLIER = IntegerUtils.reverse(MULTIPLIER, SECOND_MOD);
}
public long hash(int from) {
return hash(from, length());
}
}
interface StringHash {
long hash(int from, int to);
int length();
}
class IntegerUtils {
public static long power(long base, long exponent, long mod) {
if (base >= mod)
base %= mod;
if (exponent == 0)
return 1 % mod;
long result = power(base, exponent >> 1, mod);
result = result * result % mod;
if ((exponent & 1) != 0)
result = result * base % mod;
return result;
}
public static long reverse(long number, long module) {
return power(number, module - 2, module);
}
public static boolean isPrime(long number) {
if (number < 2)
return false;
for (long i = 2; i * i <= number; i++) {
if (number % i == 0)
return false;
}
return true;
}
public static long nextPrime(long from) {
if (from <= 2)
return 2;
from += 1 - (from & 1);
while (!isPrime(from))
from += 2;
return from;
}
}
| Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | b6be4ce36ecd198e8f66eecb2a85b3fa | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Alex
*/
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);
TaskJ solver = new TaskJ();
solver.solve(1, in, out);
out.close();
}
}
class TaskJ {
public void solve(int testNumber, InputReader in, OutputWriter out){
String first = in.next(), second = in.next();
FastStringHash fsh1 = new FastStringHash(first), fsh2 = new FastStringHash(second);
ArrayList<Integer> res = new ArrayList<>();
for(int i = 0; i < first.length(); i++) {
if((i == 0 || fsh1.hash(0, i) == fsh2.hash(0, i)) && fsh1.hash(i + 1) == fsh2.hash(i)){
res.add(i);
}
}
out.printLine(res.size());
for(int i : res) out.print((i+1) + " ");
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c))
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void close() {
writer.close();
}
public void printLine(int i) {
writer.println(i);
}
}
class FastStringHash{
private final long MULTIPLIER = 43;
private final long REVERSE_MULTIPLIER = BigInteger.valueOf(MULTIPLIER).modInverse(BigInteger.valueOf(2).pow(64)).longValue();
private final long[] hash;
private final long[] reversePower;
public FastStringHash(CharSequence string) {
hash = new long[string.length() + 1];
long power = 1;
reversePower = new long[hash.length];
reversePower[0] = 1;
for (int i = 0; i < hash.length - 1; i++) {
hash[i + 1] = hash[i] + string.charAt(i) * power;
power *= MULTIPLIER;
reversePower[i + 1] = reversePower[i] * REVERSE_MULTIPLIER;
}
}
public long hash(int from, int to) {
return (hash[to] - hash[from]) * reversePower[from];
}
public long hash(int from) {
return hash(from, hash.length - 1);
}
}
| Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 101a979c6b56c533e9b1bd825749168c | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Collections;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author John Martin
*/
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);
JSpellingCheck solver = new JSpellingCheck();
solver.solve(1, in, out);
out.close();
}
static class JSpellingCheck {
public void solve(int testNumber, InputReader c, OutputWriter w) {
char s1[] = c.readString().toCharArray(), s2[] = c.readString().toCharArray();
ArrayList<Integer> res = new ArrayList<>();
int ptr2 = 0;
for (int i = 0; i < s1.length; i++) {
if (ptr2 == s2.length || s1[i] != s2[ptr2]) {
int j = i;
while (j >= 0 && s1[i] == s1[j]) {
res.add(j + 1);
j--;
}
} else {
ptr2++;
}
}
Collections.sort(res);
if (ptr2 == s2.length) {
w.printLine(res.size());
for (int i : res) {
w.print(i + " ");
}
w.printLine();
} else {
w.printLine(0);
}
}
}
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 String readString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c)) {
res.appendCodePoint(c);
}
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void printLine() {
writer.println();
}
public void close() {
writer.close();
}
public void printLine(int i) {
writer.println(i);
}
}
}
| Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 5391f7b431bc0e1dffe209ab2b288292 | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
/**
* #
*
* @author pttrung
*/
public class J_SchoolTeamContest_1 {
public static long MOD = 1000000007;
public static void main(String[] args) throws FileNotFoundException {
// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
// "output.txt")));
PrintWriter out = new PrintWriter(System.out);
Scanner in = new Scanner();
String a = in.next();
String b = in.next();
ArrayList<Entry> x = new ArrayList();
ArrayList<Entry> y = new ArrayList();
int s = -1;
char last = 0;
for (int i = 0; i < a.length(); i++) {
if (s == -1) {
s = i;
} else if (a.charAt(i) != last) {
x.add(new Entry(s, i - 1, last));
s = i;
}
last = a.charAt(i);
}
x.add(new Entry(s, a.length() - 1, last));
s = -1;
last = 0;
for (int i = 0; i < b.length(); i++) {
if (s == -1) {
s = i;
} else if (b.charAt(i) != last) {
y.add(new Entry(s, i - 1, last));
s = i;
}
last = b.charAt(i);
}
y.add(new Entry(s, b.length() - 1, last));
// System.out.println(x);
boolean ok = true;
int i = 0;
int j = 0;
int total = -1;
s = -1;
int e = -1;
while (i < x.size() && j < y.size()) {
int n = x.get(i).e - x.get(i).s + 1;
int m = y.get(j).e - y.get(j).s + 1;
//System.out.println(x.get(i) + " " + y.get(j));
if (n == m && x.get(i).c == y.get(j).c) {
i++;
j++;
} else if (x.get(i).c == y.get(j).c) {
if (n < m) {
if (i + 2 < x.size()) {
if (x.get(i + 2).c == y.get(j).c) {
int k = (x.get(i + 2).e - x.get(i + 2).s + 1);
if (k + n == m) {
int h = (x.get(i + 1).e - x.get(i + 1).s + 1);
if (h == 1) {
if (total == -1) {
total = h;
s = x.get(i + 1).s;
e = x.get(i + 1).e;
} else {
ok = false;
break;
}
i += 3;
j++;
} else {
ok = false;
break;
}
} else {
ok = false;
break;
}
} else {
ok = false;
break;
}
} else {
ok = false;
break;
}
} else if (n == m + 1) {
if (total == -1) {
total = n;
s = x.get(i).s;
e = x.get(i).e;
} else {
ok = false;
break;
}
i++;
j++;
} else {
ok = false;
break;
}
} else {
if (n == 1) {
if (total == -1) {
total = n;
s = x.get(i).s;
e = x.get(i).e;
} else {
ok = false;
break;
}
i++;
} else {
ok = false;
break;
}
}
}
if (ok) {
if (j == y.size() && i + 1 == x.size()) {
int n = x.get(i).e - x.get(i).s + 1;
if (n == 1) {
if (total == -1) {
total = n;
s = x.get(i).s;
e = x.get(i).e;
} else {
ok = false;
}
} else {
ok = false;
}
}
}
// System.out.println(ok);
if (!ok) {
out.println(0);
} else {
out.println(total);
for (i = s; i <= e; i++) {
out.print((i + 1) + " ");
}
}
out.close();
}
static class Entry {
int s, e;
char c;
public Entry(int s, int e, char c) {
super();
this.s = s;
this.e = e;
this.c = c;
}
@Override
public String toString() {
return "Entry [s=" + s + ", e=" + e + ", c=" + c + "]";
}
}
public static int[] KMP(String val) {
int i = 0;
int j = -1;
int[] result = new int[val.length() + 1];
result[0] = -1;
while (i < val.length()) {
while (j >= 0 && val.charAt(j) != val.charAt(i)) {
j = result[j];
}
j++;
i++;
result[i] = j;
}
return result;
}
public static boolean nextPer(int[] data) {
int i = data.length - 1;
while (i > 0 && data[i] < data[i - 1]) {
i--;
}
if (i == 0) {
return false;
}
int j = data.length - 1;
while (data[j] < data[i - 1]) {
j--;
}
int temp = data[i - 1];
data[i - 1] = data[j];
data[j] = temp;
Arrays.sort(data, i, data.length);
return true;
}
public static int digit(long n) {
int result = 0;
while (n > 0) {
n /= 10;
result++;
}
return result;
}
public static double dist(long a, long b, long x, long y) {
double val = (b - a) * (b - a) + (x - y) * (x - y);
val = Math.sqrt(val);
double other = x * x + a * a;
other = Math.sqrt(other);
return val + other;
}
public static class Point implements Comparable<Point> {
int x, y;
public Point(int start, int end) {
this.x = start;
this.y = end;
}
@Override
public int hashCode() {
int hash = 5;
hash = 47 * hash + this.x;
hash = 47 * hash + this.y;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Point other = (Point) obj;
if (this.x != other.x) {
return false;
}
if (this.y != other.y) {
return false;
}
return true;
}
@Override
public int compareTo(Point o) {
return x - o.x;
}
}
public static class FT {
long[] data;
FT(int n) {
data = new long[n];
}
public void update(int index, long value) {
while (index < data.length) {
data[index] += value;
index += (index & (-index));
}
}
public long get(int index) {
long result = 0;
while (index > 0) {
result += data[index];
index -= (index & (-index));
}
return result;
}
}
public static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
public static long pow(long a, long b) {
if (b == 0) {
return 1;
}
if (b == 1) {
return a;
}
long val = pow(a, b / 2);
if (b % 2 == 0) {
return val * val % MOD;
} else {
return val * (val * a % MOD) % MOD;
}
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner() throws FileNotFoundException {
// System.setOut(new PrintStream(new
// BufferedOutputStream(System.out), true));
br = new BufferedReader(new InputStreamReader(System.in));
// br = new BufferedReader(new InputStreamReader(new
// FileInputStream(new File("input.txt"))));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
throw new RuntimeException();
}
}
return st.nextToken();
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
st = null;
try {
return br.readLine();
} catch (Exception e) {
throw new RuntimeException();
}
}
public boolean endLine() {
try {
String next = br.readLine();
while (next != null && next.trim().isEmpty()) {
next = br.readLine();
}
if (next == null) {
return true;
}
st = new StringTokenizer(next);
return st.hasMoreTokens();
} catch (Exception e) {
throw new RuntimeException();
}
}
}
}
| Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 195c3da257de6b91f877e4c9ae615f6e | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | //package prac;
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 P39J {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
char[] s = ns().toCharArray();
char[] t = ns().toCharArray();
int L = 0;
for(int i = 0;i < t.length;i++){
if(s[i] == t[i]){
L++;
}else{
break;
}
}
int R = s.length;
for(int i = 0;i < t.length;i++){
if(s[s.length-1-i] == t[t.length-1-i]){
R--;
}else{
break;
}
}
if(L >= R-1){
out.println(L-R+2);
for(int i = R-1;i <= L;i++){
out.print((i+1) + " ");
}
}else{
out.println(0);
}
}
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 P39J().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 | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 409c762d6bdff55238f5d5bc96684d0f | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.io.*;
import java.util.*;
public class J implements Runnable {
public static void main (String[] args) {new Thread(null, new J(), "_cf", 1 << 28).start();}
public void run() {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
System.err.println("Go!");
String s1 = fs.next();
String s2 = fs.next();
int[] z1 = zValues(s2 + "#" + s1);
int[] z2 = zValues(reverse(s2) + "#" + reverse(s1));
z1 = Arrays.copyOfRange(z1, s2.length()+1, z1.length);
z2 = Arrays.copyOfRange(z2, s2.length()+1, z2.length);
for(int i = 0, j = z2.length-1; i < j; i++, j--) {
int temp = z2[i];
z2[i] = z2[j];
z2[j] = temp;
}
int n = s1.length();
int[] res = new int[n];
int ptr = 0;
for(int i = 0; i <= z1[0]; i++) {
//delete this string?
int left = s2.length() - i;
if(z2[z2.length-1] >= left) {
res[ptr++] = i+1;
}
}
out.println(ptr);
for(int i = 0; i < ptr; i++) out.print(res[i] + " ");
out.println();
out.close();
}
String reverse(String s) {
return new StringBuilder(s).reverse().toString();
}
int[] zValues(String string) {
int n = string.length(); char[] s = string.toCharArray();
int[] z = new int[n]; z[0] = n;
int L = 0, R = 0;
int[] left = new int[n], right = new int[n];
for(int i = 1; i < n; ++i) {
if(i > R) {
L = R = i;
while(R < n && s[R-L] == s[R]) R++;
z[i] = R - L; R--;
} else {
int k = i-L;
if(z[k] < R-i+1) z[i] = z[k];
else {
L = i;
while(R < n && s[R-L] == s[R]) R++;
z[i] = R - L; R--;
}
}
left[i] = L; right[i] = R;
}
return z;
}
class FastScanner {
public int BS = 1<<16;
public char NC = (char)0;
byte[] buf = new byte[BS];
int bId = 0, size = 0;
char c = NC;
double num = 1;
BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) throws FileNotFoundException {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
}
public char nextChar(){
while(bId==size) {
try {
size = in.read(buf);
}catch(Exception e) {
return NC;
}
if(size==-1)return NC;
bId=0;
}
return (char)buf[bId++];
}
public int nextInt() {
return (int)nextLong();
}
public long nextLong() {
num=1;
boolean neg = false;
if(c==NC)c=nextChar();
for(;(c<'0' || c>'9'); c = nextChar()) {
if(c=='-')neg=true;
}
long res = 0;
for(; c>='0' && c <='9'; c=nextChar()) {
res = (res<<3)+(res<<1)+c-'0';
num*=10;
}
return neg?-res:res;
}
public double nextDouble() {
double cur = nextLong();
return c!='.' ? cur:cur+nextLong()/num;
}
public String next() {
StringBuilder res = new StringBuilder();
while(c<=32)c=nextChar();
while(c>32) {
res.append(c);
c=nextChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while(c<=32)c=nextChar();
while(c!='\n') {
res.append(c);
c=nextChar();
}
return res.toString();
}
public boolean hasNext() {
if(c>32)return true;
while(true) {
c=nextChar();
if(c==NC)return false;
else if(c>32)return true;
}
}
public int[] nextIntArray(int n) {
int[] res = new int[n];
for(int i = 0; i < n; i++) res[i] = nextInt();
return res;
}
}
} | Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 8c0610270eb513a2374291559b5b119a | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
//Scanner in = new Scanner(System.in);
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String error = in.readLine();
String optimal = in.readLine();
optimal += '1';
int n = optimal.length();
in.close();
int flag = 0;
int count = 0;
int startSymbol = 0;
int start = -1, finish = -1;
for(int i = 0; count < n; i ++, count ++) {
if(error.charAt(count) != error.charAt(startSymbol)) {
startSymbol = count;
}
if(error.charAt(count) != optimal.charAt(i)) {
if(flag == 1 && i != n - 1) {
start = -1;
finish = -1;
flag = -1;
break;
}
flag = 1;
finish = count + 1;
i --;
start = startSymbol + 1;
}
}
if(start == -1 && finish == -1) {
System.out.println(0);
}
else {
System.out.println(finish - start + 1);
StringBuffer output = new StringBuffer();
for (; start <= finish; start ++){
output.append((start) + " ");
}
System.out.println(output);
}
}
} | Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | c752689e50d91ec1708af7c91ada64ce | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
//Scanner in = new Scanner(System.in);
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String error = in.readLine();
String optimal = in.readLine();
int n = error.length();
in.close();
boolean flag = false;
char startSymbol = error.charAt(0);
int indStartSymbol = 0;
int start = -1, finish = -1;
int j = 0;
for(int i = 0; i < n; i ++) {
char cur = error.charAt(i);
if(j < n - 1 && cur == optimal.charAt(j)) {
if(startSymbol != cur) {
startSymbol = cur;
indStartSymbol = i;
}
j ++;
}
else
if(!flag) {
if(cur == startSymbol) {
start = indStartSymbol;
finish = i;
}
else {
start = i;
finish = i;
}
flag = true;
}
else {
start = -1;
finish = -1;
break;
}
}
if(start == -1 && finish == -1) {
System.out.println(0);
}
else {
System.out.println(finish - start + 1);
StringBuffer output = new StringBuffer();
for (; start <= finish; start ++){
output.append((start + 1) + " ");
}
System.out.println(output);
}
}
} | Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | da87ff0440f47ca7c5ed86db6bf9a087 | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
/**
* 39J
* ΞΈ(|s|) time
* ΞΈ(|s|) space
*
* @author artyom
*/
public class _39J implements Runnable {
private BufferedReader in;
private StringTokenizer tok;
private Object solve() throws IOException {
String s = nextToken(), t = nextToken();
int i = 0, n = t.length();
while (i < n && s.charAt(i) == t.charAt(i)) {
i++;
}
for (int j = i + 1; j <= n; j++) {
if (s.charAt(j) != t.charAt(j - 1)) {
return 0;
}
}
char x = s.charAt(i);
int j = i - 1;
while (j >= 0 && s.charAt(j) == x) {
j--;
}
StringBuilder sb = new StringBuilder().append(i - j).append('\n');
while (++j <= i) {
sb.append(j + 1).append(' ');
}
return sb;
}
//--------------------------------------------------------------
public static void main(String[] args) {
new _39J().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();
}
} | Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 12925b241870cf687c07a677ed25f085 | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.util.*;
public class SpellingCheck39J {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s1 = scanner.next();
String s2 = scanner.next();
if(s1.length() == 1 && s2.length() == 0) {
System.out.println("1");
System.out.println("1");
}
int i = 0;
int left = 0;
while(left < s2.length() && s1.charAt(i) == s2.charAt(left)) {
i++;
left++;
}
int j = s1.length() - 1;
int right = s2.length() - 1;
while(right >= 0 && s1.charAt(j) == s2.charAt(right)) {
j--;
right--;
}
if(right - left < 0) {
System.out.println("" + (left-right));
right++;
StringBuilder sb = new StringBuilder();
while(right <= left) {
sb.append((right+1) + " ");
//System.out.print((right+1) + " ");
right++;
}
System.out.println(sb.toString());
}
else {
System.out.println("0");
}
}
} | Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 8 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 2544dfcb02f4e7fd17af0ab76b2260a7 | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes |
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author madis
*/
public class CheckGramar {
public static void main(String[] args) throws FileNotFoundException {
Scanner in = new Scanner(System.in);
String a = in.next();
String b = in.next();
int i = 0;
char c = a.charAt(0);
long len = 0;
while (i < b.length() && a.charAt(i) == b.charAt(i)) {
if (a.charAt(i) == c) {
len++;
} else {
len = 1;
c = a.charAt(i);
}
i++;
}
if (a.charAt(i) == c) {
len++;
} else {
len = 1;
}
for (int j = i; j < b.length(); j++) {
if (a.charAt(j + 1) != b.charAt(j)) {
System.out.println(0);
return;
}
}
System.out.println(len);
for (long k = i - len + 1; k <= i; k++) {
System.out.print((k + 1) + " ");
}
}
}
| Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 6 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | dbf59c47ad5c81ef434df6f7eed41c4c | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 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.Locale;
import java.util.StringTokenizer;
public class Main {
void solve() throws IOException {
char[] s1 = next().toCharArray();
char[] s2 = next().toCharArray();
int k = 0;
while ((k < s2.length) && (s1[k] == s2[k])) {
k++;
}
// out.println("MAX common preffix len = " + k);
if ((k < s2.length) && (s1[k + 1] != s2[k])) {
out.println(0);
} else {
int kk = (k < s2.length) ? k + 1 : k;
while ((kk < s2.length) && (s1[kk + 1] == s2[kk])) {
kk++;
}
if (kk == s2.length) {
int ans = 0;
char ch = s1[k];
ArrayList<Integer> pos = new ArrayList<Integer>();
while ((k >= 0) && (s1[k] == ch)) {
ans++;
pos.add(k + 1);
k--;
}
out.println(ans);
for (int i = ans - 1; i >= 0; i--) {
out.print(pos.get(i) + " ");
}
} else {
out.println(0);
}
}
}
private BufferedReader in;
private PrintWriter out;
private StringTokenizer st;
Main() throws IOException {
Locale.setDefault(Locale.US);
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
eat("");
solve();
in.close();
out.close();
}
private void eat(String str) {
st = new StringTokenizer(str);
}
String next() throws IOException {
while (!st.hasMoreTokens()) {
String line = in.readLine();
if (line == null) {
return null;
}
eat(line);
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static void main(String[] args) throws IOException {
new Main();
}
} | Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 6 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | 4f10a9b9541f7339181d85420fae8162 | train_002.jsonl | 1287904200 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | 256 megabytes | import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Scanner;
public class J implements Runnable {
private Scanner in;
private PrintWriter out;
private void solve() {
char[] s = in.next().toCharArray();
char[] t = in.next().toCharArray();
long mul = 37, MOD = 1L << 40, h2 = 0;
for (int i = 0; i < t.length; ++i) {
h2 = (h2 * mul + t[i] - 'a' + 1) % MOD;
}
long[] pow = new long[s.length];
long cur = 1;
for (int i = 0; i < s.length; ++i) {
pow[i] = cur;
cur = (cur * mul) % MOD;
}
long[] sumsl = new long[s.length];
cur = 0;
for (int i = 0; i < s.length - 1; ++i) {
cur = (cur + pow[s.length - 2 - i] * (s[i] - 'a' + 1)) % MOD;
sumsl[i] = cur;
}
long[] sumsr = new long[s.length];
cur = 0;
for (int i = s.length - 1; i >= 0; --i) {
cur = (cur + pow[s.length - 1 - i] * (s[i] - 'a' + 1)) % MOD;
sumsr[i] = cur;
}
ArrayList<Integer> ans = new ArrayList<Integer>();
for (int i = 0; i < s.length; ++i) {
cur = 0;
if (i + 1 < s.length) {
cur = sumsr[i + 1];
}
if (i - 1 >= 0) {
cur = (cur + sumsl[i - 1]) % MOD;
}
if (cur == h2) {
ans.add(i + 1);
}
}
out.println(ans.size());
for (int i: ans) {
out.print(i + " ");
}
}
@Override
public void run() {
Locale.setDefault(Locale.US);
in = new Scanner(System.in);
out = new PrintWriter(System.out);
solve();
in.close();
out.close();
}
public static void main(String[] args) {
new J().run();
}
}
| Java | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | 2 seconds | ["1\n3", "2\n1 2", "0"] | null | Java 6 | standard input | [
"implementation",
"hashing",
"strings"
] | 0df064fd0288c2ac4832efa227107a0e | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | 1,500 | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | standard output | |
PASSED | cc6426538515ce8a69c14e1790dfa778 | train_002.jsonl | 1312390800 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? | 265 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class summRazr {
static public int count=0;
static public String b="";
static private int countInc(String s,int l){
if (s.length()==1){
return l;
}
else {
Integer y = 0,x=0;
for (int i=0; i<s.length();i++){
x=Integer.parseInt(s.substring(s.length()-i-1,s.length()-i));
y+=x;
}
count++;
//System.out.println(y);
countInc(y.toString(),l);
return l;
}
}
static public void main (String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
b=br.readLine();
countInc(b, count);
System.out.println(count);
}
}
| Java | ["0", "10", "991"] | 2 seconds | ["0", "1", "3"] | NoteIn the first sample the number already is one-digit β Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991βββ19βββ10βββ1. After three transformations the number becomes one-digit. | Java 6 | standard input | [
"implementation"
] | ddc9201725e30297a5fc83f4eed75fc9 | The first line contains the only integer n (0ββ€βnββ€β10100000). It is guaranteed that n doesn't contain any leading zeroes. | 1,000 | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | standard output | |
PASSED | e5a3c28f2b9032bf2b39dbcfd38469e4 | train_002.jsonl | 1312390800 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? | 265 megabytes | import java.util.Scanner;
public class SumOfDigits {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String k = scan.nextLine();
System.out.println(numberOfTurns(k));
}
private static int numberOfTurns(String k) {
String theNumber = k;
int sum = 0, counter = 0;
while (theNumber.length() != 1) {
counter++;
for (int i = 0; i < theNumber.length(); i++)
sum += Integer.parseInt("" + theNumber.charAt(i));
theNumber = "" + sum;
sum = 0;
}
return counter;
}
}
| Java | ["0", "10", "991"] | 2 seconds | ["0", "1", "3"] | NoteIn the first sample the number already is one-digit β Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991βββ19βββ10βββ1. After three transformations the number becomes one-digit. | Java 6 | standard input | [
"implementation"
] | ddc9201725e30297a5fc83f4eed75fc9 | The first line contains the only integer n (0ββ€βnββ€β10100000). It is guaranteed that n doesn't contain any leading zeroes. | 1,000 | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | standard output | |
PASSED | 2120e29cc23dbc348bf056d31281e5ea | train_002.jsonl | 1312390800 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? | 265 megabytes | import java.util.Scanner;
/**
* Date: 01.12.11
* Time: 10:41
*/
public class B79 {
public static void main(String[] args) {
String t = new Scanner(System.in).nextLine();
if (t.length()==1) {
System.out.println(0);
return;
}
int n = 0;
for (int i = 0; i < t.length(); i++) {
n+=(t.charAt(i)-'0');
}
int c = 1;
while (n >= 10) {
c++;
int tn = 0;
while (n > 0) {
tn+=n%10;
n/=10;
}
n = tn;
}
System.out.println(c);
}
}
| Java | ["0", "10", "991"] | 2 seconds | ["0", "1", "3"] | NoteIn the first sample the number already is one-digit β Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991βββ19βββ10βββ1. After three transformations the number becomes one-digit. | Java 6 | standard input | [
"implementation"
] | ddc9201725e30297a5fc83f4eed75fc9 | The first line contains the only integer n (0ββ€βnββ€β10100000). It is guaranteed that n doesn't contain any leading zeroes. | 1,000 | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | standard output | |
PASSED | 91a15f018015fbd2885c2a035c31148a | train_002.jsonl | 1312390800 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? | 265 megabytes | import java.io.*;
import java.util.*;
public class cf{
public static void main(String args[]) throws IOException{
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
String s = f.readLine();
int ans = 0;
while(s.length()>1){
++ans;
s = op(s);
}
System.out.println(ans);
}
static String op(String s){
int num = 0;
for(int i = 0; i < s.length(); ++i){
int dig = Integer.parseInt(s.substring(i,i+1));
num += dig;
}
return "" + num;
}
} | Java | ["0", "10", "991"] | 2 seconds | ["0", "1", "3"] | NoteIn the first sample the number already is one-digit β Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991βββ19βββ10βββ1. After three transformations the number becomes one-digit. | Java 6 | standard input | [
"implementation"
] | ddc9201725e30297a5fc83f4eed75fc9 | The first line contains the only integer n (0ββ€βnββ€β10100000). It is guaranteed that n doesn't contain any leading zeroes. | 1,000 | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | standard output | |
PASSED | 0f7ec95b6c8ce4c951bd627547e64a40 | train_002.jsonl | 1312390800 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? | 265 megabytes | import java.util.Scanner;
public class SumOfDigits{
public static void main(String [] args){
Scanner input = new Scanner(System.in);
String masuk = input.nextLine();
int temp = 0;
int sum = 0;
int count = 0;
while (masuk.length()>1){
sum = 0;
for(int i = 0; i<masuk.length();i++){
String dummy = masuk.substring(i,i+1);
temp = Integer.parseInt(dummy);
sum = sum +temp;
}
masuk = Integer.toString(sum);
count++;
}
System.out.println(count);
}
} | Java | ["0", "10", "991"] | 2 seconds | ["0", "1", "3"] | NoteIn the first sample the number already is one-digit β Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991βββ19βββ10βββ1. After three transformations the number becomes one-digit. | Java 6 | standard input | [
"implementation"
] | ddc9201725e30297a5fc83f4eed75fc9 | The first line contains the only integer n (0ββ€βnββ€β10100000). It is guaranteed that n doesn't contain any leading zeroes. | 1,000 | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | standard output | |
PASSED | 6e1ac3f7f585cc6550e9aa8cdb985db5 | train_002.jsonl | 1312390800 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? | 265 megabytes | import java.math.BigInteger;
import java.util.Scanner;
public class B {
private void solve() {
while(sc.hasNext()) {
//BigInteger b = new BigInteger(sc.nextLine());
String s = sc.nextLine();
int n = 0;
long b = 0;
if(s.length()>1) {
n++;
int size = s.length();
for(int i=0;i<size;i++) b+= s.charAt(i)-'0';
}
/* while(b.compareTo(BigInteger.TEN)>=0) {
b = new BigInteger(String.valueOf(sum(b)));
n++;
if(n>0) break;
}*/
// long bb = b.longValue();
long bb = b;
while(bb>=10) {
bb = sum(bb);
n++;
}
System.out.println(n);
}
}
private long sum(BigInteger b) {
long ret = 0;
while(b.compareTo(BigInteger.TEN)>=0) {
ret += b.mod(BigInteger.TEN).intValue();
b = b.divide(BigInteger.TEN);
}
return ret + b.intValue();
}
private long sum(long b) {
long ret = 0;
while(b>=10) {
ret += b%10;
b/=10;
}
return ret+b;
}
Scanner sc = new Scanner(System.in);
public static void main(String[] args) { new B().solve(); }
} | Java | ["0", "10", "991"] | 2 seconds | ["0", "1", "3"] | NoteIn the first sample the number already is one-digit β Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991βββ19βββ10βββ1. After three transformations the number becomes one-digit. | Java 6 | standard input | [
"implementation"
] | ddc9201725e30297a5fc83f4eed75fc9 | The first line contains the only integer n (0ββ€βnββ€β10100000). It is guaranteed that n doesn't contain any leading zeroes. | 1,000 | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | standard output | |
PASSED | 35f799f7b61e78bd41be49322a96d996 | train_002.jsonl | 1312390800 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? | 265 megabytes | import java.io.IOException;
import java.util.Scanner;
public class B102 {
public static void main(String[] args) throws IOException {
Scanner sc=new Scanner(System.in);
String s1=sc.next();
int n=0,l=0,i=0,x=0,j=0,k=s1.length();
String s;
for(int u=0;u<k;u++)
{n=n+(s1.charAt(u)-'0');
i++;
}/*while(true)
{
if(c=='\n') break;
n+=c-'0';
i++;
c=(char)System.in.read();
System.out.println(c);
}*/
int t=0;
if(i==1)
{
System.out.println("0");
System.exit(0);
}
x=0;
do
{
s=Integer.toString(n);
i=s.length();
char a[]=s.toCharArray();
n=0;
for(j=0;j<i;j++)
n+=a[j]-'0';
x++;
}while(i>1);
System.out.println(x);
}
} | Java | ["0", "10", "991"] | 2 seconds | ["0", "1", "3"] | NoteIn the first sample the number already is one-digit β Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991βββ19βββ10βββ1. After three transformations the number becomes one-digit. | Java 6 | standard input | [
"implementation"
] | ddc9201725e30297a5fc83f4eed75fc9 | The first line contains the only integer n (0ββ€βnββ€β10100000). It is guaranteed that n doesn't contain any leading zeroes. | 1,000 | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | standard output | |
PASSED | bc1f5981d28df087bec11f87e65a28a1 | train_002.jsonl | 1312390800 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? | 265 megabytes |
import java.util.*;
public class Main{
public static void main(String[]args)throws Exception{
Scanner in = new Scanner(System.in);
String s = in.next();
if(s.length() == 1){
System.out.println(0);
}else{
int count = 0;
while(true){
count++;
if((""+sum(s)).length() == 1){
break;
}
s = ((""+sum(s)));
}
System.out.println(count);
}
}
public static int sum(String s){
int summa = 0;
for(int i=0;i<s.length();i++){
summa+=((int)s.charAt(i)-48);
}
return summa;
}
} | Java | ["0", "10", "991"] | 2 seconds | ["0", "1", "3"] | NoteIn the first sample the number already is one-digit β Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991βββ19βββ10βββ1. After three transformations the number becomes one-digit. | Java 6 | standard input | [
"implementation"
] | ddc9201725e30297a5fc83f4eed75fc9 | The first line contains the only integer n (0ββ€βnββ€β10100000). It is guaranteed that n doesn't contain any leading zeroes. | 1,000 | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | standard output | |
PASSED | 347c0f8fdebd03d68999713977f08027 | train_002.jsonl | 1312390800 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? | 265 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
public class Task {
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
//br = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter(new OutputStreamWriter(System.out));
new Task().run();
out.close();
}
static BufferedReader br;
static PrintWriter out;
StringTokenizer st;
static String taskName = "";
String nline() {
try {
return br.readLine();
} catch (Exception exc) {
return null;
}
}
String ns() {
try {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(nline());
}
return st.nextToken();
} catch (Exception exc) {
return null;
}
}
int ni() {
return Integer.valueOf(ns());
}
double nd() {
return Double.valueOf(ns());
}
void pf(String format, Object ... obj) {
out.printf(format, obj);
}
void pln() {
out.println();
}
void pt(Object obj) {
out.print(obj);
}
void run() {
//Place your code here
String s = ns();
int ans = 0;
while (s.length() > 1) {
int sum = 0;
for (char ch : s.toCharArray()) {
sum += ch - '0';
}
s = Integer.toString(sum);
ans++;
}
out.print(ans);
}
} | Java | ["0", "10", "991"] | 2 seconds | ["0", "1", "3"] | NoteIn the first sample the number already is one-digit β Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991βββ19βββ10βββ1. After three transformations the number becomes one-digit. | Java 6 | standard input | [
"implementation"
] | ddc9201725e30297a5fc83f4eed75fc9 | The first line contains the only integer n (0ββ€βnββ€β10100000). It is guaranteed that n doesn't contain any leading zeroes. | 1,000 | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | standard output | |
PASSED | 47da73894df8885e780ccd21097a4562 | train_002.jsonl | 1558884900 | Toad Rash has a binary string $$$s$$$. A binary string consists only of zeros and ones.Let $$$n$$$ be the length of $$$s$$$.Rash needs to find the number of such pairs of integers $$$l$$$, $$$r$$$ that $$$1 \leq l \leq r \leq n$$$ and there is at least one pair of integers $$$x$$$, $$$k$$$ such that $$$1 \leq x, k \leq n$$$, $$$l \leq x < x + 2k \leq r$$$, and $$$s_x = s_{x+k} = s_{x+2k}$$$.Find this number of pairs for Rash. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class fast implements Runnable {
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
}
catch (IOException e) {
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class pair implements Comparable<pair>{
int x,y;
pair(int xi, int yi){
x=xi;
y=yi;
}
@Override
public int compareTo(pair other){
if(this.x>other.x){return 1;}
if(this.x<other.x){return -1;}
if(this.y>other.y){return 1;}
if(this.y<other.y){return -1;}
return 0;
}
}
class dist implements Comparable<dist>{
int x,y,z;
dist(int xi, int yi, int zi){
x=xi;
y=yi;
z=zi;
}
@Override
public int compareTo(dist other){
if(this.z>other.z){return 1;}
if(this.z<other.z){return -1;}
return 0;
}
}
public static void main(String args[]) throws Exception {
new Thread(null, new fast(),"fast",1<<26).start();
}
public void sortbyColumn(int arr[][], final int col){
// Using built-in sort function Arrays.sort
Arrays.sort(arr, new Comparator<int[]>() {
@Override
// Compare values according to columns
public int compare(final int[] entry1, final int[] entry2) {
// To sort in descending order revert
// the '>' Operator
if (entry1[col] > entry2[col])
return 1;
if(entry1[col] < entry2[col])
return -1;
return 0;
}
}); // End of function call sort().
}
public void sortbyColumn(long arr[][], final int col){
// Using built-in sort function Arrays.sort
Arrays.sort(arr, new Comparator<long[]>() {
@Override
// Compare values according to columns
public int compare(final long[] entry1, final long[] entry2) {
// To sort in descending order revert
// the '>' Operator
if (entry1[col] > entry2[col])
return 1;
if(entry1[col] < entry2[col])
return -1;
return 0;
}
}); // End of function call sort().
}
public void sort(int ar[]){
int n=ar.length;
Integer arr[]=new Integer[n];
for(int i=0;i<n;i++){
arr[i]=ar[i];
}
Arrays.sort(arr);
for(int i=0;i<n;i++){
ar[i]=arr[i].intValue();
}
}
public void sort(long ar[]){
int n=ar.length;
Long arr[]=new Long[n];
for(int i=0;i<n;i++){
arr[i]=ar[i];
}
Arrays.sort(arr);
for(int i=0;i<n;i++){
ar[i]=arr[i].longValue();
}
}
long power(long x, long y, long p){
long res = 1;
x = x % p;
while (y > 0)
{
if((y & 1)==1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
public void run(){
InputReader s = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
char c[]=s.next().toCharArray();
int n=c.length,r[]=new int[n];
if(n<3){
w.println(0);w.flush();return;
}
long ans=0;
r[n-2]=n;
for(int l=n-3;l>=0;l--){
r[l]=r[l+1];
for(int k=1;l+2*k<r[l];k++){
if(c[l]==c[l+k] && c[l]==c[l+2*k]){
r[l]=l+2*k;
}
}ans+=n-r[l];
}w.println(ans);
w.close();
}
} | Java | ["010101", "11001100"] | 4 seconds | ["3", "0"] | NoteIn the first example, there are three $$$l$$$, $$$r$$$ pairs we need to count: $$$1$$$, $$$6$$$; $$$2$$$, $$$6$$$; and $$$1$$$, $$$5$$$.In the second example, there are no values $$$x$$$, $$$k$$$ for the initial string, so the answer is $$$0$$$. | Java 8 | standard input | [
"two pointers",
"brute force"
] | 71bace75df1279ae55a6e755159d4191 | The first line contains the string $$$s$$$ ($$$1 \leq |s| \leq 300\,000$$$), consisting of zeros and ones. | 1,900 | Output one integer: the number of such pairs of integers $$$l$$$, $$$r$$$ that $$$1 \leq l \leq r \leq n$$$ and there is at least one pair of integers $$$x$$$, $$$k$$$ such that $$$1 \leq x, k \leq n$$$, $$$l \leq x < x + 2k \leq r$$$, and $$$s_x = s_{x+k} = s_{x+2k}$$$. | standard output | |
PASSED | 620564462835c954692bc382fdf59760 | train_002.jsonl | 1558884900 | Toad Rash has a binary string $$$s$$$. A binary string consists only of zeros and ones.Let $$$n$$$ be the length of $$$s$$$.Rash needs to find the number of such pairs of integers $$$l$$$, $$$r$$$ that $$$1 \leq l \leq r \leq n$$$ and there is at least one pair of integers $$$x$$$, $$$k$$$ such that $$$1 \leq x, k \leq n$$$, $$$l \leq x < x + 2k \leq r$$$, and $$$s_x = s_{x+k} = s_{x+2k}$$$.Find this number of pairs for Rash. | 256 megabytes | import java.util.*;
import java.io.*;
public class CF1168B
{
public static void main(String[] args) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();
char[] c=s.toCharArray();
int n=s.length(),r=n;
long sum=0;
for(int i=n-1;i>=0;i--){
for(int j=1;(i+j*2)<r;j++){
if(c[i]==c[i+j]&&c[i+j]==c[i+2*j])
r=(i+2*j);
}
sum+=n-r;
}
System.out.println(sum);
}
} | Java | ["010101", "11001100"] | 4 seconds | ["3", "0"] | NoteIn the first example, there are three $$$l$$$, $$$r$$$ pairs we need to count: $$$1$$$, $$$6$$$; $$$2$$$, $$$6$$$; and $$$1$$$, $$$5$$$.In the second example, there are no values $$$x$$$, $$$k$$$ for the initial string, so the answer is $$$0$$$. | Java 8 | standard input | [
"two pointers",
"brute force"
] | 71bace75df1279ae55a6e755159d4191 | The first line contains the string $$$s$$$ ($$$1 \leq |s| \leq 300\,000$$$), consisting of zeros and ones. | 1,900 | Output one integer: the number of such pairs of integers $$$l$$$, $$$r$$$ that $$$1 \leq l \leq r \leq n$$$ and there is at least one pair of integers $$$x$$$, $$$k$$$ such that $$$1 \leq x, k \leq n$$$, $$$l \leq x < x + 2k \leq r$$$, and $$$s_x = s_{x+k} = s_{x+2k}$$$. | standard output | |
PASSED | 9a9ba3259b5fa5e4e37c5531a9099543 | train_002.jsonl | 1558884900 | Toad Rash has a binary string $$$s$$$. A binary string consists only of zeros and ones.Let $$$n$$$ be the length of $$$s$$$.Rash needs to find the number of such pairs of integers $$$l$$$, $$$r$$$ that $$$1 \leq l \leq r \leq n$$$ and there is at least one pair of integers $$$x$$$, $$$k$$$ such that $$$1 \leq x, k \leq n$$$, $$$l \leq x < x + 2k \leq r$$$, and $$$s_x = s_{x+k} = s_{x+2k}$$$.Find this number of pairs for Rash. | 256 megabytes | import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Created on 5/11/2017.
*/
public class B {
Scanner sc;
PrintWriter pw;
void run() throws FileNotFoundException {
// sc = new Scanner(new File("D.txt"));
sc = new Scanner(System.in);
pw = new PrintWriter(System.out);
// int[] a = new int[100];
// int k = 9;
// int count = 0;
// for (int ii = 0; ii < (1 << k); ii++) {
// for (int i = 0; i < k; i++) {
// a[i] = (ii / (1 << i)) % 2;
// }
//
// boolean good = false;
// for (int i = 0; i < k; i++) {
// for (int s = 1; i + 2 * s < k; s++) {
// if (a[i] == a[i + s] && a[i] == a[i + 2 * s]) {
// good = true;
// break;
// }
// }
// }
// if (!good) {
// for (int i = 0; i < k; i++) {
// System.out.print(a[i] + " ");
// }
// System.out.println();
// count++;
//// System.exit(0);
// }
// }
// System.out.println(count + " bad possibilities");
// System.exit(0);
String str = sc.next();
char[] a = str.toCharArray();
long n = a.length;
long nBad = 0;
for (int i = 0; i < n; i++) {
for (int len = 1; len < 9; len++) {
if (i + len > n) {
break;
}
boolean hasTriplet = false;
for (int i0 = i; i0 < i + len && !hasTriplet; i0++) {
for (int s = 1; i0 + 2 * s < i + len; s++) {
if (a[i0] == a[i0 + s] && a[i0] == a[i0 + 2 * s]) {
hasTriplet = true;
break;
}
}
}
if (!hasTriplet) {
nBad++;
}
}
}
long nGood = n * (n + 1) / 2 - nBad;
pw.println(nGood);
pw.close();
}
public static void main(String[] args) throws FileNotFoundException {
B sol = new B();
sol.run();
}
}
| Java | ["010101", "11001100"] | 4 seconds | ["3", "0"] | NoteIn the first example, there are three $$$l$$$, $$$r$$$ pairs we need to count: $$$1$$$, $$$6$$$; $$$2$$$, $$$6$$$; and $$$1$$$, $$$5$$$.In the second example, there are no values $$$x$$$, $$$k$$$ for the initial string, so the answer is $$$0$$$. | Java 8 | standard input | [
"two pointers",
"brute force"
] | 71bace75df1279ae55a6e755159d4191 | The first line contains the string $$$s$$$ ($$$1 \leq |s| \leq 300\,000$$$), consisting of zeros and ones. | 1,900 | Output one integer: the number of such pairs of integers $$$l$$$, $$$r$$$ that $$$1 \leq l \leq r \leq n$$$ and there is at least one pair of integers $$$x$$$, $$$k$$$ such that $$$1 \leq x, k \leq n$$$, $$$l \leq x < x + 2k \leq r$$$, and $$$s_x = s_{x+k} = s_{x+2k}$$$. | standard output | |
PASSED | fc90a49dd5a3b405a4cfe7ca66eaa889 | train_002.jsonl | 1558884900 | Toad Rash has a binary string $$$s$$$. A binary string consists only of zeros and ones.Let $$$n$$$ be the length of $$$s$$$.Rash needs to find the number of such pairs of integers $$$l$$$, $$$r$$$ that $$$1 \leq l \leq r \leq n$$$ and there is at least one pair of integers $$$x$$$, $$$k$$$ such that $$$1 \leq x, k \leq n$$$, $$$l \leq x < x + 2k \leq r$$$, and $$$s_x = s_{x+k} = s_{x+2k}$$$.Find this number of pairs for Rash. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]) {new Main().run();}
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
void run(){
out.println(work());
out.flush();
}
long mod=1000000007;
long gcd(long a,long b) {
return b==0?a:gcd(b,a%b);
}
long work() {
String str=in.next();
long n=str.length();
long ret=(n+1)*n/2;
for(int i=0,j=0;i<n;i++) {
out:
while(j<n) {
for(int k=j-2;k>=i;k-=2) {
if(str.charAt(j)==str.charAt((j+k)/2)&&str.charAt(j)==str.charAt(k)) {
break out;
}
}
j++;
}
ret-=j-i;
}
return ret;
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
public String next()
{
if(st==null || !st.hasMoreElements())
{
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt()
{
return Integer.parseInt(next());
}
public long nextLong()
{
return Long.parseLong(next());
}
} | Java | ["010101", "11001100"] | 4 seconds | ["3", "0"] | NoteIn the first example, there are three $$$l$$$, $$$r$$$ pairs we need to count: $$$1$$$, $$$6$$$; $$$2$$$, $$$6$$$; and $$$1$$$, $$$5$$$.In the second example, there are no values $$$x$$$, $$$k$$$ for the initial string, so the answer is $$$0$$$. | Java 8 | standard input | [
"two pointers",
"brute force"
] | 71bace75df1279ae55a6e755159d4191 | The first line contains the string $$$s$$$ ($$$1 \leq |s| \leq 300\,000$$$), consisting of zeros and ones. | 1,900 | Output one integer: the number of such pairs of integers $$$l$$$, $$$r$$$ that $$$1 \leq l \leq r \leq n$$$ and there is at least one pair of integers $$$x$$$, $$$k$$$ such that $$$1 \leq x, k \leq n$$$, $$$l \leq x < x + 2k \leq r$$$, and $$$s_x = s_{x+k} = s_{x+2k}$$$. | standard output | |
PASSED | f4c8abc0023673ece7374b7c7030fc1d | train_002.jsonl | 1558884900 | Toad Rash has a binary string $$$s$$$. A binary string consists only of zeros and ones.Let $$$n$$$ be the length of $$$s$$$.Rash needs to find the number of such pairs of integers $$$l$$$, $$$r$$$ that $$$1 \leq l \leq r \leq n$$$ and there is at least one pair of integers $$$x$$$, $$$k$$$ such that $$$1 \leq x, k \leq n$$$, $$$l \leq x < x + 2k \leq r$$$, and $$$s_x = s_{x+k} = s_{x+2k}$$$.Find this number of pairs for Rash. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author aryssoncf
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
static class TaskB {
final int THRESHOLD = 9;
public void solve(int testNumber, Scanner in, PrintWriter out) {
try {
String str = in.next();
long res = 0;
for (int i = 0; i < str.length(); i++) {
if (i + THRESHOLD <= str.length()) {
res += str.length() - i - THRESHOLD + 1;
}
for (int j = 1; j < THRESHOLD && i + j <= str.length(); j++) {
if (has(str.substring(i, i + j))) {
res++;
}
}
}
out.println(res);
} catch (Exception e) {
}
}
boolean has(String str) {
for (int k = 1; k <= str.length(); k++) {
for (int i = 0; i + 2 * k < str.length(); i++) {
if (str.charAt(i + k) == str.charAt(i) && str.charAt(i + 2 * k) == str.charAt(i)) {
return true;
}
}
}
return false;
}
}
}
| Java | ["010101", "11001100"] | 4 seconds | ["3", "0"] | NoteIn the first example, there are three $$$l$$$, $$$r$$$ pairs we need to count: $$$1$$$, $$$6$$$; $$$2$$$, $$$6$$$; and $$$1$$$, $$$5$$$.In the second example, there are no values $$$x$$$, $$$k$$$ for the initial string, so the answer is $$$0$$$. | Java 8 | standard input | [
"two pointers",
"brute force"
] | 71bace75df1279ae55a6e755159d4191 | The first line contains the string $$$s$$$ ($$$1 \leq |s| \leq 300\,000$$$), consisting of zeros and ones. | 1,900 | Output one integer: the number of such pairs of integers $$$l$$$, $$$r$$$ that $$$1 \leq l \leq r \leq n$$$ and there is at least one pair of integers $$$x$$$, $$$k$$$ such that $$$1 \leq x, k \leq n$$$, $$$l \leq x < x + 2k \leq r$$$, and $$$s_x = s_{x+k} = s_{x+2k}$$$. | standard output | |
PASSED | 85dab4cd44d01970a52b3932243f577d | train_002.jsonl | 1558884900 | Toad Rash has a binary string $$$s$$$. A binary string consists only of zeros and ones.Let $$$n$$$ be the length of $$$s$$$.Rash needs to find the number of such pairs of integers $$$l$$$, $$$r$$$ that $$$1 \leq l \leq r \leq n$$$ and there is at least one pair of integers $$$x$$$, $$$k$$$ such that $$$1 \leq x, k \leq n$$$, $$$l \leq x < x + 2k \leq r$$$, and $$$s_x = s_{x+k} = s_{x+2k}$$$.Find this number of pairs for Rash. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
static class TaskB {
int MAX_DELTA = 12;
public void solve(int testNumber, InputReader in, PrintWriter out) {
String s = in.next();
int[] r = new int[s.length()];
for (int i = 0; i < s.length(); ++i) {
r[i] = s.length();
for (int j = 1; j <= MAX_DELTA && i + 2 * j < s.length(); ++j) {
if (s.charAt(i) == s.charAt(i + j) && s.charAt(i) == s.charAt(i + 2 * j)) {
r[i] = i + 2 * j;
break;
}
}
}
int sofar = s.length();
long res = 0;
for (int i = s.length() - 1; i >= 0; --i) {
sofar = Math.min(sofar, r[i]);
res += s.length() - sofar;
}
out.println(res);
}
}
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();
}
}
}
| Java | ["010101", "11001100"] | 4 seconds | ["3", "0"] | NoteIn the first example, there are three $$$l$$$, $$$r$$$ pairs we need to count: $$$1$$$, $$$6$$$; $$$2$$$, $$$6$$$; and $$$1$$$, $$$5$$$.In the second example, there are no values $$$x$$$, $$$k$$$ for the initial string, so the answer is $$$0$$$. | Java 8 | standard input | [
"two pointers",
"brute force"
] | 71bace75df1279ae55a6e755159d4191 | The first line contains the string $$$s$$$ ($$$1 \leq |s| \leq 300\,000$$$), consisting of zeros and ones. | 1,900 | Output one integer: the number of such pairs of integers $$$l$$$, $$$r$$$ that $$$1 \leq l \leq r \leq n$$$ and there is at least one pair of integers $$$x$$$, $$$k$$$ such that $$$1 \leq x, k \leq n$$$, $$$l \leq x < x + 2k \leq r$$$, and $$$s_x = s_{x+k} = s_{x+2k}$$$. | standard output | |
PASSED | 5ca234e5dca6a8c912c0c1acd22ab34f | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.lang.*;
import java.io.*;
import java.util.*;
public class Diverse {
public static void main(String[] args) throws java.lang.Exception {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(in, out);
out.close();
}
}
class TaskA {
public void solve(InputReader in, PrintWriter out) {
int n = in.nextInt(), k = in.nextInt();
int i, j;
int[] ans = new int[n+1];
int o, e;
ans[1] = n;
o = n - 1;
e = 1;
for (i=2; k>1; ++i,--k) {
if ((i&1) > 0) {
ans[i] = o--;
} else {
ans[i] = e++;
}
}
if ((i&1) > 0) {
for (; i<=n; ++i)
ans[i] = e++;
} else {
for (; i<=n; ++i)
ans[i] = o--;
}
for (i=1; i<=n; ++i)
out.print(ans[i] + " ");
out.println();
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public Long nextLong() {
return Long.parseLong(next());
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | d6d1071ed861e6732ef28495a0ce63a3 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
private static void solve(InputReader in, OutputWriter out) {
int n, k;
n = in.nextInt();
k = in.nextInt();
int left, right;
left = 0;
right = 2 + k;
while (true) {
left++;
if (left == right)break;
out.print(left + " ");
right--;
if (right == left) break;
out.print(right + " ");
}
for (int i = 2 + k; i <= n; i++)
out.print(i + " ");
}
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
OutputWriter out = new OutputWriter(System.out);
solve(in, out);
in.close();
out.close();
}
private static class InputReader {
private BufferedReader br;
private StringTokenizer st;
InputReader(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
st = null;
}
String nextLine() {
String line = null;
try {
line = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return line;
}
String next() {
while (st == null || !st.hasMoreTokens()) {
String line = nextLine();
if (line == null)
return null;
st = new StringTokenizer(line);
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
void close() {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static class OutputWriter {
BufferedWriter bw;
OutputWriter(OutputStream os) {
bw = new BufferedWriter(new OutputStreamWriter(os));
}
void print(int i) {
print(Integer.toString(i));
}
void println(int i) {
print(i);
print('\n');
}
void print(long l) {
print(Long.toString(l));
}
void println(long l) {
print(l);
print('\n');
}
void print(double d) {
print(Double.toString(d));
}
void println(double d) {
print(d);
print('\n');
}
void print(boolean b) {
print(Boolean.toString(b));
}
void println(boolean b) {
print(b);
print('\n');
}
void print(char c) {
try {
bw.write(c);
} catch (IOException e) {
e.printStackTrace();
}
}
void println(char c) {
print(c);
print('\n');
}
void print(String s) {
try {
bw.write(s);
} catch (IOException e) {
e.printStackTrace();
}
}
void println(String s) {
print(s);
print('\n');
}
void close() {
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | a9435d2a7cf05bfaada5ac5f559f6352 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes |
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Rinat
*/
public class C275A {
public static void main(String... args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = (i + 1);
}
List ll = new ArrayList();
int c = k;
for (int i=0; i<k;i++) {
ll.add(arr[i]);
arr[i] = 0;
ll.add(arr[i + c]);
arr[i + c] = 0;
c-=2;
if (c <=0 ) break;
}
for (int i : arr) {
if (i != 0) {
ll.add(i);
}
}
for (Object object : ll) {
System.out.print(object + " ");
}
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | ddea513233c50b36791f853200c7eec6 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.*;
/**
*
* @author greggy
*/
public class DiversePermutation {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int a = 1;
System.out.print(1 + " ");
for (int i = 2; i <= n; i++) {
while (k > 0) {
if (i % 2 == 0) {
a = a + k;
System.out.print(a);
System.out.print(" ");
} else {
a = a - k;
System.out.print(a);
System.out.print(" ");
}
k--;
i++;
}
if (k == 0) {
k--;
i--;
continue;
}
System.out.print(i);
System.out.print(" ");
}
System.out.println();
in.close();
}
} | Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 63d4be44810f9d7901bd184251ad025c | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Nguyen Trung Hieu - vuondenthanhcong11@gmail.com
*/
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) {
int count = in.readInt();
int k = in.readInt();
int sign = 1;
boolean flag = false;
int[] answer = new int[count];
for (int i = 0; i < count; i++) {
answer[i] = i + 1;
if (flag) {
answer[i] = sign * k + answer[i - 1];
sign *= -1;
k--;
}
if (answer[i] + sign * k == count)
flag = true;
}
out.printLine(answer);
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public 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 OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public void print(int[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(array[i]);
}
}
public void printLine(int[] array) {
print(array);
writer.println();
}
public void close() {
writer.close();
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 4fe81184356b94ebdc153957aa0c0c1a | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes |
import java.awt.Point;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.AbstractList;
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.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import sun.misc.Queue;
/**
*
* @author Mojtaba
*/
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
MojtabaKhooryaniScanner in = new MojtabaKhooryaniScanner(System.in);
PrintWriter writer = new PrintWriter(System.out);
StringBuilder sb = new StringBuilder("");
int n = in.nextInt();
int k = in.nextInt();
int num = 1;
sb.append(num).append(" ");
int sign = 1;
int dif = k;
for (int i = 0; i < k; i++) {
num += (sign * dif);
sb.append(num).append(" ");
dif--;
sign *= -1;
}
for (int i = k + 2; i <= n; i++) {
sb.append(i).append(" ");
}
writer.println(sb.toString());
writer.close();
in.close();
}
}
class MojtabaKhooryaniScanner {
BufferedReader reader;
StringTokenizer tokenizer;
public MojtabaKhooryaniScanner(InputStream stream) {
this.reader = new BufferedReader(new InputStreamReader(stream));
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public int[] nextIntegerArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = nextInt();
}
return a;
}
public long[] nextLongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < a.length; i++) {
a[i] = nextLong();
}
return a;
}
public int nextInt(int radix) throws IOException {
return Integer.parseInt(next(), radix);
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public long nextLong(int radix) throws IOException {
return Long.parseLong(next(), radix);
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}
public BigInteger nextBigInteger(int radix) throws IOException {
return new BigInteger(next(), radix);
}
public String next() throws IOException {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
return this.next();
}
return tokenizer.nextToken();
}
public void close() throws IOException {
this.reader.close();
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | bcc33789e28f15008eb0d515a643bf16 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.io.*;
import java.util.*;
public class Smile {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
int k = in.nextInt();
int i = 1;
int j = k + 1;
boolean flag = true;
while (i <= j) {
if (flag) {
out.print(i + " ");
i++;
flag = false;
} else {
out.print(j + " ");
j--;
flag = true;
}
}
if (k + 1 == n) {
out.close();
return;
}
else {
for (int t = k + 2; t <= n; t++) {
out.print(t + " ");
}
}
out.close();
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | a46c690379b52d556f5692edefed11f8 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.*;
public class a {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt(), k = input.nextInt();
int[] res = new int[n];
int lo = 0, hi = n-1;
for(int i = 0; i<k; i++)
{
if(i%2 == 0) res[i] = lo++;
else res[i] = hi--;
}
for(int i = k; i<n; i++)
{
if(k%2 == 1) res[i] = lo++;
else res[i] = hi--;
}
for(int x: res) System.out.print((x+1)+" ");
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 68f1f784c76a747a9c9c2f4af405b77b | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
long n = scanner.nextLong();
long k = scanner.nextLong();
if (k == 1){
for (int i=1; i<=n; i++){
System.out.print(i + " ");
}
return;
}
long small = 1;
long big = n;
int i = 0;
while (k > 1){
if (i % 2 == 0){
System.out.print(big + " ");
big--;
} else {
System.out.print(small + " ");
small++;
}
k--;
i++;
}
if (i % 2 == 0){
for (long j = big; j>= small; j--){
System.out.print(j + " ");
}
} else {
for (long j = small; j<=big; j++){
System.out.print(j + " ");
}
}
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | d0cbebd2093731661e2a9399e27062fd | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.Scanner;
public class Diverse_Permutation {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner x = new Scanner(System.in);
int n = x.nextInt();
int k = x.nextInt();
int tempk = k+1;
int temp = 1;
int [] lis = new int [k+2];
for (int i = 1; i <= k+1; i+=2) {
lis[i] = temp;
temp++;
}
for (int i = 2; i <=k+1; i+=2) {
lis[i] = tempk;
tempk--;
}
for (int i = 1; i <= k+1; i++) {
System.out.print(lis[i]+ " ");
}
for(int i = k+2 ;i<=n;i++)
{
System.out.print(i + " ");
}
}
} | Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 1bba944a55ed5767c2fedca0799963d9 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.*;
public class CF482A_DiversePermutation {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
for(int i = 1; i <= k/2; i ++)
System.out.print(i + " " + (n - i + 1) + " ");
if(k%2!=0)
for(int i = k/2 + 1; i <= n - k/2; i++)
System.out.print(i + " ");
else
for(int i = n - k/2; i > k/2; i--)
System.out.print(i + " ");
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | caa5709f5c63b88552c7cc7e4fff8b06 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
public class solver {
BufferedReader in;
PrintWriter out;
StringTokenizer tok;
static final boolean OJ = System.getProperty("ONLINE_JUDGE") != null;
void init() throws FileNotFoundException{
if (OJ){
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}else{
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
}
}
String readString() throws IOException{
while (tok == null || !tok.hasMoreTokens()){
tok = new StringTokenizer(in.readLine()," :");
}
return tok.nextToken();
}
int readInt() throws NumberFormatException, IOException{
return Integer.parseInt(readString());
}
double readDouble() throws NumberFormatException, IOException{
return Double.parseDouble(readString());
}
long readLong() throws NumberFormatException, IOException{
return Long.parseLong(readString());
}
long time;
void run(){
try{
time = System.currentTimeMillis();
init();
solve();
if (!OJ) System.err.println(System.currentTimeMillis() - time);
out.close();
in.close();
}catch (Exception e){
e.printStackTrace();
}
}
long gcd(long a, long b){
if (a == 0) return b;
return gcd(b % a, a);
}
void solve() throws NumberFormatException, IOException{
int n = readInt();
int k = readInt();
int first = 1;
int last = n;
int c = 0;
for (int i=0;i<k;i++){
if (c == 0){
out.print(first+" ");
first++;
}else{
out.print(last+" ");
last--;
}
c = 1 - c;
}
if (c == 0){
for (int i=last;i>=first;i--){
out.print(i+" ");
}
}else{
for (int i=first;i<=last;i++){
out.print(i+" ");
}
}
}
public static void main(String[] args) {
new solver().run();
}
} | Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 3d128e66732093f1080d75be2482da0d | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class A_Div2_275 {
public static void main(String[]arg) throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
int n,k,i,val,c;
String ans = "";
n = Integer.parseInt(st.nextToken());
k = Integer.parseInt(st.nextToken());
val = 1;c = 0;
System.out.print(1);
int f = -1;
for(i = k; i >= 1; i--,c++)
{
val += i*(f*-1);
f *= -1;
System.out.print(" " + val);
}
//System.out.println(ans+".."+c);
val = 1 + k;
for(i = c+1; i < n; i++)
{
val += 1;
System.out.print(" " +val);
}
System.out.println();
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 2bc95da071c4b4b87c8c17436548f47b | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class A {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tok = new StringTokenizer(br.readLine());
int N, K;
N = Integer.parseInt( tok.nextToken() );
K = Integer.parseInt( tok.nextToken() );
System.out.println( print(solve(N, K)) );
}
static String print(int[] res) {
StringBuilder sb = new StringBuilder();
sb.append(res[0]);
for (int i = 1; i < res.length; i++) {
sb.append(' ').append(res[i]);
}
return sb.toString();
}
static int[] solve(int n, int k) {
int[] res = new int[n];
int f = 1;
int last = n;
int idx = 0;
boolean fromEnd = true;
while (k > 0) {
if (fromEnd) {
res[idx++] = last--;
} else {
res[idx++] = f++;
}
fromEnd = !fromEnd;
if (idx == 0) continue;
--k;
}
if (fromEnd) {
for (int i = idx; i < n; i++) {
res[i] = f++;
}
} else {
for (int i = idx; i < n; i++) {
res[i] = last--;
}
}
return res;
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 9208370083f133a7b0b8820f22d42e9f | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class DiversePermutation {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
out.print("1");
int current =1;
boolean used[] = new boolean[n+1];
used[1] = true;
while(k>0){
if(current-k>0&&!used[current-k]){
current-=k;
}
else if(current+k<=n&&!used[current+k]){
current+=k;
}
out.print(" "+current);
k--;
used[current] =true;
}
for(int i = 1;i<=n;i++)
if(!used[i])
out.print(" "+i);
out.println();
in.close();
out.close();
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | feb3685319b91a54dd92b8764031c299 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.Scanner;
////cf1*
public class Main {
public static void main(String[]args){
Scanner scanner =new Scanner(System.in);
int n = scanner.nextInt();
int k = scanner.nextInt();
int[] array = new int[n];
array[0] = 1;
int f = 1;
int i;
for (i = 1; i <= k; i++)
{
array[i] = array[i - 1] + f * (k - i + 1);
f *= -1;
}
int current = k + 2;
while (i < n)
{
array[i++] = current++;
}
for (int j = 0; j < n; j++)
{
System.out.print(array[j] + " ");
}
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 0398ba0cc2c095116c0db72b55cf8801 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
void solve() throws IOException {
int n = readInt();
int k = readInt();
int len = n - 1;
int pos = 1;
boolean toRight = true;
List<Integer> ans = new ArrayList<Integer>();
for (int i = 0; i < k - 1; i++) {
ans.add(pos);
if (toRight) {
pos += len;
} else {
pos -= len;
}
toRight = !toRight;
len--;
}
while(ans.size() != n) {
ans.add(pos);
if(toRight) {
pos++;
} else {
pos--;
}
}
for (Integer an : ans) {
out.print(an + " ");
}
}
//-------------------------------------------------
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
BufferedReader in;
PrintWriter out;
StringTokenizer tok;
public void run() {
try {
long startTime = System.currentTimeMillis();
Locale.setDefault(Locale.US);
if (ONLINE_JUDGE) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
} else {
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
}
tok = new StringTokenizer("");
solve();
in.close();
out.close();
long endTime = System.currentTimeMillis();
long totalMemory = Runtime.getRuntime().totalMemory();
long freeMemory = Runtime.getRuntime().freeMemory();
System.err.println("Time = " + (endTime - startTime) + " ms");
System.err.println("Memory = " + ((totalMemory - freeMemory) / 1024) + " KB");
} catch (Throwable e) {
e.printStackTrace(System.err);
System.exit(-1);
}
}
String readString() throws IOException {
while (!tok.hasMoreTokens()) {
String line = in.readLine();
if (line == null) return null;
tok = new StringTokenizer(line);
}
return tok.nextToken();
}
int readInt() throws IOException {
return Integer.parseInt(readString());
}
long readLong() throws IOException {
return Long.parseLong(readString());
}
double readDouble() throws IOException {
return Double.parseDouble(readString());
}
void debug(Object... o) {
if (!ONLINE_JUDGE) {
System.err.println(Arrays.deepToString(o));
}
}
public static void main(String[] args) {
new Solution().run();
}
//------------------------------------------------------------------------------
static class Mergesort {
private Mergesort() {
}
public static void sort(int[] a) {
mergesort(a, 0, a.length - 1);
}
public static void sort(long[] a) {
mergesort(a, 0, a.length - 1);
}
public static void sort(double[] a) {
mergesort(a, 0, a.length - 1);
}
private static final int MAGIC_VALUE = 42;
private static void mergesort(int[] a, int leftIndex, int rightIndex) {
if (leftIndex < rightIndex) {
if (rightIndex - leftIndex <= MAGIC_VALUE) {
insertionSort(a, leftIndex, rightIndex);
} else {
int middleIndex = (leftIndex + rightIndex) / 2;
mergesort(a, leftIndex, middleIndex);
mergesort(a, middleIndex + 1, rightIndex);
merge(a, leftIndex, middleIndex, rightIndex);
}
}
}
private static void mergesort(long[] a, int leftIndex, int rightIndex) {
if (leftIndex < rightIndex) {
if (rightIndex - leftIndex <= MAGIC_VALUE) {
insertionSort(a, leftIndex, rightIndex);
} else {
int middleIndex = (leftIndex + rightIndex) / 2;
mergesort(a, leftIndex, middleIndex);
mergesort(a, middleIndex + 1, rightIndex);
merge(a, leftIndex, middleIndex, rightIndex);
}
}
}
private static void mergesort(double[] a, int leftIndex, int rightIndex) {
if (leftIndex < rightIndex) {
if (rightIndex - leftIndex <= MAGIC_VALUE) {
insertionSort(a, leftIndex, rightIndex);
} else {
int middleIndex = (leftIndex + rightIndex) / 2;
mergesort(a, leftIndex, middleIndex);
mergesort(a, middleIndex + 1, rightIndex);
merge(a, leftIndex, middleIndex, rightIndex);
}
}
}
private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
int length1 = middleIndex - leftIndex + 1;
int length2 = rightIndex - middleIndex;
int[] leftArray = new int[length1];
int[] rightArray = new int[length2];
System.arraycopy(a, leftIndex, leftArray, 0, length1);
System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
if (i == length1) {
a[k] = rightArray[j++];
} else if (j == length2) {
a[k] = leftArray[i++];
} else {
a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
}
}
}
private static void merge(long[] a, int leftIndex, int middleIndex, int rightIndex) {
int length1 = middleIndex - leftIndex + 1;
int length2 = rightIndex - middleIndex;
long[] leftArray = new long[length1];
long[] rightArray = new long[length2];
System.arraycopy(a, leftIndex, leftArray, 0, length1);
System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
if (i == length1) {
a[k] = rightArray[j++];
} else if (j == length2) {
a[k] = leftArray[i++];
} else {
a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
}
}
}
private static void merge(double[] a, int leftIndex, int middleIndex, int rightIndex) {
int length1 = middleIndex - leftIndex + 1;
int length2 = rightIndex - middleIndex;
double[] leftArray = new double[length1];
double[] rightArray = new double[length2];
System.arraycopy(a, leftIndex, leftArray, 0, length1);
System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
if (i == length1) {
a[k] = rightArray[j++];
} else if (j == length2) {
a[k] = leftArray[i++];
} else {
a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
}
}
}
private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
for (int i = leftIndex + 1; i <= rightIndex; i++) {
int current = a[i];
int j = i - 1;
while (j >= leftIndex && a[j] > current) {
a[j + 1] = a[j];
j--;
}
a[j + 1] = current;
}
}
private static void insertionSort(long[] a, int leftIndex, int rightIndex) {
for (int i = leftIndex + 1; i <= rightIndex; i++) {
long current = a[i];
int j = i - 1;
while (j >= leftIndex && a[j] > current) {
a[j + 1] = a[j];
j--;
}
a[j + 1] = current;
}
}
private static void insertionSort(double[] a, int leftIndex, int rightIndex) {
for (int i = leftIndex + 1; i <= rightIndex; i++) {
double current = a[i];
int j = i - 1;
while (j >= leftIndex && a[j] > current) {
a[j + 1] = a[j];
j--;
}
a[j + 1] = current;
}
}
}
} | Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | a06bf3d82e511ccbd0fb2ebd08e0bc77 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.Scanner;
public class Round275_C_Diverse_Permutation {
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
int n = x.nextInt(), k = x.nextInt() ,temp = 1, tempk = k + 1;
int[] set = new int[k + 2];
for (int i = 1; i <= k + 1; i += 2) {
set[i] = temp;
temp++;
}
for (int i = 2; i <= k + 1; i += 2) {
set[i] = tempk;
tempk--;
}
for (int i = 1; i <= k + 1; i++) {
System.out.print(set[i] + " ");
}
for (int i = k + 2; i <= n; i++) {
System.out.print(i + " ");
}
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 57b986af7a6ce51a998efd69e689f1f2 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.*;
public class _482A_Diverse_Permutation {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int l = 1;
System.out.print(1 + " ");
for (int i = 0; i < k; i++)
System.out.print((l += i % 2 == 0 ? k - i : -(k - i)) + " ");
for (int i = k + 2; i <= n; i++)
System.out.print(i + " ");
}
} | Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | beda677cac0a1daf4cdfc21de011a733 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.*;
public class _482A_Diverse_Permutation {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int MAX = 100005;
boolean[] a = new boolean[MAX];
int l = 1;
boolean inc = false;
a[1] = true;
System.out.print(1 + " ");
for (int i = k; i > 0; i--) {
l += (inc = !inc) ? i : -i;
a[l] = true;
System.out.print(l + " ");
}
for (int i = 1; i <= n; i++)
if (!a[i])
System.out.print(i + " ");
}
} | Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 582146fd315b9689f670850da5bb98ba | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.*;
public class _482A_Diverse_Permutation {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int MAX = 100005;
boolean[] a = new boolean[MAX];
int l = 1;
boolean inc = true;
a[1] = true;
System.out.print(1 + " ");
for (int i = k; i > 0; i--) {
if (inc) {
l = l + i;
} else {
l = l - i;
}
inc = !inc;
a[l] = true;
System.out.print(l + " ");
}
for (int i = 1; i <= n; i++) {
if (!a[i])
System.out.print(i + " ");
}
}
} | Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 54534aee9bea0aca5aa25f7395ec5920 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
public class Codeforces implements Runnable {
private BufferedReader br = null;
private PrintWriter pw = null;
private StringTokenizer stk = new StringTokenizer("");
public static void main(String[] args) {
new Thread(new Codeforces()).run();
}
public void run() {
/*
* try { br = new BufferedReader(new FileReader("/home/user/freshdb.sql")); pw = new
* PrintWriter("/home/user/freshdb_fix.sql"); } catch (FileNotFoundException e) {
* e.printStackTrace(); }
*/
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new OutputStreamWriter(System.out));
solver();
pw.close();
}
private void nline() {
try {
if (!stk.hasMoreTokens())
stk = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException("KaVaBUnGO!!!", e);
}
}
private String nstr() {
while (!stk.hasMoreTokens())
nline();
return stk.nextToken();
}
private int ni() {
return Integer.valueOf(nstr());
}
private long nl() {
return Long.valueOf(nstr());
}
private double nd() {
return Double.valueOf(nstr());
}
String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
}
return null;
}
class Point {
int x;
int y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
}
private void bfs(int t, boolean[] using, int[][] g) {
Stack<Integer> st = new Stack<Integer>();
int n = using.length;
st.add(t);
while (!st.empty()) {
int p = st.pop();
for (int i = 0; i < n; i++) {
if (g[p][i] == 1 && !using[i]) {
st.add(i);
using[i] = true;
}
}
}
}
public int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private boolean checkPrime(int a) {
for (int i = 2; i <= Math.sqrt(a); i++) {
if (a % i == 0)
return false;
}
return true;
}
class KeySet implements Comparable<KeySet> {
int key;
int value;
public KeySet(int key, int value) {
this.key = key;
this.value = value;
}
public int getKey() {
return key;
}
public void setKey(int key) {
this.key = key;
}
@Override
public int compareTo(KeySet keySet) {
if (this.value > keySet.value) {
return 1;
} else if (this.value < keySet.value) {
return -1;
} else {
return 0;
}
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
BigInteger toPositive(BigInteger bi) {
return bi.signum() < 0 ? bi.negate() : bi;
}
int fact(int x) {
int ans = 1;
for (int i = 1; i <= x; i++) {
ans *= i;
}
return ans;
}
private void solver() {
int n = ni(), k = ni();
int l = 1, r = n;
boolean d = true;
int p = 0;
while (p < k){
if (d){
System.out.print(l + " ");
l++;
d = false;
p++;
}else {
System.out.print(r + " ");
r--;
d = true;
p++;
}
}
for(int i=0; i<n-k; i++){
if(!d){
System.out.print(l + " ");
l++;
}else {
System.out.print(r + " ");
r--;
}
}
}
private BigInteger nbi() {
return new BigInteger(nstr());
}
void exit() {
pw.close();
System.exit(0);
}
} | Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | e84238ec30c6973a9f93b3656d838983 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.Scanner;
/**
* Created by G on 11/1/14.
*/
public class CF482A {
public static void main(String[] args){
Scanner sin = new Scanner(System.in);
int n = sin.nextInt();
int k = sin.nextInt();
int i = 1;
int last = 1;
System.out.print("1 ");
while (i <= k){
int dif = k - i + 1;
if (i % 2 == 0){
dif *= -1;
}
last = last + dif;
System.out.print(last + " ");
++i;
}
while(i < n){
System.out.print(++i + " ");
}
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 0ef701f26dd622aceaee1e5e93c5cd43 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | //package Codeforces.Div1A_275.Code1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/*
* some cheeky quote
*/
public class Main
{
FastScanner in;
PrintWriter out;
public void solve() throws IOException
{
int n = in.nextInt();
int k = in.nextInt();
int left = 1;
int right = n;
boolean isFirst = true;
for (int i = 0; i < k; i++)
{
if (!isFirst)
{
out.print(" ");
}
isFirst = false;
if (i % 2 == 0)
{
out.print(left++);
} else
{
out.print(right--);
}
}
if (k % 2 == 0)
{
for (int i = k; i < n; i++)
{
out.print(" " + right--);
}
} else
{
for (int i = k; k < n; k++)
{
out.print(" " + left++);
}
}
}
public void run()
{
try
{
in = new FastScanner();
out = new PrintWriter(System.out);
solve();
out.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
class FastScanner
{
BufferedReader br;
StringTokenizer st;
FastScanner()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreTokens())
{
try
{
st = new StringTokenizer(br.readLine());
} catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
}
public static void main(String[] arg)
{
new Main().run();
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 783dac41b7473337513741cb77a4a257 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class DiversePermutation {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(f.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
StringBuffer sb = new StringBuffer();
for (int i = n; i >= k+1; i--)
sb.append(" " + i);
int i = 1;
int j = k;
int count = 0;
while (i <= j) {
if (count % 2 == 0)
sb.append(" " + i++);
else
sb.append(" " + j--);
count++;
}
System.out.println(sb.toString().substring(1));
}
} | Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 0e04ae3566c6db2b26fd2eba03faf71d | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | // package Div2;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
public class Sketch {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int n = input.nextInt(); int k = input.nextInt();
input.close();
int[] result = new int[n];
for(int i=0; i<n-k-1; i++){
result[i] = i+1;
}
int cnt = n-k;
for(int i=n-k-1; i<n; i+=2, cnt++){
result[i] = cnt;
}
cnt = n;
for(int i=n-k; i<n; i+=2, cnt--){
result[i] = cnt;
}
for(int i=0; i<n; i++){
System.out.print(result[i] + " ");
}
}
} | Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 4791518707b36a73c98d6984a3e6b929 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.Scanner;
public class PlayGround {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int p = k + 1;
for (int i = 0; i < k + 1; i++)
if (i % 2 == 0) {
System.out.print(((i + 1) / 2 + 1) + " ");
} else {
System.out.print(p + " ");
p--;
}
for (int i = k + 1; i < n; i++)
System.out.print((i+ 1) + " ");
System.out.println();
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 391df09a8fe8265dd6c0ac90a06617dc | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.Scanner;
public class divperm {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int numints = scan.nextInt();
boolean[] avail = new boolean[numints];
int kunique = scan.nextInt();
for (int i = 0; i < numints; ++i)
avail[i] = false;
int left = 0, r = numints - 1;
for (int i = 0; i < kunique; ++i) {
avail[(i & 1) == 0 ? left : r] = true;
if ((i & 1) == 0) {
System.out.print((1 + (left++)));
}
else {
System.out.print((1 + (r--)));
}
System.out.print(' ');
}
if ((kunique & 1) == 1) {
for (int i = 0; i < numints; ++i) {
if (!avail[i]) {
System.out.print(i + 1);
System.out.print(' ');
}
}
} else {
for (int i = numints - 1; i >= 0; --i) {
if (!avail[i]) {
System.out.print(i + 1);
System.out.print(' ');
}
}
}
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 0e62797e5ef5e2ba6bac9c62054fd6e3 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Solver {
public static void main(String[] Args) throws NumberFormatException,
IOException {
new Solver().Run();
}
PrintWriter pw;
StringTokenizer Stok;
BufferedReader br;
public String nextToken() throws IOException {
while (Stok == null || !Stok.hasMoreTokens()) {
Stok = new StringTokenizer(br.readLine());
}
return Stok.nextToken();
}
public int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(nextToken());
}
public double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(nextToken());
}
public long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(nextToken());
}
public void Run() throws NumberFormatException, IOException {
//br = new BufferedReader(new FileReader("input.txt")); pw = new PrintWriter("output.txt");
br=new BufferedReader(new InputStreamReader(System.in)); pw=new PrintWriter(new OutputStreamWriter(System.out));
int n=nextInt();
int k=nextInt();
int[] result=new int[n];
int maxNum=1+k;
result[0]=1;
int diff=k;
int i=1;
while (Math.abs(diff)>0){
result[i]=result[i-1]+diff;
if (diff>0){
diff=1-diff;
} else {
diff=-diff-1;
}
i++;
}
for (; i<n; i++){
result[i]=i+1;
}
for (i=0; i<n; i++){
pw.print(result[i]);
pw.print(' ');
}
pw.println();
pw.flush();
pw.close();
}
} | Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 48d9d395e927f00a266cc9cf9ee06890 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.lang.Math.*;
import java.io.*;
public class cf {
public static void main(String[] args) throws java.lang.Exception
{
Scanner reader = new Scanner(System.in);
int n,k;
n = reader.nextInt();
k = reader.nextInt();
for (int i=1; i<=n-k-1; i++) { System.out.print(i); System.out.print(" "); }
for (int i=1; i<=k+1; i++)
if (i%2 == 1)
{
System.out.print(n-k-1 + (i+1)/2);
System.out.print(" ");
}
else
{
System.out.print(n+1 - i/2);
System.out.print(" ");
}
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | c36a0c36b42f9c40a150d55f9bc892c0 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
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();
}
}
class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int k = in.nextInt();
int[] p = new int[n];
for (int i = 0; i < k; i++) {
if (i % 2 == 0) {
p[i] = i / 2;
} else {
p[i] = n - 1 - i / 2;
}
}
if (k % 2 != 0) {
for (int i = k; i < n; i++) {
p[i] = p[i - 1] + 1;
}
} else {
for (int i = k; i < n; i++) {
p[i] = p[i - 1] - 1;
}
}
for (int i = 0; i < n; i++) {
if (i > 0) {
out.print(' ');
}
out.print(p[i] + 1);
}
out.println();
}
}
class InputReader {
BufferedReader br;
StringTokenizer st;
public InputReader(InputStream stream) {
br = new BufferedReader(new InputStreamReader(stream));
}
public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
String line = null;
try {
line = br.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
if (line == null) {
return null;
}
st = new StringTokenizer(line);
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | e999e09ee4aa0ff1970f64ad53f8f655 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.Arrays;
import java.util.*;
import java.io.*;
import java.lang.Math.*;
public class diversePermutation {
public static void main(String[] args) {
Scanner infile = new Scanner(System.in);
int n = infile.nextInt(); //
int k = infile.nextInt(); //1 - 64
generatePerm(n,k); //1 <= k < n <= 1 x 10e5
}
public static void generatePerm(int n, int k)
{
int left = 1;
int right = n;
int count = k;
if(k == 1)
for(int i = 0; i < n; i++)
System.out.print((i + 1) + " ");
else
{
for(int a = 1; a <= k; a++)
{
if(a % 2 == 1)
{
System.out.print(left+ " ");
left++;
}
else
{
System.out.print(right + " ");
right--;
}
}
while(count < n)
{
if(k % 2 == 1)
{
System.out.print(left + " ");
left++;
}
if(k % 2 == 0)
{
System.out.print(right + " ");
right--;
}
count++;
}
}
}
} | Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 1e9945f9e8f1ce1597f73f35ae0813e8 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
/**
* #
* @author pttrung
*/
public class A_Round_275_Div1 {
public static long MOD = 1000000007;
public static void main(String[] args) throws FileNotFoundException {
// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
// "output.txt")));
PrintWriter out = new PrintWriter(System.out);
Scanner in = new Scanner();
int n = in.nextInt();
int k = in.nextInt();
boolean[]check = new boolean[n + 1];
out.print(1 + " ");
check[1] = true;
int last = 1;
while(k > 0){
int a = last + k;
int b = last - k;
if(b > 0 && !check[b]){
check[b] = true;
out.print(b + " ");
last = b;
}else{
check[a] = true;
out.print(a + " ");
last = a;
}
k--;
}
for(int i = 2; i <= n; i++){
if(!check[i]){
out.print(i + " ");
}
}
out.close();
}
public static int[] KMP(String val) {
int i = 0;
int j = -1;
int[] result = new int[val.length() + 1];
result[0] = -1;
while (i < val.length()) {
while (j >= 0 && val.charAt(j) != val.charAt(i)) {
j = result[j];
}
j++;
i++;
result[i] = j;
}
return result;
}
public static boolean nextPer(int[] data) {
int i = data.length - 1;
while (i > 0 && data[i] < data[i - 1]) {
i--;
}
if (i == 0) {
return false;
}
int j = data.length - 1;
while (data[j] < data[i - 1]) {
j--;
}
int temp = data[i - 1];
data[i - 1] = data[j];
data[j] = temp;
Arrays.sort(data, i, data.length);
return true;
}
public static int digit(long n) {
int result = 0;
while (n > 0) {
n /= 10;
result++;
}
return result;
}
public static double dist(long a, long b, long x, long y) {
double val = (b - a) * (b - a) + (x - y) * (x - y);
val = Math.sqrt(val);
double other = x * x + a * a;
other = Math.sqrt(other);
return val + other;
}
public static class Point implements Comparable<Point> {
int x, y;
public Point(int start, int end) {
this.x = start;
this.y = end;
}
@Override
public int hashCode() {
int hash = 5;
hash = 47 * hash + this.x;
hash = 47 * hash + this.y;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Point other = (Point) obj;
if (this.x != other.x) {
return false;
}
if (this.y != other.y) {
return false;
}
return true;
}
@Override
public int compareTo(Point o) {
return x - o.x;
}
}
public static class FT {
long[] data;
FT(int n) {
data = new long[n];
}
public void update(int index, long value) {
while (index < data.length) {
data[index] += value;
index += (index & (-index));
}
}
public long get(int index) {
long result = 0;
while (index > 0) {
result += data[index];
index -= (index & (-index));
}
return result;
}
}
public static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
public static long pow(long a, long b) {
if (b == 0) {
return 1;
}
if (b == 1) {
return a;
}
long val = pow(a, b / 2);
if (b % 2 == 0) {
return val * val % MOD;
} else {
return val * (val * a % MOD) % MOD;
}
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner() throws FileNotFoundException {
// System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
br = new BufferedReader(new InputStreamReader(System.in));
// br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
throw new RuntimeException();
}
}
return st.nextToken();
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
st = null;
try {
return br.readLine();
} catch (Exception e) {
throw new RuntimeException();
}
}
public boolean endLine() {
try {
String next = br.readLine();
while (next != null && next.trim().isEmpty()) {
next = br.readLine();
}
if (next == null) {
return true;
}
st = new StringTokenizer(next);
return st.hasMoreTokens();
} catch (Exception e) {
throw new RuntimeException();
}
}
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | c14f14027d60afe66fdd02afd83d7e37 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 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.util.TreeSet;
import java.io.Writer;
import java.math.BigInteger;
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);
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) {
int n = in.readInt();
int k = in.readInt();
TreeSet<Integer> set = new TreeSet<Integer>();
for (int i = 0; i < n; i++) {
set.add(i + 1);
}
int maxDiff = k;
while (!set.isEmpty()) {
if (set.size() == 1) {
out.print(set.pollFirst());
continue;
}
if (maxDiff == 1) {
while (!set.isEmpty()) {
out.print(set.pollFirst() + " ");
}
break;
}
int a = set.pollFirst();
set.remove(a + maxDiff);
out.print(a + " " + (a + maxDiff) + " ");
maxDiff = Math.max(maxDiff - 2, 1);
}
out.printLine();
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public 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);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
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() {
writer.println();
}
public void close() {
writer.close();
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 077c5af6e94bf4bb019081ca19c63e6c | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author giovanny
*/
public class DiversePermutation {
DiversePermutation(int n, int k) {
int kpos;
int kval = n;
int j = 0;
if (k % 2 == 0) {//multiplo de 2
for (int i = 0; i < n; i++) {
if (i % 2 == 0 && k > 1) {
System.out.print(kval + " ");
k -= 2;
kval--;
} else {
System.out.print((j + 1) + " ");
j++;
}
}
} else {
for (int i = 0; i < n; i++) {
if (i % 2 == 1 && k > 1) {
System.out.print(kval + " ");
k-=2;
kval--;
} else {
System.out.print((j + 1) + " ");
j++;
}
}
}
System.out.println("");
}
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String[] linea = (in.readLine()).split(" ");
int n, k;
n = Integer.parseInt(linea[0]);
k = Integer.parseInt(linea[1]);
DiversePermutation DP = new DiversePermutation(n, k);
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 2781092376936c2297d4b8262836effa | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | //package codeforces;
import java.io.*;
import java.util.*;
public class A {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out);
A() throws IOException {
// reader = new BufferedReader(new FileReader("input.txt"));
// writer = new PrintWriter(new FileWriter("output.txt"));
}
StringTokenizer stringTokenizer;
String next() throws IOException {
while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
stringTokenizer = new StringTokenizer(reader.readLine());
}
return stringTokenizer.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
void solve() throws IOException {
int n = nextInt();
int k = nextInt();
int i = 1, j = n;
for(int r = 0; r < k - 1; r++) {
if(r % 2 == 0) {
writer.print(i++ + " ");
} else {
writer.print(j-- + " ");
}
}
while(i != j) {
if(k % 2 == 0) {
writer.print(j-- + " ");
} else {
writer.print(i++ + " ");
}
}
writer.println(i);
writer.close();
}
public static void main(String[] args) throws IOException {
new A().solve();
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | eb75f02d3e9020123397d83e12cbadec | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes |
import java.util.Scanner;
/**
* Created by user1 on 14/10/29.
*/
public class ProblemA {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int[] p = new int[n];
int idx = 0;
for (int i = 1 ; i <= n-k ; i++) {
p[idx++] = i;
}
int left = n-k+1;
int right = n;
boolean toR = true;
while (idx < n) {
if (toR) {
p[idx++] = right;
right--;
} else {
p[idx++] = left;
left++;
}
toR = !toR;
}
StringBuilder b = new StringBuilder();
for (int i = 0; i < n; i++) {
b.append(' ').append(p[i]);
}
System.out.println(b.substring(1));
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 06dbf1656231fe0ea319fb34bd6c2c50 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(br);
int n = sc.nextInt();
int k = sc.nextInt();
int lastRemoved = 0;
LinkedList<Integer> list = new LinkedList<Integer>();
for (int i = 1; i <= n; i++) {
list.add(i);
}
for (int i = 0; i < (k == 1 ? 0 : k); i++) {
if (i % 2 == 0) {
lastRemoved = list.removeLast();
System.out.print(lastRemoved + " ");
} else {
lastRemoved = list.removeFirst();
System.out.print(lastRemoved + " ");
}
}
if (list.size() > 0) {
if (Math.abs(list.getFirst() - lastRemoved) == 1) {
while (list.size() != 0) {
System.out.print(list.removeFirst() + " ");
}
} else {
while (list.size() != 0) {
System.out.print(list.removeLast() + " ");
}
}
}
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 3e8624eac2c06402892a15f1f102e853 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes |
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
public class Nothing {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
int n = Reader.nextInt();
int k = Reader.nextInt();
int z = k;
StringBuilder ans = new StringBuilder();
int a = 1, b = k+1;
while(b > a){
ans.append(a).append(' ').append(b).append(' ');
a++;
b--;
}
if(a == b)
ans.append(b).append(' ');
for(int i = k+2; i <= n; i++)
ans.append(i).append(' ');
System.out.println(ans);
}
}
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
public static int pars(String x) {
int num = 0;
int i = 0;
if (x.charAt(0) == '-') {
i = 1;
}
for (; i < x.length(); i++) {
num = num * 10 + (x.charAt(i) - '0');
}
if (x.charAt(0) == '-') {
return -num;
}
return num;
}
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
static void init(FileReader input) {
reader = new BufferedReader(input);
tokenizer = new StringTokenizer("");
}
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(
reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return pars(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 8e1b40ddbf2016571d4c19ac0e7ef2ea | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes |
import java.util.Scanner;
public class A482 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int N = input.nextInt();
int K = input.nextInt();
int down = 1;
int up = N+1;
boolean lastUp = false;
StringBuilder output = new StringBuilder("1");
for (int n=2; n<=N; n++) {
int next;
if (n <= K) {
if (lastUp) {
next = ++down;
} else {
next = --up;
}
lastUp = !lastUp;
} else {
if (lastUp) {
next = --up;
} else {
next = ++down;
}
}
output.append(' ');
output.append(next);
}
System.out.println(output);
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output | |
PASSED | 221edb1f45e381331d3ba06f58d5ff08 | train_002.jsonl | 1414170000 | Permutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Your task is to find such permutation p of length n, that the group of numbers |p1β-βp2|,β|p2β-βp3|,β...,β|pnβ-β1β-βpn| has exactly k distinct elements. | 256 megabytes | import java.util.Scanner;
public class A482 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int l = 1;
int r = m + 1;
while (l <= r){
System.out.print(l + " ");
l++;
if (l <= r){
System.out.print(r + " ");
r--;
}
}
for (int i = m + 2; i <= n; i++){
System.out.print(i + " ");
}
}
}
| Java | ["3 2", "3 1", "5 2"] | 1 second | ["1 3 2", "1 2 3", "1 3 2 4 5"] | NoteBy |x| we denote the absolute value of number x. | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 18b3d8f57ecc2b392c7b1708f75a477e | The single line of the input contains two space-separated positive integers n, k (1ββ€βkβ<βnββ€β105). | 1,200 | Print n integers forming the permutation. If there are multiple answers, print any of them. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.