sample_inputs
stringlengths
5
384
input_specification
stringlengths
48
911
src_uid
stringlengths
32
32
source_code
stringlengths
29
6.77k
sample_outputs
stringlengths
5
393
lang_cluster
stringclasses
4 values
notes
stringlengths
30
1.52k
βŒ€
output_specification
stringlengths
25
681
description
stringlengths
140
2.49k
human_testcases
stringlengths
243
50.8k
human_pass_rate
float64
100
100
human_line_coverage
float64
100
100
human_branch_coverage
float64
100
100
human_sample_testcases_1
stringlengths
190
3.11k
human_sample_testcases_2
stringlengths
190
3.11k
human_sample_testcases_3
stringlengths
190
3.11k
human_sample_testcases_4
stringlengths
190
3.11k
human_sample_testcases_5
stringlengths
190
3.11k
human_sample_pass_rate_1
float64
100
100
human_sample_pass_rate_2
float64
100
100
human_sample_pass_rate_3
float64
100
100
human_sample_pass_rate_4
float64
100
100
human_sample_pass_rate_5
float64
100
100
human_sample_line_coverage_1
float64
52.2
100
human_sample_line_coverage_2
float64
60
100
human_sample_line_coverage_3
float64
50
100
human_sample_line_coverage_4
float64
43.5
100
human_sample_line_coverage_5
float64
21.7
100
human_sample_branch_coverage_1
float64
45.5
100
human_sample_branch_coverage_2
float64
45.8
100
human_sample_branch_coverage_3
float64
16.7
100
human_sample_branch_coverage_4
float64
36.4
100
human_sample_branch_coverage_5
float64
18.2
100
id
int64
1
400
human_sample_pass_rate
float64
100
100
human_sample_line_coverage
float64
47
100
human_sample_branch_coverage
float64
41.8
100
["5 2\nNYNNY", "6 1\n????NN"]
The first line contains two integers n and k (1 ≀ n ≀ 100, 0 ≀ k ≀ n) β€” the number of episodes in the series and the dissatisfaction which should be checked. The second line contains the sequence which consists of n symbols "Y", "N" and "?". If the i-th symbol equals "Y", Stepan remembers that he has watched the episode number i. If the i-th symbol equals "N", Stepan remembers that he hasn't watched the epizode number i. If the i-th symbol equals "?", Stepan doesn't exactly remember if he has watched the episode number i or not.
5bd578d3da5837c259b222336a194d12
import java.util.Scanner; public class project{ public static void main(String[]args){ Scanner s = new Scanner(System.in); int n = s.nextInt(), k = s.nextInt(); String str = s.nextLine(); str = s.nextLine(); int ans = 0; for (int i = 0; i < n; ++i) { if (i == 0 || str.charAt(i - 1) != 'N') { int j = i; for (j = i; j < n; ++j) { if (str.charAt(j) == 'Y') { break; } if (j - i == k - 1 && (j + 1 == n || str.charAt(j + 1) != 'N')) { ans = 1; } } } } if (k == 0) { ans = 1; } for (int i = 0; i < n; ++i) { for (int j = i; j < n && str.charAt(j) == 'N'; ++j) { if (j - i == k) { ans = 0; } } } if (ans == 1) { System.out.println("YES"); } else { System.out.println("NO"); } } }
["YES", "NO"]
Java
NoteIn the first test Stepan remembers about all the episodes whether he has watched them or not. His dissatisfaction is 2, because he hasn't watch two episodes in a row β€” the episode number 3 and the episode number 4. The answer is "YES", because k = 2.In the second test k = 1, Stepan's dissatisfaction is greater than or equal to 2 (because he remembers that he hasn't watch at least two episodes in a row β€” number 5 and number 6), even if he has watched the episodes from the first to the fourth, inclusive.
If Stepan's dissatisfaction can be exactly equal to k, then print "YES" (without qoutes). Otherwise print "NO" (without qoutes).
Well, the series which Stepan watched for a very long time, ended. In total, the series had n episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he definitely hasn't watched it, or he is unsure, has he watched this episode or not. Stepan's dissatisfaction is the maximum number of consecutive series that Stepan did not watch.Your task is to determine according to Stepan's memories if his dissatisfaction could be exactly equal to k.
[{"input": "5 2\r\nNYNNY\r\n", "output": ["YES"]}, {"input": "6 1\r\n????NN\r\n", "output": ["NO"]}, {"input": "100 8\r\nNYNNY?YNNNNNN?NNNNNYNY?YYNYNN?NNNY??NNYNYNNNYNNNYNNNNNNNNY?NNNYNYN?NNNY?YY?NNYNN?NNNYNNYNNYN?NNYNYNN\r\n", "output": ["YES"]}, {"input": "10 1\r\nNY???NY?Y?\r\n", "output": ["YES"]}, {"input": "20 7\r\nN?N??NNN?NNN?Y???Y??\r\n", "output": ["YES"]}, {"input": "30 1\r\nNYYYNYYY?Y?YY?YYYYYYYYYYYYYNYY\r\n", "output": ["YES"]}, {"input": "40 14\r\nNNNNNNNNNNNNNNNNNYNNNNYNNYNNNNNNYNNNNNNN\r\n", "output": ["NO"]}, {"input": "51 1\r\nYYYNYNYNNYYNNY?YNYYYYYYNNYNYN??NYNYYNYYYYYYNNYNNNYY\r\n", "output": ["NO"]}, {"input": "70 3\r\nYNNNYYYNY?YYNYYNYYN?NYYYYYYYYYYYYYNYYNNYYYYYYYNYYNNNY??YYNYYYYYYYYNYYN\r\n", "output": ["YES"]}, {"input": "85 10\r\nYNNYNNNNNYNNNNNNNNNNNYNYYNNYNNNYYYNNNYYNNNNYNNNYNNNYNNNNNNNNNNNNN?NNNNYNNYYNNNNNNYNNN\r\n", "output": ["NO"]}, {"input": "90 18\r\nNNNN?NNNNNYNYNYNNY?NNNNNNNNNNNNNNYNNNNNNYYNYYNNNNYNNNNNNNNNNNNNNNNNNNYNNYYNYNNNNNNNYNNNNYN\r\n", "output": ["NO"]}, {"input": "99 2\r\nYNYYYYYYYYYYYN?YYNYYYYYYYYYYYYYY?YYYNYYYYYYYYYYYYYNYYYYYYNY?YYYYYNNYYYNYNYYYYNYYYYYYYYYYYNYY?NYYYYY\r\n", "output": ["YES"]}, {"input": "100 74\r\nNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN?NNNNNNNNNNNN?NNNNNNNNNNNNNN\r\n", "output": ["NO"]}, {"input": "100 19\r\nYYNN?NNNNNNNNNNNYNYYNYNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNYNNNNNNYNNYYNNNYNNNYNYNNYNNNYYNNNYNNN?NNNNN?YNN\r\n", "output": ["NO"]}, {"input": "100 10\r\nNNNNYNNNYNNNNNNNNYNYNYNNNNNYNNNNNYNNNNNNNNNNNYNYYNNNNNNNYYNNYNYNNYYNNNNYNNNNNYNNNNYNNNNYNNY??YNNNNYY\r\n", "output": ["NO"]}, {"input": "100 4\r\nYYNNNNYYYNNNNNNYNYYYNYYNYYNNYYNNNNNNNYNYYNYYNNYNNNNNYN?YNYYYNNYNNNNNYNNNNYYNYYYYYNYNNNNYYNNNNYNNNNYY\r\n", "output": ["NO"]}, {"input": "100 2\r\nYYNNYYYNNYYYYYYYYYYYYYYYNYYYNYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNYNYYYYYYNNYYYNYYNNYYNYYYYNYNYYYYYYNYYY\r\n", "output": ["YES"]}, {"input": "100 3\r\nYYYYYYYYNNNYNYNYYYYNY?YYYYYYNYYYNYYYYYYYYYYYYNNYYYYYNYNYYNYYYYYYYYYYYYYYYYYYY?YYNNYYNNYYYNYYYYYYYYYY\r\n", "output": ["YES"]}, {"input": "100 2\r\nYYYYYYYYYYYNYYYYYYYYYYYYYYYYYYYYYYYYYNYY?YYYYYYYYYYYYYYYNYYYYYYYYYYYYNNYYYYYYYYYNYYYYYYYYYYNYYYYYYYY\r\n", "output": ["YES"]}, {"input": "100 3\r\nNYNNYYYYYYNYNNYYYYYYNYYNYNYYYYYNYYYYYNNNYYYYYNYNYYNYYNYYNYNNNYYNYYYYYNYYYYYYNNYYNYNNYYNYYYY?YYNNYYNN\r\n", "output": ["YES"]}, {"input": "100 26\r\nNNYNNNNNNNNNNNNN?NNNNNNNNNNNNNYNNNNYNNNNNNNNNNNNYNNNNNN?NNNYNNNNNNNNNNYYNNNNNNNNYNNNNNNNNYYYNNNNYYNY\r\n", "output": ["NO"]}, {"input": "1 1\r\nY\r\n", "output": ["NO"]}, {"input": "1 1\r\nN\r\n", "output": ["YES"]}, {"input": "1 1\r\n?\r\n", "output": ["YES"]}, {"input": "1 0\r\n?\r\n", "output": ["YES"]}, {"input": "1 0\r\nN\r\n", "output": ["NO"]}, {"input": "1 0\r\nY\r\n", "output": ["YES"]}, {"input": "100 100\r\n????????????????????????????????????????????????????????????????????????????????????????????????????\r\n", "output": ["YES"]}, {"input": "6 4\r\nNN??NN\r\n", "output": ["NO"]}, {"input": "6 3\r\nNNYYN?\r\n", "output": ["NO"]}, {"input": "7 3\r\nN?YY???\r\n", "output": ["YES"]}, {"input": "24 4\r\nY?NYYNYYYNYYN?NNN?N?Y?Y?\r\n", "output": ["NO"]}, {"input": "3 3\r\n?Y?\r\n", "output": ["NO"]}, {"input": "10 1\r\nNY???NY?Y?\r\n", "output": ["YES"]}, {"input": "20 8\r\nNNNYY?????NN???N?YN?\r\n", "output": ["YES"]}, {"input": "30 2\r\n??????????????????????????????\r\n", "output": ["YES"]}, {"input": "40 17\r\nNNNNNNNNNNNNNNNNNYNNNNYNNYNNNNNNYNNNNNNN\r\n", "output": ["YES"]}, {"input": "51 5\r\nY??N????????Y??N?????N???N???YN?N?Y?N??Y?Y??Y???NN?\r\n", "output": ["YES"]}, {"input": "70 3\r\nY?N?Y???NN?NY?N?YY?Y????YNYY?Y?N??Y????YY??N????NY?NYY?YY?YYYY?YY?N?Y?\r\n", "output": ["YES"]}, {"input": "85 18\r\nNNNNNNN??Y???NN?YNNNNNNNN???YNNNNNN??Y?N?YNYYNN?NNNNNNNNNNNNNN????NNY??NNNN?NN??NNNNN\r\n", "output": ["YES"]}, {"input": "90 15\r\nYNNNNN?NNYNNYNNNN?NNNNYNNY?NNNNNNN?NNNNNNYN?NNYNNNNNN?NNYYNNYN?NNN??NNNNYNNN?YN?NNNNYNN?NY\r\n", "output": ["YES"]}, {"input": "99 1\r\nYYYYYYYNYYY??YY??YYYYYYY????NYY?YYY?Y??YYYY????YY?YY?YYY?YY??YYY?Y??NYYYY?YNYY??Y??YYYYY?YYY????YYY\r\n", "output": ["YES"]}, {"input": "100 34\r\n?NNNN??N???NNNN?NNN?N???N?N????NNNNNNN?N??N???NNNN???N?N?NN?NNNNN?NNN???N??NN??Y??NNN??N?NNN???NN?NN\r\n", "output": ["YES"]}, {"input": "100 21\r\n?NNNNNYNN??NNN?N????N?NN?N??NN?NNNY?NN?NY?NN?NNN?NN?N?NNNNNNY?NYNN??N??NYNN?NN?NNNN?N???NN?NN?Y?NYNY\r\n", "output": ["YES"]}, {"input": "100 10\r\nN?NNYYYNNNNNNYYNNYYNNNNNNNNYYNNNYYNNYNYNY?NNNNNNNNNYYNNNNYNNNNYNNNYNNYNNN?NNY?NNNNNNNNN?NYNYNNNNNNNN\r\n", "output": ["YES"]}, {"input": "100 6\r\n????????????????????????????????????????????????????????????????????????????????????????????????????\r\n", "output": ["YES"]}, {"input": "100 2\r\nYYNNYYYNNYYYYYYYYYYYYYYYNYYYNYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNYNYYYYYYNNYYYNYYNNYYNYYYYNYNYYYYYYNYYY\r\n", "output": ["YES"]}, {"input": "100 1\r\n???Y??????????????????????????????????????Y?????????N???Y????????Y?????Y???????Y??Y??????????YY?????\r\n", "output": ["YES"]}, {"input": "100 1\r\nYYYYYYYYY??YYN?YYNYYYYYYYNYYYYYYYYYYY?YN?YYYYY?YYYYYYYYYYYYY?YYYYYYYYYYYYN?YYYYYYYY?YYYYY?YYNYYYYYNY\r\n", "output": ["YES"]}, {"input": "100 3\r\n?YNNYYNYYYYYYNYYYYYNY?NNYYYYNYY??NYYNYNYYYY?YYNYYNYYYYYYYYYYNYYYYNYYYYNYYYYNYYNYYYYYYNYNYNYYYYYYNNYY\r\n", "output": ["YES"]}, {"input": "3 2\r\n?Y?\r\n", "output": ["NO"]}]
100
100
100
[{'input': '1 0\r\nN\r\n', 'output': ['NO']}, {'input': '51 1\r\nYYYNYNYNNYYNNY?YNYYYYYYNNYNYN??NYNYYNYYYYYYNNYNNNYY\r\n', 'output': ['NO']}, {'input': '100 10\r\nN?NNYYYNNNNNNYYNNYYNNNNNNNNYYNNNYYNNYNYNY?NNNNNNNNNYYNNNNYNNNNYNNNYNNYNNN?NNY?NNNNNNNNN?NYNYNNNNNNNN\r\n', 'output': ['YES']}, {'input': '100 34\r\n?NNNN??N???NNNN?NNN?N???N?N????NNNNNNN?N??N???NNNN???N?N?NN?NNNNN?NNN???N??NN??Y??NNN??N?NNN???NN?NN\r\n', 'output': ['YES']}, {'input': '1 0\r\nY\r\n', 'output': ['YES']}]
[{'input': '100 6\r\n????????????????????????????????????????????????????????????????????????????????????????????????????\r\n', 'output': ['YES']}, {'input': '100 26\r\nNNYNNNNNNNNNNNNN?NNNNNNNNNNNNNYNNNNYNNNNNNNNNNNNYNNNNNN?NNNYNNNNNNNNNNYYNNNNNNNNYNNNNNNNNYYYNNNNYYNY\r\n', 'output': ['NO']}, {'input': '100 1\r\nYYYYYYYYY??YYN?YYNYYYYYYYNYYYYYYYYYYY?YN?YYYYY?YYYYYYYYYYYYY?YYYYYYYYYYYYN?YYYYYYYY?YYYYY?YYNYYYYYNY\r\n', 'output': ['YES']}, {'input': '3 2\r\n?Y?\r\n', 'output': ['NO']}, {'input': '51 5\r\nY??N????????Y??N?????N???N???YN?N?Y?N??Y?Y??Y???NN?\r\n', 'output': ['YES']}]
[{'input': '20 7\r\nN?N??NNN?NNN?Y???Y??\r\n', 'output': ['YES']}, {'input': '100 8\r\nNYNNY?YNNNNNN?NNNNNYNY?YYNYNN?NNNY??NNYNYNNNYNNNYNNNNNNNNY?NNNYNYN?NNNY?YY?NNYNN?NNNYNNYNNYN?NNYNYNN\r\n', 'output': ['YES']}, {'input': '100 34\r\n?NNNN??N???NNNN?NNN?N???N?N????NNNNNNN?N??N???NNNN???N?N?NN?NNNNN?NNN???N??NN??Y??NNN??N?NNN???NN?NN\r\n', 'output': ['YES']}, {'input': '1 0\r\n?\r\n', 'output': ['YES']}, {'input': '100 4\r\nYYNNNNYYYNNNNNNYNYYYNYYNYYNNYYNNNNNNNYNYYNYYNNYNNNNNYN?YNYYYNNYNNNNNYNNNNYYNYYYYYNYNNNNYYNNNNYNNNNYY\r\n', 'output': ['NO']}]
[{'input': '100 10\r\nNNNNYNNNYNNNNNNNNYNYNYNNNNNYNNNNNYNNNNNNNNNNNYNYYNNNNNNNYYNNYNYNNYYNNNNYNNNNNYNNNNYNNNNYNNY??YNNNNYY\r\n', 'output': ['NO']}, {'input': '51 5\r\nY??N????????Y??N?????N???N???YN?N?Y?N??Y?Y??Y???NN?\r\n', 'output': ['YES']}, {'input': '7 3\r\nN?YY???\r\n', 'output': ['YES']}, {'input': '1 0\r\n?\r\n', 'output': ['YES']}, {'input': '90 15\r\nYNNNNN?NNYNNYNNNN?NNNNYNNY?NNNNNNN?NNNNNNYN?NNYNNNNNN?NNYYNNYN?NNN??NNNNYNNN?YN?NNNNYNN?NY\r\n', 'output': ['YES']}]
[{'input': '51 1\r\nYYYNYNYNNYYNNY?YNYYYYYYNNYNYN??NYNYYNYYYYYYNNYNNNYY\r\n', 'output': ['NO']}, {'input': '100 21\r\n?NNNNNYNN??NNN?N????N?NN?N??NN?NNNY?NN?NY?NN?NNN?NN?N?NNNNNNY?NYNN??N??NYNN?NN?NNNN?N???NN?NN?Y?NYNY\r\n', 'output': ['YES']}, {'input': '100 2\r\nYYYYYYYYYYYNYYYYYYYYYYYYYYYYYYYYYYYYYNYY?YYYYYYYYYYYYYYYNYYYYYYYYYYYYNNYYYYYYYYYNYYYYYYYYYYNYYYYYYYY\r\n', 'output': ['YES']}, {'input': '100 2\r\nYYNNYYYNNYYYYYYYYYYYYYYYNYYYNYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNYNYYYYYYNNYYYNYYNNYYNYYYYNYNYYYYYYNYYY\r\n', 'output': ['YES']}, {'input': '5 2\r\nNYNNY\r\n', 'output': ['YES']}]
100
100
100
100
100
100
91.3
100
100
95.65
96.43
89.29
96.43
96.43
85.71
201
100
97.39
92.858
["1 10 1 10 1", "1 5 6 10 1"]
First string contains five integer numbers l, r, x, y, k (1 ≀ l ≀ r ≀ 107, 1 ≀ x ≀ y ≀ 107, 1 ≀ k ≀ 107).
1110d3671e9f77fd8d66dca6e74d2048
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner scan=new Scanner(System.in); int l=scan.nextInt(); int r=scan.nextInt(); int x=scan.nextInt(); int y=scan.nextInt(); long k=scan.nextInt(); for(int i=x;i<=y;i++) if(k*i>=l&&k*i<=r){System.out.println("YES");return;} System.out.println("NO"); } }
["YES", "NO"]
Java
null
Print "YES" without quotes if a potion with efficiency exactly k can be bought in the store and "NO" without quotes otherwise. You can output each of the letters in any register.
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integersΒ β€” amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.For each two integer numbers a and b such that l ≀ a ≀ r and x ≀ b ≀ y there is a potion with experience a and cost b in the store (that is, there are (r - l + 1)Β·(y - x + 1) potions).Kirill wants to buy a potion which has efficiency k. Will he be able to do this?
[{"input": "1 10 1 10 1\r\n", "output": ["YES"]}, {"input": "1 5 6 10 1\r\n", "output": ["NO"]}, {"input": "1 1 1 1 1\r\n", "output": ["YES"]}, {"input": "1 1 1 1 2\r\n", "output": ["NO"]}, {"input": "1 100000 1 100000 100000\r\n", "output": ["YES"]}, {"input": "1 100000 1 100000 100001\r\n", "output": ["NO"]}, {"input": "25 10000 200 10000 5\r\n", "output": ["YES"]}, {"input": "1 100000 10 100000 50000\r\n", "output": ["NO"]}, {"input": "91939 94921 10197 89487 1\r\n", "output": ["NO"]}, {"input": "30518 58228 74071 77671 1\r\n", "output": ["NO"]}, {"input": "46646 79126 78816 91164 5\r\n", "output": ["NO"]}, {"input": "30070 83417 92074 99337 2\r\n", "output": ["NO"]}, {"input": "13494 17544 96820 99660 6\r\n", "output": ["NO"]}, {"input": "96918 97018 10077 86510 9\r\n", "output": ["YES"]}, {"input": "13046 45594 14823 52475 1\r\n", "output": ["YES"]}, {"input": "29174 40572 95377 97669 4\r\n", "output": ["NO"]}, {"input": "79894 92433 8634 86398 4\r\n", "output": ["YES"]}, {"input": "96022 98362 13380 94100 6\r\n", "output": ["YES"]}, {"input": "79446 95675 93934 96272 3\r\n", "output": ["NO"]}, {"input": "5440 46549 61481 99500 10\r\n", "output": ["NO"]}, {"input": "21569 53580 74739 87749 3\r\n", "output": ["NO"]}, {"input": "72289 78297 79484 98991 7\r\n", "output": ["NO"]}, {"input": "88417 96645 92742 98450 5\r\n", "output": ["NO"]}, {"input": "71841 96625 73295 77648 8\r\n", "output": ["NO"]}, {"input": "87969 99230 78041 94736 4\r\n", "output": ["NO"]}, {"input": "4 4 1 2 3\r\n", "output": ["NO"]}, {"input": "150 150 1 2 100\r\n", "output": ["NO"]}, {"input": "99 100 1 100 50\r\n", "output": ["YES"]}, {"input": "7 7 3 6 2\r\n", "output": ["NO"]}, {"input": "10 10 1 10 1\r\n", "output": ["YES"]}, {"input": "36 36 5 7 6\r\n", "output": ["YES"]}, {"input": "73 96 1 51 51\r\n", "output": ["NO"]}, {"input": "3 3 1 3 2\r\n", "output": ["NO"]}, {"input": "10000000 10000000 1 100000 10000000\r\n", "output": ["YES"]}, {"input": "9222174 9829060 9418763 9955619 9092468\r\n", "output": ["NO"]}, {"input": "70 70 1 2 50\r\n", "output": ["NO"]}, {"input": "100 200 1 20 5\r\n", "output": ["YES"]}, {"input": "1 200000 65536 65536 65537\r\n", "output": ["NO"]}, {"input": "15 15 1 100 1\r\n", "output": ["YES"]}, {"input": "10000000 10000000 1 10000000 100000\r\n", "output": ["YES"]}, {"input": "10 10 2 5 4\r\n", "output": ["NO"]}, {"input": "67 69 7 7 9\r\n", "output": ["NO"]}, {"input": "100000 10000000 1 10000000 100000\r\n", "output": ["YES"]}, {"input": "9 12 1 2 7\r\n", "output": ["NO"]}, {"input": "5426234 6375745 2636512 8492816 4409404\r\n", "output": ["NO"]}, {"input": "6134912 6134912 10000000 10000000 999869\r\n", "output": ["NO"]}, {"input": "3 3 1 100 1\r\n", "output": ["YES"]}, {"input": "10000000 10000000 10 10000000 100000\r\n", "output": ["YES"]}, {"input": "4 4 1 100 2\r\n", "output": ["YES"]}, {"input": "8 13 1 4 7\r\n", "output": ["NO"]}, {"input": "10 10 100000 10000000 10000000\r\n", "output": ["NO"]}, {"input": "5 6 1 4 2\r\n", "output": ["YES"]}, {"input": "1002 1003 1 2 1000\r\n", "output": ["NO"]}, {"input": "4 5 1 2 2\r\n", "output": ["YES"]}, {"input": "5 6 1 5 1\r\n", "output": ["YES"]}, {"input": "15 21 2 4 7\r\n", "output": ["YES"]}, {"input": "4 5 3 7 1\r\n", "output": ["YES"]}, {"input": "15 15 3 4 4\r\n", "output": ["NO"]}, {"input": "3 6 1 2 2\r\n", "output": ["YES"]}, {"input": "2 10 3 6 3\r\n", "output": ["YES"]}, {"input": "1 10000000 1 10000000 100000\r\n", "output": ["YES"]}, {"input": "8 13 1 2 7\r\n", "output": ["NO"]}, {"input": "98112 98112 100000 100000 128850\r\n", "output": ["NO"]}, {"input": "2 2 1 2 1\r\n", "output": ["YES"]}, {"input": "8 8 3 4 2\r\n", "output": ["YES"]}, {"input": "60 60 2 3 25\r\n", "output": ["NO"]}, {"input": "16 17 2 5 5\r\n", "output": ["NO"]}, {"input": "2 4 1 3 1\r\n", "output": ["YES"]}, {"input": "4 5 1 2 3\r\n", "output": ["NO"]}, {"input": "10 10 3 4 3\r\n", "output": ["NO"]}, {"input": "10 10000000 999999 10000000 300\r\n", "output": ["NO"]}, {"input": "100 120 9 11 10\r\n", "output": ["YES"]}, {"input": "8 20 1 3 4\r\n", "output": ["YES"]}, {"input": "10 14 2 3 4\r\n", "output": ["YES"]}, {"input": "2000 2001 1 3 1000\r\n", "output": ["YES"]}, {"input": "12 13 2 3 5\r\n", "output": ["NO"]}, {"input": "7 7 2 3 3\r\n", "output": ["NO"]}, {"input": "5 8 1 10000000 4\r\n", "output": ["YES"]}, {"input": "5 5 1 1 4\r\n", "output": ["NO"]}, {"input": "5 5 1 6 2\r\n", "output": ["NO"]}, {"input": "200 300 4000381 4000382 4000381\r\n", "output": ["NO"]}, {"input": "11 17 2 5 2\r\n", "output": ["NO"]}, {"input": "9999999 10000000 1 10000000 999997\r\n", "output": ["NO"]}, {"input": "7 8 2 3 3\r\n", "output": ["NO"]}, {"input": "7 7 3 3 2\r\n", "output": ["NO"]}, {"input": "15 15 2 3 7\r\n", "output": ["NO"]}, {"input": "65408 65408 859 859 10000000\r\n", "output": ["NO"]}, {"input": "1000000 10000000 1 100000 1\r\n", "output": ["NO"]}, {"input": "6 12 2 3 2\r\n", "output": ["YES"]}, {"input": "7 8 1 3 3\r\n", "output": ["NO"]}, {"input": "4 4 1 2 2\r\n", "output": ["YES"]}, {"input": "2 3 1 2 2\r\n", "output": ["YES"]}, {"input": "11 14 2 3 5\r\n", "output": ["NO"]}, {"input": "7 7 1 10 3\r\n", "output": ["NO"]}, {"input": "49 50 1 2 27\r\n", "output": ["NO"]}, {"input": "1 10000000 1 10000000 123456\r\n", "output": ["YES"]}, {"input": "100000 10000000 100 10000000 100000\r\n", "output": ["YES"]}, {"input": "17 19 2 3 8\r\n", "output": ["NO"]}, {"input": "4 6 3 9 1\r\n", "output": ["YES"]}, {"input": "19 20 6 7 3\r\n", "output": ["NO"]}, {"input": "5000000 10000000 1 4999999 1\r\n", "output": ["NO"]}]
100
100
100
[{'input': '5000000 10000000 1 4999999 1\r\n', 'output': ['NO']}, {'input': '2 3 1 2 2\r\n', 'output': ['YES']}, {'input': '99 100 1 100 50\r\n', 'output': ['YES']}, {'input': '10 10 2 5 4\r\n', 'output': ['NO']}, {'input': '9222174 9829060 9418763 9955619 9092468\r\n', 'output': ['NO']}]
[{'input': '5440 46549 61481 99500 10\r\n', 'output': ['NO']}, {'input': '200 300 4000381 4000382 4000381\r\n', 'output': ['NO']}, {'input': '10000000 10000000 10 10000000 100000\r\n', 'output': ['YES']}, {'input': '60 60 2 3 25\r\n', 'output': ['NO']}, {'input': '91939 94921 10197 89487 1\r\n', 'output': ['NO']}]
[{'input': '10 10 100000 10000000 10000000\r\n', 'output': ['NO']}, {'input': '2 4 1 3 1\r\n', 'output': ['YES']}, {'input': '1 1 1 1 2\r\n', 'output': ['NO']}, {'input': '5426234 6375745 2636512 8492816 4409404\r\n', 'output': ['NO']}, {'input': '79446 95675 93934 96272 3\r\n', 'output': ['NO']}]
[{'input': '7 7 3 6 2\r\n', 'output': ['NO']}, {'input': '15 21 2 4 7\r\n', 'output': ['YES']}, {'input': '3 6 1 2 2\r\n', 'output': ['YES']}, {'input': '99 100 1 100 50\r\n', 'output': ['YES']}, {'input': '1 100000 1 100000 100001\r\n', 'output': ['NO']}]
[{'input': '10000000 10000000 1 100000 10000000\r\n', 'output': ['YES']}, {'input': '4 4 1 100 2\r\n', 'output': ['YES']}, {'input': '30518 58228 74071 77671 1\r\n', 'output': ['NO']}, {'input': '1 1 1 1 1\r\n', 'output': ['YES']}, {'input': '11 17 2 5 2\r\n', 'output': ['NO']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
202
100
100
100
["4\nVKVK", "5\nBVVKV", "7\nVVKEVKK", "20\nVKVKVVVKVOVKVQKKKVVK", "5\nLIMAK"]
The first line of the input contains an integer n (1 ≀ n ≀ 75)Β β€” the length of the string. The second line contains a string s, consisting of uppercase English letters. The length of the string is equal to n.
08444f9ab1718270b5ade46852b155d7
import java.util.*; public class C_Bear_And_Company_3 { static int cv, ck , cs; static int[][] freq; static ArrayList<Integer>[] pos; static int[][][][] dp; public static void main(String[] agrs) { Scanner in = new Scanner(System.in); int n = in.nextInt(); char[] c = in.next().toCharArray(); cv = 0; ck = 0; cs = 0; freq = new int[n + 1][3]; pos = new ArrayList[3]; for (int i = 0; i < 3; i++) pos[i] = new ArrayList<>(); int idx = 0; for (char x : c) { System.arraycopy(freq[idx], 0, freq[idx + 1], 0, 3); idx++; if (x == 'V') { freq[idx][0]++; cv++; pos[0].add(idx); } else if (x == 'K') { freq[idx][1]++; ck++; pos[1].add(idx); } else { freq[idx][2]++; cs++; pos[2].add(idx); } } dp = new int[cv + 1][ck + 1][cs + 1][3]; for (int[][][] x : dp) for (int[][] y : x) for (int[] z : y) Arrays.fill(z, -1); System.out.println(dfs(0, 0, 0, 2)); } static int dfs(int tv, int tk, int ts, int last) { if (tv == cv && tk == ck && ts == cs) { return 0; } if (dp[tv][tk][ts][last] != -1) return dp[tv][tk][ts][last]; int ret = 1 << 29; if (tv < cv) { int p = pos[0].get(tv); int move = Math.max(freq[p][0] - tv, 0) + Math.max(freq[p][1] - tk, 0) + Math.max(freq[p][2] - ts, 0) - 1; ret = Math.min(ret, dfs(tv + 1, tk, ts, 0) + move); } if (tk < ck && last != 0) { int p = pos[1].get(tk); int move = Math.max(freq[p][0] - tv, 0) + Math.max(freq[p][1] - tk, 0) + Math.max(freq[p][2] - ts, 0) - 1; ret = Math.min(ret, dfs(tv, tk + 1, ts, 1) + move); } if (ts < cs) { int p = pos[2].get(ts); int move = Math.max(freq[p][0] - tv, 0) + Math.max(freq[p][1] - tk, 0) + Math.max(freq[p][2] - ts, 0) - 1; ret = Math.min(ret, dfs(tv, tk, ts + 1, 2) + move); } return dp[tv][tk][ts][last] = ret; } }
["3", "2", "3", "8", "0"]
Java
NoteIn the first sample, the initial string is "VKVK". The minimum possible number of moves is 3. One optimal sequence of moves is: Swap two last letters. The string becomes "VKKV". Swap first two letters. The string becomes "KVKV". Swap the second and the third letter. The string becomes "KKVV". Indeed, this string doesn't have a substring "VK".In the second sample, there are two optimal sequences of moves. One is "BVVKV"  →  "VBVKV"  →  "VVBKV". The other is "BVVKV"  →  "BVKVV"  →  "BKVVV".In the fifth sample, no swaps are necessary.
Print one integer, denoting the minimum possible number of moves Limak can do, in order to obtain a string without a substring "VK".
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible.Limak has a string s that consists of uppercase English letters. In one move he can swap two adjacent letters of the string. For example, he can transform a string "ABBC" into "BABC" or "ABCB" in one move.Limak wants to obtain a string without a substring "VK" (i.e. there should be no letter 'V' immediately followed by letter 'K'). It can be easily proved that it's possible for any initial string s.What is the minimum possible number of moves Limak can do?
[{"input": "4\r\nVKVK\r\n", "output": ["3"]}, {"input": "5\r\nBVVKV\r\n", "output": ["2"]}, {"input": "7\r\nVVKEVKK\r\n", "output": ["3"]}, {"input": "20\r\nVKVKVVVKVOVKVQKKKVVK\r\n", "output": ["8"]}, {"input": "5\r\nLIMAK\r\n", "output": ["0"]}, {"input": "1\r\nV\r\n", "output": ["0"]}, {"input": "1\r\nK\r\n", "output": ["0"]}, {"input": "1\r\nZ\r\n", "output": ["0"]}, {"input": "17\r\nVAKVAKLIMAKVVVKKK\r\n", "output": ["4"]}, {"input": "10\r\nVVKAVZVAAZ\r\n", "output": ["1"]}, {"input": "17\r\nQZVRZKDKMZZAKKZVA\r\n", "output": ["0"]}, {"input": "51\r\nAVVVVVVVVVVKKKKKKKKKKVVVVVVVVVVVVVVVKKKKKKKKKKKKKKK\r\n", "output": ["135"]}, {"input": "75\r\nVFZVZRVZAZJAKAZKAVVKZKVHZZZZAVAAKKAADKNAKRFKAAAZKZVAKAAAJAVKYAAZAKAVKASZAAK\r\n", "output": ["3"]}, {"input": "75\r\nVVKAVKKVAKVXCKKZKKAVVVAKKKKVVKSKVVWVLEVVHVXKKKVKVJKVVVZVVKKKVVKVVVKKKVVKZKV\r\n", "output": ["19"]}, {"input": "2\r\nVK\r\n", "output": ["1"]}, {"input": "2\r\nKV\r\n", "output": ["0"]}, {"input": "3\r\nVKK\r\n", "output": ["2"]}, {"input": "3\r\nKVV\r\n", "output": ["0"]}, {"input": "75\r\nVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKV\r\n", "output": ["703"]}, {"input": "75\r\nVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKOOOKVKV\r\n", "output": ["175"]}, {"input": "6\r\nVVVKKK\r\n", "output": ["9"]}, {"input": "7\r\nVVVKKKO\r\n", "output": ["3"]}, {"input": "12\r\nVKVKVKVKVKVK\r\n", "output": ["21"]}, {"input": "5\r\nVKOVK\r\n", "output": ["2"]}, {"input": "3\r\nKKV\r\n", "output": ["0"]}, {"input": "6\r\nVVOKKK\r\n", "output": ["0"]}, {"input": "15\r\nVOKVOKVVKKKKKKK\r\n", "output": ["4"]}, {"input": "10\r\nKKZKKVKZKV\r\n", "output": ["1"]}, {"input": "15\r\nVKKHKKKKZVKKVKV\r\n", "output": ["4"]}, {"input": "22\r\nVKKVKVKKVKVKZKKVKVAKKK\r\n", "output": ["14"]}, {"input": "46\r\nVVFVKKVAKVKKVGVKKKKZKKKKKKKAKKZKVVVVKKZVVKFVKK\r\n", "output": ["9"]}, {"input": "50\r\nKKAKVVNAVVVVKKVKKZVKKKKVKFTVVKKVVVVVZVLKKKKKKVKVVV\r\n", "output": ["11"]}, {"input": "75\r\nVKVVKVKKKVVZKVZKVKVKVVKIAVKVVVKKKVDKVKKVKAKKAKNAKVZKAAVVAKUKVKKVKKVZVAKKKVV\r\n", "output": ["27"]}, {"input": "75\r\nAJAKVZASUKAYZFSZRPAAVAGZKFZZHZZZKKKVLQAAVAHQHAZCVEZAAZZAAZIAAAZKKAAUKROVKAK\r\n", "output": ["1"]}, {"input": "75\r\nKAVVZVKKVVKVKVLVVKKKVVAKVVKEVAVVKKVVKVDVVKKVKKVZKKAKKKVKVZAVVKKKZVVDKVVAKZV\r\n", "output": ["20"]}, {"input": "75\r\nVKKVKKAKKKVVVVVZKKKKVKAVKKAZKKKKVKVVKVVKVVKCKKVVVVVZKKVKKKVKKKVVKVKVKOVVZKK\r\n", "output": ["26"]}, {"input": "74\r\nVVVKVKKKAZVVVKKKKKVVVVKKVVVKKVAKVVVVVVKVKVKVVMVVKVVVKVKKVVVVVKVKKKVVVXKVVK\r\n", "output": ["66"]}, {"input": "74\r\nVJVKVUKVVVVVVKVLVKKVVKZVNZVKKVVVAVVVKKAKZKZVAZVVKVKKZKKVNAVAKVKKCVVVKKVKVV\r\n", "output": ["19"]}, {"input": "75\r\nZXPZMAKZZZZZZAZXAZAAPOAFAZUZZAZABQZZAZZBZAAAZZFANYAAZZZZAZHZARACAAZAZDPCAVZ\r\n", "output": ["0"]}, {"input": "75\r\nVZVVVZAUVZZTZZCTJZAVZVSVAAACVAHZVVAFZSVVAZAZVXVKVZVZVVZTAZREOVZZEVAVBAVAAAF\r\n", "output": ["1"]}, {"input": "75\r\nAZKZWAOZZLTZIZTAYKOALAAKKKZAASKAAZFHVZKZAAZUKAKZZBIAZZWAZZZZZPZZZRAZZZAZJZA\r\n", "output": ["0"]}, {"input": "52\r\nVAVBVCVDVEVFVGVHVIVJVKVLVMVNVOVPVQVRVSVTVUVVVWVXVYVZ\r\n", "output": ["1"]}, {"input": "52\r\nAKBKCKDKEKFKGKHKIKJKKKLKMKNKOKPKQKRKSKTKUKVKWKXKYKZK\r\n", "output": ["1"]}, {"input": "64\r\nVVKKVAVBVCVDVEVFVGVHVIVJVKVLVMVNVOVPVQVRVSVTVUVVVWVXVYVZVVVKKKKK\r\n", "output": ["7"]}, {"input": "64\r\nVVKKAKBKCKDKEKFKGKHKIKJKKKLKMKNKOKPKQKRKSKTKUKVKWKXKYKZKVVVKKKKK\r\n", "output": ["7"]}, {"input": "75\r\nVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK\r\n", "output": ["1406"]}, {"input": "75\r\nVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK\r\n", "output": ["1406"]}, {"input": "72\r\nAVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK\r\n", "output": ["35"]}, {"input": "73\r\nAVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKB\r\n", "output": ["32"]}, {"input": "72\r\nAVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKB\r\n", "output": ["30"]}, {"input": "67\r\nVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKXVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKK\r\n", "output": ["213"]}, {"input": "57\r\nVVVVKKKKKKAAVVVVVVVVKKKKKKKVVVVVVVVVKKKKKKKKKKKKKKKKKKKKO\r\n", "output": ["34"]}, {"input": "13\r\nVVVVKKAVVKVKK\r\n", "output": ["10"]}, {"input": "65\r\nVVVVKKAVVKVKKVVVVKKAVVKVKKVVVVKKAVVKVKKVVVVKKAVVKVKKVVVVKKAVVKVKK\r\n", "output": ["50"]}, {"input": "67\r\nVVVVKKAVVKVKKVVVVKKAVVKVKKAOVVVVKKAVVKVKKVVVVKKAVVKVKKVVVVKKAVVKVKK\r\n", "output": ["44"]}, {"input": "52\r\nZVKVVKKKVKKZKZVKVVKKKVKKZKZVKVVKKKVKKZKZVKVVKKKVKKZK\r\n", "output": ["28"]}, {"input": "63\r\nKKKVVVKAAKVVVTVVVKAUVKKKVKVKKVKVKVVKVKKVKVKKKQVKVVVKVKKVKKKKKKZ\r\n", "output": ["43"]}, {"input": "75\r\nVVKVKKKVKVVKKKKKVVKKKKVVVKVKKKAVAKKKVVKVKEVVVVVVVVKKKKKVVVVVKVVVKKKVVKVVKVV\r\n", "output": ["114"]}, {"input": "75\r\nVVVVVKVKVVKKEVVVVVAKVKKZKVVPKKZKAVKVAKVMZKZVUVKKIVVZVVVKVKZVVVVKKVKVZZVOVKV\r\n", "output": ["23"]}, {"input": "75\r\nVAKKVKVKKZVVZAVKKVKVZKKVKVVKKAVKKKVVZVKVKVKKKKVVVVKKVZKVVKKKVAKKZVKKVKVVKVK\r\n", "output": ["36"]}, {"input": "75\r\nVVKVKKVZAVVKHKRAVKAKVKKVKKAAVKVVNZVKKKVVKMAVVKKWKKVVKVHKKVKVZVVKZZKVKVIKZVK\r\n", "output": ["22"]}, {"input": "75\r\nKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK\r\n", "output": ["0"]}, {"input": "75\r\nVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\r\n", "output": ["0"]}, {"input": "75\r\nVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVK\r\n", "output": ["74"]}, {"input": "75\r\nKVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\r\n", "output": ["0"]}, {"input": "38\r\nZKKKVVVVVVVVVVKKKKKEVVKKVVVKKKVVVVKKKK\r\n", "output": ["40"]}, {"input": "74\r\nZKKKVVVVVVVVVVKKKKKEVVKKVVVKKKVVVVKKKKVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKK\r\n", "output": ["98"]}, {"input": "71\r\nZKKKVVVVVVVKKKKKEVVKKVVVKKKVVVVKKKKVVVVVVVVKKKKKKKKKKKVVVVVVVVVVKKKKKKK\r\n", "output": ["153"]}, {"input": "68\r\nKKVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKV\r\n", "output": ["400"]}, {"input": "75\r\nKVVKCVKVVVVKVVVKVKVAVVMVVVVVKKVVVKVVVVVKKVVVVVKVVKVVVKKKKKVKKVKAVVVVVVVVVVK\r\n", "output": ["71"]}, {"input": "74\r\nKKKZKVKKKKVKKKKVKVZKKKZKKKKKZKVKKZZKKBVKKVAKVKVKZVVKKKKKKKKKVKKVVKKVVKKKVK\r\n", "output": ["45"]}, {"input": "75\r\nKVKVVKVKVKVVVVVKVKKKVKVVKVVKVVKKKKEKVVVKKKVVKVVVVVVVKKVKKVVVKAKVVKKVVVVVKUV\r\n", "output": ["103"]}, {"input": "75\r\nKKVVAVVVVKVKAVVAKVKVKVVVVKKKKKAZVKVKVKJVVVAKVVKKKVVVVZVAVVVZKVZAKVVVVVVVAKK\r\n", "output": ["18"]}]
100
100
100
[{'input': '10\r\nKKZKKVKZKV\r\n', 'output': ['1']}, {'input': '1\r\nK\r\n', 'output': ['0']}, {'input': '57\r\nVVVVKKKKKKAAVVVVVVVVKKKKKKKVVVVVVVVVKKKKKKKKKKKKKKKKKKKKO\r\n', 'output': ['34']}, {'input': '71\r\nZKKKVVVVVVVKKKKKEVVKKVVVKKKVVVVKKKKVVVVVVVVKKKKKKKKKKKVVVVVVVVVVKKKKKKK\r\n', 'output': ['153']}, {'input': '74\r\nZKKKVVVVVVVVVVKKKKKEVVKKVVVKKKVVVVKKKKVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKK\r\n', 'output': ['98']}]
[{'input': '75\r\nZXPZMAKZZZZZZAZXAZAAPOAFAZUZZAZABQZZAZZBZAAAZZFANYAAZZZZAZHZARACAAZAZDPCAVZ\r\n', 'output': ['0']}, {'input': '10\r\nVVKAVZVAAZ\r\n', 'output': ['1']}, {'input': '65\r\nVVVVKKAVVKVKKVVVVKKAVVKVKKVVVVKKAVVKVKKVVVVKKAVVKVKKVVVVKKAVVKVKK\r\n', 'output': ['50']}, {'input': '75\r\nVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\r\n', 'output': ['0']}, {'input': '52\r\nAKBKCKDKEKFKGKHKIKJKKKLKMKNKOKPKQKRKSKTKUKVKWKXKYKZK\r\n', 'output': ['1']}]
[{'input': '50\r\nKKAKVVNAVVVVKKVKKZVKKKKVKFTVVKKVVVVVZVLKKKKKKVKVVV\r\n', 'output': ['11']}, {'input': '17\r\nQZVRZKDKMZZAKKZVA\r\n', 'output': ['0']}, {'input': '75\r\nAJAKVZASUKAYZFSZRPAAVAGZKFZZHZZZKKKVLQAAVAHQHAZCVEZAAZZAAZIAAAZKKAAUKROVKAK\r\n', 'output': ['1']}, {'input': '74\r\nVJVKVUKVVVVVVKVLVKKVVKZVNZVKKVVVAVVVKKAKZKZVAZVVKVKKZKKVNAVAKVKKCVVVKKVKVV\r\n', 'output': ['19']}, {'input': '72\r\nAVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKB\r\n', 'output': ['30']}]
[{'input': '75\r\nVVVVVKVKVVKKEVVVVVAKVKKZKVVPKKZKAVKVAKVMZKZVUVKKIVVZVVVKVKZVVVVKKVKVZZVOVKV\r\n', 'output': ['23']}, {'input': '2\r\nKV\r\n', 'output': ['0']}, {'input': '5\r\nLIMAK\r\n', 'output': ['0']}, {'input': '75\r\nKVVKCVKVVVVKVVVKVKVAVVMVVVVVKKVVVKVVVVVKKVVVVVKVVKVVVKKKKKVKKVKAVVVVVVVVVVK\r\n', 'output': ['71']}, {'input': '68\r\nKKVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKV\r\n', 'output': ['400']}]
[{'input': '75\r\nVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKV\r\n', 'output': ['703']}, {'input': '64\r\nVVKKVAVBVCVDVEVFVGVHVIVJVKVLVMVNVOVPVQVRVSVTVUVVVWVXVYVZVVVKKKKK\r\n', 'output': ['7']}, {'input': '51\r\nAVVVVVVVVVVKKKKKKKKKKVVVVVVVVVVVVVVVKKKKKKKKKKKKKKK\r\n', 'output': ['135']}, {'input': '72\r\nAVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK\r\n', 'output': ['35']}, {'input': '52\r\nZVKVVKKKVKKZKZVKVVKKKVKKZKZVKVVKKKVKKZKZVKVVKKKVKKZK\r\n', 'output': ['28']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
203
100
100
100
["mew", "wuffuw", "qqqqqqqq"]
The first line contains a non-empty string $$$s$$$ with length at most $$$50$$$ characters, containing lowercase English letters only.
6c85175d334f811617e7030e0403f706
import java.util.HashSet; import java.util.Scanner; public class Nafis { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); int sz = str.length(); HashSet<Character> freq = new HashSet<>(); for (int i = 0; i <= sz / 2; i++) { if (str.charAt(i) == str.charAt(sz - i - 1)) { freq.add(str.charAt(i)); continue; } else { System.out.println(sz); return; } } System.out.println(freq.size() == 1 ? 0 : sz - 1); } }
["3", "5", "0"]
Java
Note"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $$$3$$$.The string "uffuw" is one of the longest non-palindrome substrings (of length $$$5$$$) of the string "wuffuw", so the answer for the second example is $$$5$$$.All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $$$0$$$.
If there is such a substring in $$$s$$$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $$$0$$$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.A substring $$$s[l \ldots r]$$$ ($$$1 \leq l \leq r \leq |s|$$$) of a string $$$s = s_{1}s_{2} \ldots s_{|s|}$$$ is the string $$$s_{l}s_{l + 1} \ldots s_{r}$$$.Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $$$s$$$ is changed into its longest substring that is not a palindrome. If all the substrings of $$$s$$$ are palindromes, she skips the word at all.Some time ago Ann read the word $$$s$$$. What is the word she changed it into?
[{"input": "mew\r\n", "output": ["3"]}, {"input": "wuffuw\r\n", "output": ["5"]}, {"input": "qqqqqqqq\r\n", "output": ["0"]}, {"input": "ijvji\r\n", "output": ["4"]}, {"input": "iiiiiii\r\n", "output": ["0"]}, {"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow\r\n", "output": ["49"]}, {"input": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\r\n", "output": ["0"]}, {"input": "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy\r\n", "output": ["50"]}, {"input": "ijvxljt\r\n", "output": ["7"]}, {"input": "fyhcncnchyf\r\n", "output": ["10"]}, {"input": "ffffffffffff\r\n", "output": ["0"]}, {"input": "fyhcncfsepqj\r\n", "output": ["12"]}, {"input": "ybejrrlbcinttnicblrrjeby\r\n", "output": ["23"]}, {"input": "yyyyyyyyyyyyyyyyyyyyyyyyy\r\n", "output": ["0"]}, {"input": "ybejrrlbcintahovgjddrqatv\r\n", "output": ["25"]}, {"input": "oftmhcmclgyqaojljoaqyglcmchmtfo\r\n", "output": ["30"]}, {"input": "oooooooooooooooooooooooooooooooo\r\n", "output": ["0"]}, {"input": "oftmhcmclgyqaojllbotztajglsmcilv\r\n", "output": ["32"]}, {"input": "gxandbtgpbknxvnkjaajknvxnkbpgtbdnaxg\r\n", "output": ["35"]}, {"input": "gggggggggggggggggggggggggggggggggggg\r\n", "output": ["0"]}, {"input": "gxandbtgpbknxvnkjaygommzqitqzjfalfkk\r\n", "output": ["36"]}, {"input": "fcliblymyqckxvieotjooojtoeivxkcqymylbilcf\r\n", "output": ["40"]}, {"input": "fffffffffffffffffffffffffffffffffffffffffff\r\n", "output": ["0"]}, {"input": "fcliblymyqckxvieotjootiqwtyznhhvuhbaixwqnsy\r\n", "output": ["43"]}, {"input": "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr\r\n", "output": ["0"]}, {"input": "rajccqwqnqmshmerpvjyfepxwpxyldzpzhctqjnstxyfmlhiy\r\n", "output": ["49"]}, {"input": "a\r\n", "output": ["0"]}, {"input": "abca\r\n", "output": ["4"]}, {"input": "aaaaabaaaaa\r\n", "output": ["10"]}, {"input": "aba\r\n", "output": ["2"]}, {"input": "asaa\r\n", "output": ["4"]}, {"input": "aabaa\r\n", "output": ["4"]}, {"input": "aabbaa\r\n", "output": ["5"]}, {"input": "abcdaaa\r\n", "output": ["7"]}, {"input": "aaholaa\r\n", "output": ["7"]}, {"input": "abcdefghijka\r\n", "output": ["12"]}, {"input": "aaadcba\r\n", "output": ["7"]}, {"input": "aaaabaaaa\r\n", "output": ["8"]}, {"input": "abaa\r\n", "output": ["4"]}, {"input": "abcbaa\r\n", "output": ["6"]}, {"input": "ab\r\n", "output": ["2"]}, {"input": "l\r\n", "output": ["0"]}, {"input": "aaaabcaaaa\r\n", "output": ["10"]}, {"input": "abbaaaaaabba\r\n", "output": ["11"]}, {"input": "abaaa\r\n", "output": ["5"]}, {"input": "baa\r\n", "output": ["3"]}, {"input": "aaaaaaabbba\r\n", "output": ["11"]}, {"input": "ccbcc\r\n", "output": ["4"]}, {"input": "bbbaaab\r\n", "output": ["7"]}, {"input": "abaaaaaaaa\r\n", "output": ["10"]}, {"input": "abaaba\r\n", "output": ["5"]}, {"input": "aabsdfaaaa\r\n", "output": ["10"]}, {"input": "aaaba\r\n", "output": ["5"]}, {"input": "aaabaaa\r\n", "output": ["6"]}, {"input": "baaabbb\r\n", "output": ["7"]}, {"input": "ccbbabbcc\r\n", "output": ["8"]}, {"input": "cabc\r\n", "output": ["4"]}, {"input": "aabcd\r\n", "output": ["5"]}, {"input": "abcdea\r\n", "output": ["6"]}, {"input": "bbabb\r\n", "output": ["4"]}, {"input": "aaaaabababaaaaa\r\n", "output": ["14"]}, {"input": "bbabbb\r\n", "output": ["6"]}, {"input": "aababd\r\n", "output": ["6"]}, {"input": "abaaaa\r\n", "output": ["6"]}, {"input": "aaaaaaaabbba\r\n", "output": ["12"]}, {"input": "aabca\r\n", "output": ["5"]}, {"input": "aaabccbaaa\r\n", "output": ["9"]}, {"input": "aaaaaaaaaaaaaaaaaaaab\r\n", "output": ["21"]}, {"input": "babb\r\n", "output": ["4"]}, {"input": "abcaa\r\n", "output": ["5"]}, {"input": "qwqq\r\n", "output": ["4"]}, {"input": "aaaaaaaaaaabbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": ["48"]}, {"input": "aaab\r\n", "output": ["4"]}, {"input": "aaaaaabaaaaa\r\n", "output": ["12"]}, {"input": "wwuww\r\n", "output": ["4"]}, {"input": "aaaaabcbaaaaa\r\n", "output": ["12"]}, {"input": "aaabbbaaa\r\n", "output": ["8"]}, {"input": "aabcbaa\r\n", "output": ["6"]}, {"input": "abccdefccba\r\n", "output": ["11"]}, {"input": "aabbcbbaa\r\n", "output": ["8"]}, {"input": "aaaabbaaaa\r\n", "output": ["9"]}, {"input": "aabcda\r\n", "output": ["6"]}, {"input": "abbca\r\n", "output": ["5"]}, {"input": "aaaaaabbaaa\r\n", "output": ["11"]}, {"input": "sssssspssssss\r\n", "output": ["12"]}, {"input": "sdnmsdcs\r\n", "output": ["8"]}, {"input": "aaabbbccbbbaaa\r\n", "output": ["13"]}, {"input": "cbdbdc\r\n", "output": ["6"]}, {"input": "abb\r\n", "output": ["3"]}, {"input": "abcdefaaaa\r\n", "output": ["10"]}, {"input": "abbbaaa\r\n", "output": ["7"]}, {"input": "v\r\n", "output": ["0"]}, {"input": "abccbba\r\n", "output": ["7"]}, {"input": "axyza\r\n", "output": ["5"]}, {"input": "abcdefgaaaa\r\n", "output": ["11"]}, {"input": "aaabcdaaa\r\n", "output": ["9"]}, {"input": "aaaacaaaa\r\n", "output": ["8"]}, {"input": "aaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaa\r\n", "output": ["42"]}, {"input": "abbbaa\r\n", "output": ["6"]}, {"input": "abcdee\r\n", "output": ["6"]}, {"input": "oom\r\n", "output": ["3"]}, {"input": "aabcaa\r\n", "output": ["6"]}, {"input": "abba\r\n", "output": ["3"]}, {"input": "aaca\r\n", "output": ["4"]}, {"input": "aacbca\r\n", "output": ["6"]}, {"input": "ababa\r\n", "output": ["4"]}, {"input": "abcda\r\n", "output": ["5"]}, {"input": "cccaaccc\r\n", "output": ["7"]}, {"input": "aaabcda\r\n", "output": ["7"]}, {"input": "aa\r\n", "output": ["0"]}, {"input": "aabaaaa\r\n", "output": ["7"]}, {"input": "abbaaaa\r\n", "output": ["7"]}, {"input": "aaabcbaaa\r\n", "output": ["8"]}, {"input": "aabba\r\n", "output": ["5"]}, {"input": "xyxx\r\n", "output": ["4"]}, {"input": "aaaaaaaaaaaabc\r\n", "output": ["14"]}, {"input": "bbaaaabb\r\n", "output": ["7"]}, {"input": "aaabaa\r\n", "output": ["6"]}, {"input": "sssssabsssss\r\n", "output": ["12"]}, {"input": "bbbaaaabbb\r\n", "output": ["9"]}, {"input": "abbbbaaaa\r\n", "output": ["9"]}, {"input": "wwufuww\r\n", "output": ["6"]}, {"input": "oowoo\r\n", "output": ["4"]}, {"input": "cccaccc\r\n", "output": ["6"]}, {"input": "aaa\r\n", "output": ["0"]}, {"input": "bbbcc\r\n", "output": ["5"]}, {"input": "abcdef\r\n", "output": ["6"]}, {"input": "abbba\r\n", "output": ["4"]}, {"input": "aab\r\n", "output": ["3"]}, {"input": "aaba\r\n", "output": ["4"]}, {"input": "azbyaaa\r\n", "output": ["7"]}, {"input": "oooooiooooo\r\n", "output": ["10"]}, {"input": "aabbbbbaaaaaa\r\n", "output": ["13"]}]
100
100
100
[{'input': 'aaabcda\r\n', 'output': ['7']}, {'input': 'abbaaaaaabba\r\n', 'output': ['11']}, {'input': 'oftmhcmclgyqaojljoaqyglcmchmtfo\r\n', 'output': ['30']}, {'input': 'aabca\r\n', 'output': ['5']}, {'input': 'abcda\r\n', 'output': ['5']}]
[{'input': 'abcdefgaaaa\r\n', 'output': ['11']}, {'input': 'abcaa\r\n', 'output': ['5']}, {'input': 'aabbbbbaaaaaa\r\n', 'output': ['13']}, {'input': 'aabaa\r\n', 'output': ['4']}, {'input': 'yyyyyyyyyyyyyyyyyyyyyyyyy\r\n', 'output': ['0']}]
[{'input': 'ababa\r\n', 'output': ['4']}, {'input': 'cabc\r\n', 'output': ['4']}, {'input': 'abbbaaa\r\n', 'output': ['7']}, {'input': 'sssssspssssss\r\n', 'output': ['12']}, {'input': 'abbaaaaaabba\r\n', 'output': ['11']}]
[{'input': 'abaaaaaaaa\r\n', 'output': ['10']}, {'input': 'abba\r\n', 'output': ['3']}, {'input': 'aabcd\r\n', 'output': ['5']}, {'input': 'abbbaaa\r\n', 'output': ['7']}, {'input': 'aacbca\r\n', 'output': ['6']}]
[{'input': 'rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr\r\n', 'output': ['0']}, {'input': 'yyyyyyyyyyyyyyyyyyyyyyyyy\r\n', 'output': ['0']}, {'input': 'aba\r\n', 'output': ['2']}, {'input': 'cabc\r\n', 'output': ['4']}, {'input': 'aaaaabababaaaaa\r\n', 'output': ['14']}]
100
100
100
100
100
100
100
100
100
100
83.33
100
83.33
83.33
100
204
100
100
89.998
["1f", "2d", "4a", "5e"]
The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space.
069d0cb9b7c798a81007fb5b63fa0f45
import java.util.*; import java.math.*; import java.io.*; public class FoodOnThePlane { public static void main(String args[]) throws Exception { BufferedReader s = new BufferedReader(new InputStreamReader(System.in)); //BufferedReader s = new BufferedReader(new FileReader("*.in")); //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("*.out"))); //StringTokenizer st = new StringTokenizer(s.readLine()); String y = s.readLine(); long row = Long.parseLong(y.substring(0, y.length()-1)); int col = y.charAt(y.length()-1) - 'a'; long secs = 0; if(row == 1)secs = 0; else if (row == 2)secs = 7; else { long remainder = row % 4; if(remainder == 1){ secs = ((row - 1) / 4) * 16; } else if (remainder == 3){ secs = ((row - 3)/4) * 16; } else if (remainder == 2){ secs = ((((row + 2) / 4)-1) * 16)+7; } else { secs = (((row / 4)-1) * 16)+7; } } if(col == 0){ secs += 4; } else if(col == 1){ secs += 5; } else if(col == 2){ secs += 6; } else if(col == 3){ secs += 3; } else if(col == 4){ secs += 2; } else { secs+=1; } System.out.println(secs); } }
["1", "10", "11", "18"]
Java
NoteIn the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.
Print one integerΒ β€” the number of seconds Vasya has to wait until he gets his lunch.
A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. Β It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last oneΒ β€” in seat 'c'. Assume that all seats are occupied.Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch.
[{"input": "1f\r\n", "output": ["1"]}, {"input": "2d\r\n", "output": ["10"]}, {"input": "4a\r\n", "output": ["11"]}, {"input": "5e\r\n", "output": ["18"]}, {"input": "2c\r\n", "output": ["13"]}, {"input": "1b\r\n", "output": ["5"]}, {"input": "1000000000000000000d\r\n", "output": ["3999999999999999994"]}, {"input": "999999999999999997a\r\n", "output": ["3999999999999999988"]}, {"input": "1c\r\n", "output": ["6"]}, {"input": "1d\r\n", "output": ["3"]}, {"input": "1e\r\n", "output": ["2"]}, {"input": "1a\r\n", "output": ["4"]}, {"input": "2a\r\n", "output": ["11"]}, {"input": "2b\r\n", "output": ["12"]}, {"input": "2e\r\n", "output": ["9"]}, {"input": "2f\r\n", "output": ["8"]}, {"input": "3a\r\n", "output": ["4"]}, {"input": "3b\r\n", "output": ["5"]}, {"input": "3c\r\n", "output": ["6"]}, {"input": "3d\r\n", "output": ["3"]}, {"input": "3e\r\n", "output": ["2"]}, {"input": "3f\r\n", "output": ["1"]}, {"input": "4b\r\n", "output": ["12"]}, {"input": "4c\r\n", "output": ["13"]}, {"input": "4d\r\n", "output": ["10"]}, {"input": "4e\r\n", "output": ["9"]}, {"input": "4f\r\n", "output": ["8"]}, {"input": "999999997a\r\n", "output": ["3999999988"]}, {"input": "999999997b\r\n", "output": ["3999999989"]}, {"input": "999999997c\r\n", "output": ["3999999990"]}, {"input": "999999997d\r\n", "output": ["3999999987"]}, {"input": "999999997e\r\n", "output": ["3999999986"]}, {"input": "999999997f\r\n", "output": ["3999999985"]}, {"input": "999999998a\r\n", "output": ["3999999995"]}, {"input": "999999998b\r\n", "output": ["3999999996"]}, {"input": "999999998c\r\n", "output": ["3999999997"]}, {"input": "999999998d\r\n", "output": ["3999999994"]}, {"input": "999999998e\r\n", "output": ["3999999993"]}, {"input": "999999998f\r\n", "output": ["3999999992"]}, {"input": "999999999a\r\n", "output": ["3999999988"]}, {"input": "999999999b\r\n", "output": ["3999999989"]}, {"input": "999999999c\r\n", "output": ["3999999990"]}, {"input": "999999999d\r\n", "output": ["3999999987"]}, {"input": "999999999e\r\n", "output": ["3999999986"]}, {"input": "999999999f\r\n", "output": ["3999999985"]}, {"input": "1000000000a\r\n", "output": ["3999999995"]}, {"input": "1000000000b\r\n", "output": ["3999999996"]}, {"input": "1000000000c\r\n", "output": ["3999999997"]}, {"input": "1000000000d\r\n", "output": ["3999999994"]}, {"input": "1000000000e\r\n", "output": ["3999999993"]}, {"input": "1000000000f\r\n", "output": ["3999999992"]}, {"input": "100000b\r\n", "output": ["399996"]}, {"input": "100000f\r\n", "output": ["399992"]}, {"input": "100001d\r\n", "output": ["400003"]}, {"input": "100001e\r\n", "output": ["400002"]}, {"input": "100001f\r\n", "output": ["400001"]}, {"input": "100002a\r\n", "output": ["400011"]}, {"input": "100002b\r\n", "output": ["400012"]}, {"input": "100002d\r\n", "output": ["400010"]}, {"input": "1231273a\r\n", "output": ["4925092"]}, {"input": "82784f\r\n", "output": ["331128"]}, {"input": "88312c\r\n", "output": ["353245"]}, {"input": "891237e\r\n", "output": ["3564946"]}, {"input": "999999999999999997b\r\n", "output": ["3999999999999999989"]}, {"input": "999999999999999997c\r\n", "output": ["3999999999999999990"]}, {"input": "999999999999999997d\r\n", "output": ["3999999999999999987"]}, {"input": "999999999999999997e\r\n", "output": ["3999999999999999986"]}, {"input": "999999999999999997f\r\n", "output": ["3999999999999999985"]}, {"input": "999999999999999998a\r\n", "output": ["3999999999999999995"]}, {"input": "999999999999999998b\r\n", "output": ["3999999999999999996"]}, {"input": "999999999999999998c\r\n", "output": ["3999999999999999997"]}, {"input": "999999999999999998d\r\n", "output": ["3999999999999999994"]}, {"input": "999999999999999998e\r\n", "output": ["3999999999999999993"]}, {"input": "999999999999999998f\r\n", "output": ["3999999999999999992"]}, {"input": "999999999999999999a\r\n", "output": ["3999999999999999988"]}, {"input": "999999999999999999b\r\n", "output": ["3999999999999999989"]}, {"input": "999999999999999999c\r\n", "output": ["3999999999999999990"]}, {"input": "999999999999999999d\r\n", "output": ["3999999999999999987"]}, {"input": "1000000000000000000a\r\n", "output": ["3999999999999999995"]}, {"input": "1000000000000000000e\r\n", "output": ["3999999999999999993"]}, {"input": "1000000000000000000f\r\n", "output": ["3999999999999999992"]}, {"input": "1000000000000000000c\r\n", "output": ["3999999999999999997"]}, {"input": "97a\r\n", "output": ["388"]}, {"input": "6f\r\n", "output": ["24"]}, {"input": "7f\r\n", "output": ["17"]}, {"input": "7e\r\n", "output": ["18"]}, {"input": "999999999999999992c\r\n", "output": ["3999999999999999965"]}, {"input": "7a\r\n", "output": ["20"]}, {"input": "8f\r\n", "output": ["24"]}, {"input": "999999999999999992a\r\n", "output": ["3999999999999999963"]}, {"input": "999999999999999992b\r\n", "output": ["3999999999999999964"]}, {"input": "999999999999999992c\r\n", "output": ["3999999999999999965"]}, {"input": "999999999999999992d\r\n", "output": ["3999999999999999962"]}, {"input": "999999999999999992e\r\n", "output": ["3999999999999999961"]}, {"input": "999999999999999992f\r\n", "output": ["3999999999999999960"]}, {"input": "999999999999999993a\r\n", "output": ["3999999999999999972"]}, {"input": "999999999999999993b\r\n", "output": ["3999999999999999973"]}, {"input": "999999999999999993c\r\n", "output": ["3999999999999999974"]}, {"input": "999999999999999993d\r\n", "output": ["3999999999999999971"]}, {"input": "999999999999999993e\r\n", "output": ["3999999999999999970"]}, {"input": "999999999999999993f\r\n", "output": ["3999999999999999969"]}, {"input": "999999999999999994a\r\n", "output": ["3999999999999999979"]}, {"input": "999999999999999994b\r\n", "output": ["3999999999999999980"]}, {"input": "999999999999999994c\r\n", "output": ["3999999999999999981"]}, {"input": "999999999999999994d\r\n", "output": ["3999999999999999978"]}, {"input": "999999999999999994e\r\n", "output": ["3999999999999999977"]}, {"input": "999999999999999994f\r\n", "output": ["3999999999999999976"]}, {"input": "999999999999999995a\r\n", "output": ["3999999999999999972"]}, {"input": "999999999999999995b\r\n", "output": ["3999999999999999973"]}, {"input": "999999999999999995c\r\n", "output": ["3999999999999999974"]}, {"input": "999999999999999995d\r\n", "output": ["3999999999999999971"]}, {"input": "999999999999999995e\r\n", "output": ["3999999999999999970"]}, {"input": "999999999999999995f\r\n", "output": ["3999999999999999969"]}, {"input": "10a\r\n", "output": ["43"]}, {"input": "11f\r\n", "output": ["33"]}, {"input": "681572647b\r\n", "output": ["2726290581"]}, {"input": "23f\r\n", "output": ["81"]}, {"input": "123a\r\n", "output": ["484"]}, {"input": "999999888888777777a\r\n", "output": ["3999999555555111108"]}]
100
100
100
[{'input': '999999999e\r\n', 'output': ['3999999986']}, {'input': '100001d\r\n', 'output': ['400003']}, {'input': '999999999999999994d\r\n', 'output': ['3999999999999999978']}, {'input': '11f\r\n', 'output': ['33']}, {'input': '999999999999999997a\r\n', 'output': ['3999999999999999988']}]
[{'input': '999999999a\r\n', 'output': ['3999999988']}, {'input': '999999999999999993e\r\n', 'output': ['3999999999999999970']}, {'input': '3c\r\n', 'output': ['6']}, {'input': '8f\r\n', 'output': ['24']}, {'input': '4c\r\n', 'output': ['13']}]
[{'input': '999999999999999993e\r\n', 'output': ['3999999999999999970']}, {'input': '2c\r\n', 'output': ['13']}, {'input': '3d\r\n', 'output': ['3']}, {'input': '999999999999999994a\r\n', 'output': ['3999999999999999979']}, {'input': '999999999999999999a\r\n', 'output': ['3999999999999999988']}]
[{'input': '999999997d\r\n', 'output': ['3999999987']}, {'input': '999999999999999999c\r\n', 'output': ['3999999999999999990']}, {'input': '4b\r\n', 'output': ['12']}, {'input': '1e\r\n', 'output': ['2']}, {'input': '2f\r\n', 'output': ['8']}]
[{'input': '8f\r\n', 'output': ['24']}, {'input': '1a\r\n', 'output': ['4']}, {'input': '999999999b\r\n', 'output': ['3999999989']}, {'input': '999999999999999999d\r\n', 'output': ['3999999999999999987']}, {'input': '999999888888777777a\r\n', 'output': ['3999999555555111108']}]
100
100
100
100
100
89.29
89.29
89.29
92.86
89.29
75
75
80
90
80
205
100
90.004
80
["2 2 1 0 0 1", "2 2 10 11 0 1", "2 4 3 -1 3 7"]
The only line contains integers a, b, x1, y1, x2 and y2 β€” the parameters of the bad squares, the coordinates of the initial and the final squares correspondingly (2 ≀ a, b ≀ 109 and |x1|,|y1|,|x2|,|y2| ≀ 109). It is guaranteed that the initial and the final square aren't bad.
7219d1837c83b5920992aee5a60dc0d9
import java.io.*; import java.util.*; public class Main { void solve(Scanner in, PrintWriter out) { int a = in.nextInt(); int b = in.nextInt(); int x1 = in.nextInt(); int y1 = in.nextInt(); int x2 = in.nextInt(); int y2 = in.nextInt(); int n1 = Math.floorDiv(x1 + y1, 2 * a); int m1 = Math.floorDiv(x1 - y1, 2 * b); int n2 = Math.floorDiv(x2 + y2, 2 * a); int m2 = Math.floorDiv(x2 - y2, 2 * b); int res = Math.max(Math.abs(n2 - n1), Math.abs(m2 - m1)); out.print(res); } void run() { try (Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out)) { solve(in, out); } } public static void main(String[] args) { new Main().run(); } }
["1", "5", "2"]
Java
NoteIn the third sample one of the possible paths in (3;-1)-&gt;(3;0)-&gt;(3;1)-&gt;(3;2)-&gt;(4;2)-&gt;(4;3)-&gt;(4;4)-&gt;(4;5)-&gt;(4;6)-&gt;(4;7)-&gt;(3;7). Squares (3;1) and (4;4) are bad.
Print a single number β€” the minimum number of bad cells that one will have to visit in order to travel from square (x1; y1) to square (x2; y2).
You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one. A square (x; y) is considered bad, if at least one of the two conditions is fulfilled: |x + y| ≑ 0 (modΒ 2a), |x - y| ≑ 0 (modΒ 2b). Your task is to find the minimum number of bad cells one will have to visit on the way from (x1; y1) to (x2; y2).
[{"input": "2 2 1 0 0 1\r\n", "output": ["1"]}, {"input": "2 2 10 11 0 1\r\n", "output": ["5"]}, {"input": "2 4 3 -1 3 7\r\n", "output": ["2"]}, {"input": "2 2 9 10 -10 -11\r\n", "output": ["10"]}, {"input": "3 2 -11 -10 10 11\r\n", "output": ["7"]}, {"input": "3 2 11 -12 -12 11\r\n", "output": ["11"]}, {"input": "3 3 12 11 -12 -11\r\n", "output": ["7"]}, {"input": "2 3 -12 13 13 -12\r\n", "output": ["9"]}, {"input": "3 4 -8 5 6 -3\r\n", "output": ["3"]}, {"input": "2 3 2 -1 -10 -1\r\n", "output": ["3"]}, {"input": "4 4 3 2 10 -1\r\n", "output": ["1"]}, {"input": "3 2 -8 -9 -14 -1\r\n", "output": ["4"]}, {"input": "4 4 0 -3 11 -4\r\n", "output": ["1"]}, {"input": "5 3 6 3 3 12\r\n", "output": ["2"]}, {"input": "3 5 -4 -7 5 0\r\n", "output": ["2"]}, {"input": "3 5 -20 19 21 16\r\n", "output": ["7"]}, {"input": "5 6 23 -10 -20 -17\r\n", "output": ["5"]}, {"input": "3 2 8 -25 0 25\r\n", "output": ["15"]}, {"input": "7 7 23 28 -20 -27\r\n", "output": ["7"]}, {"input": "7 7 -30 -29 32 31\r\n", "output": ["9"]}, {"input": "5 8 35 -36 -34 33\r\n", "output": ["9"]}, {"input": "2 9 37 34 -38 -37\r\n", "output": ["36"]}, {"input": "10 8 -44 41 43 -38\r\n", "output": ["11"]}, {"input": "8 9 8 -23 31 -46\r\n", "output": ["3"]}, {"input": "11 10 9 -40 37 -56\r\n", "output": ["2"]}, {"input": "11 5 -71 44 -18 -21\r\n", "output": ["12"]}, {"input": "6 13 -37 12 3 60\r\n", "output": ["8"]}, {"input": "14 9 44 45 -50 -9\r\n", "output": ["6"]}, {"input": "14 16 1967781 241814 1873488 -829353\r\n", "output": ["41624"]}, {"input": "8 12 -14763515 -11730382 -1343471 -4020758\r\n", "output": ["1320604"]}, {"input": "18 17 -26078453 -12853708 26705417 -4593122\r\n", "output": ["1695679"]}, {"input": "5 18 41299309 8851928 -40049166 -35564497\r\n", "output": ["12576490"]}, {"input": "7 20 10771554 -46099323 39192337 54007626\r\n", "output": ["9180553"]}, {"input": "21 24 31005425 54491054 -24732944 -61529693\r\n", "output": ["4089503"]}, {"input": "24 27 -57405669 -65437426 56079726 56139299\r\n", "output": ["4897128"]}, {"input": "17 22 72042304 -75756269 -70969649 64115614\r\n", "output": ["6429178"]}, {"input": "31 29 73305636 76203147 -85238444 -86730133\r\n", "output": ["5185118"]}, {"input": "34 19 -95432112 102651275 96089919 -106537520\r\n", "output": ["10545022"]}, {"input": "26 34 -107153659 6976200 34136365 -95904822\r\n", "output": ["3590751"]}, {"input": "38 5 -13548447 534376 64966608 -29272371\r\n", "output": ["10832180"]}, {"input": "42 45 13921918 62207801 80023961 -85820354\r\n", "output": ["2379224"]}, {"input": "15 11 -140506021 21571904 -148280972 64286933\r\n", "output": ["2294999"]}, {"input": "53 50 -120558789 -138770904 4229051 102239338\r\n", "output": ["3450925"]}, {"input": "29 54 16062290 129524399 -84381788 132177911\r\n", "output": ["1686044"]}, {"input": "12 63 100712190 36906101 87205943 82885374\r\n", "output": ["1353043"]}, {"input": "66 39 -170201625 -169447104 166170410 181151513\r\n", "output": ["5204323"]}, {"input": "72 75 182000846 -19533501 -166922752 -142084479\r\n", "output": ["3274129"]}, {"input": "55 22 189761193 -192020216 -153412991 188486816\r\n", "output": ["16447301"]}, {"input": "86 84 -65173069 221707138 155388823 -224274366\r\n", "output": ["3967520"]}, {"input": "77 101 -241379320 -196400933 220541904 214436435\r\n", "output": ["5667263"]}, {"input": "70 110 221139524 -236077945 -236283510 205078897\r\n", "output": ["4084454"]}, {"input": "18 116 231579605 226020224 -214399491 -217631436\r\n", "output": ["24711966"]}, {"input": "133 122 -258888058 250173335 258738451 -242389122\r\n", "output": ["4140119"]}, {"input": "127 88 66407013 205897916 133496817 264883406\r\n", "output": ["496360"]}, {"input": "146 157 261464154 113810381 214579048 -202712885\r\n", "output": ["1244549"]}, {"input": "148 163 -62225702 -294347345 -98578232 214557359\r\n", "output": ["1672568"]}, {"input": "7 179 -249546082 207791883 267735483 49881404\r\n", "output": ["25669363"]}, {"input": "125 204 91089644 83192699 -300075653 54365352\r\n", "output": ["1679971"]}, {"input": "216 218 15106122 259371253 296596165 -45704666\r\n", "output": ["1345335"]}, {"input": "207 226 -194940280 130461973 246251465 260969752\r\n", "output": ["1380917"]}, {"input": "267 263 -291849914 -111930623 344642355 250706518\r\n", "output": ["1871029"]}, {"input": "288 40 338359015 273791206 -341021431 56950660\r\n", "output": ["5781749"]}, {"input": "321 30 46954660 -343679003 -37851471 373573736\r\n", "output": ["13367648"]}, {"input": "356 10 97627462 341324361 -132835544 -334849729\r\n", "output": ["22285554"]}, {"input": "380 397 -340890121 -349529418 396652406 353599055\r\n", "output": ["1895619"]}, {"input": "388 113 366011910 -387447751 -403158698 353327235\r\n", "output": ["6681175"]}, {"input": "465 469 376765675 358805048 -390193085 -375070460\r\n", "output": ["1613801"]}, {"input": "504 116 -408147784 387006943 367365902 -415105789\r\n", "output": ["6800114"]}, {"input": "509 565 14560229 -77153392 -340426524 82224911\r\n", "output": ["455190"]}, {"input": "605 297 -251700323 -366763764 -445828791 325081312\r\n", "output": ["1491538"]}, {"input": "689 635 344525358 -321493413 12979458 -353392841\r\n", "output": ["263749"]}, {"input": "664 408 -151206136 -299481355 -385233545 310492602\r\n", "output": ["1034315"]}, {"input": "783 827 -98613981 316213558 -275430891 455234090\r\n", "output": ["190954"]}, {"input": "899 549 -249681750 38465319 105189786 -64009701\r\n", "output": ["416527"]}, {"input": "868 969 245648369 212586392 258298826 -389155385\r\n", "output": ["339339"]}, {"input": "1005 557 -451917708 -32771965 501646713 -357583032\r\n", "output": ["1147554"]}, {"input": "1123 1126 438419485 487688122 -477080698 -185247601\r\n", "output": ["707229"]}, {"input": "1174 901 522498777 -499217148 77740787 519316970\r\n", "output": ["812037"]}, {"input": "1425 1444 516172942 520776621 -319341286 -488388923\r\n", "output": ["647256"]}, {"input": "1576 15 -503228573 -531048974 531411118 557082183\r\n", "output": ["1783049"]}, {"input": "1147 1627 473801348 -494462579 -514604760 486124951\r\n", "output": ["605100"]}, {"input": "1811 1038 526157767 549399960 -479125660 -508887739\r\n", "output": ["569733"]}, {"input": "2033 1908 -480144210 482795119 496763189 -594064604\r\n", "output": ["538199"]}, {"input": "86 1341 -197343715 13981506 -529124963 208152056\r\n", "output": ["800062"]}, {"input": "2455 2436 -335351804 -50788097 286734045 222304974\r\n", "output": ["182317"]}, {"input": "2571 2243 474188235 -306739018 48936920 -83297677\r\n", "output": ["144603"]}, {"input": "1558 2911 -239080974 -489789417 369291826 -67795521\r\n", "output": ["330670"]}, {"input": "2795 3024 418200485 -575735266 101404272 -10209857\r\n", "output": ["145887"]}, {"input": "3341 3479 481143880 -383576301 -584637231 166949262\r\n", "output": ["232295"]}, {"input": "3868 1251 -639544998 21536679 -480078735 -457166436\r\n", "output": ["255064"]}, {"input": "4260 4286 -559966975 430515446 630949753 -403746792\r\n", "output": ["236255"]}, {"input": "4685 84 597126772 174658367 -667031403 657366658\r\n", "output": ["10398014"]}, {"input": "5099 3763 239091250 -689089763 -331708609 690647436\r\n", "output": ["259173"]}, {"input": "5431 5421 218916782 582895951 714645533 -634539842\r\n", "output": ["158012"]}, {"input": "5989 6249 -605686335 -602992500 586207791 624769222\r\n", "output": ["202009"]}, {"input": "4238 464 631928630 -699088687 -665579317 658247096\r\n", "output": ["2860823"]}, {"input": "7368 7243 646513016 723552175 -631585348 -678824351\r\n", "output": ["181900"]}, {"input": "6929 8303 -718092932 630511765 717136401 -678221530\r\n", "output": ["165239"]}, {"input": "551 8823 -644698584 720097649 -746775493 -719362914\r\n", "output": ["1398855"]}, {"input": "2036 9146 46737913 478540414 -603176411 -34978692\r\n", "output": ["285715"]}, {"input": "10000 10002 96487781 -692179874 182133670 357089051\r\n", "output": ["56746"]}, {"input": "4209 7951 232804958 -326325341 -138865076 516216059\r\n", "output": ["76356"]}, {"input": "10005 10008 -234169778 -592210597 -126329886 -812018105\r\n", "output": ["16370"]}, {"input": "8387 10012 -275798799 489020846 127010938 154401541\r\n", "output": ["36828"]}, {"input": "10058 9799 -25054219 -611037250 172201377 486371190\r\n", "output": ["64360"]}, {"input": "10088 6166 -735339950 -111273129 787180186 -439981865\r\n", "output": ["150116"]}, {"input": "10311 10242 764996339 626041956 -740573838 -97126465\r\n", "output": ["108076"]}, {"input": "10067 8186 -736794579 -820525762 -407728461 839527984\r\n", "output": ["98794"]}, {"input": "10721 11225 -767745746 709747051 443545879 -717667636\r\n", "output": ["117537"]}, {"input": "13225 984 -760662977 -854994174 786299019 825465374\r\n", "output": ["122020"]}, {"input": "14699 14675 792934253 -867739654 -737526630 840318203\r\n", "output": ["110341"]}, {"input": "20967 19929 821529452 892087465 -867106029 -836044344\r\n", "output": ["81480"]}, {"input": "43649 46022 -793221994 750708255 871188328 -901390875\r\n", "output": ["36031"]}, {"input": "25706 3236 867426580 143799455 254112907 -287546356\r\n", "output": ["28116"]}, {"input": "222075 201776 -663198106 -381459887 -29690718 -65372649\r\n", "output": ["2138"]}, {"input": "526654 264582 -19827600 -757880279 -903623062 -934193021\r\n", "output": ["1337"]}, {"input": "34483 1001201 -483230679 -24466088 827887504 293189155\r\n", "output": ["23617"]}, {"input": "840853 1638188 -425749679 502946202 -953467908 557484181\r\n", "output": ["281"]}, {"input": "4237214 4640696 -612169083 -326390834 887479529 304518522\r\n", "output": ["251"]}, {"input": "2959011 3049607 253816894 -342369389 610124947 440828496\r\n", "output": ["192"]}, {"input": "31288011 27242802 -934902606 343371553 926119543 -195542560\r\n", "output": ["44"]}, {"input": "6152051 53675778 964821583 85960172 -939564894 755134693\r\n", "output": ["100"]}, {"input": "101304499 148554333 -590787464 -890180401 -117457421 997140710\r\n", "output": ["12"]}, {"input": "134699726 208640218 514309071 801051734 276512437 -803859310\r\n", "output": ["6"]}, {"input": "472555248 417950652 -897989583 -805741694 915661619 800897620\r\n", "output": ["3"]}, {"input": "299386785 573704302 956852511 -973861202 -816995136 989470727\r\n", "output": ["3"]}, {"input": "1000000000 1000000000 871940474 991768763 -914352281 -886310260\r\n", "output": ["1"]}, {"input": "781751245 1000000000 -848188940 813653557 978830633 -825182414\r\n", "output": ["1"]}, {"input": "999999999 1000000000 1000000000 -999999999 -1000000000 999999999\r\n", "output": ["1"]}, {"input": "999999 100000 12345 54321 6789 9876\r\n", "output": ["0"]}]
100
100
100
[{'input': '55 22 189761193 -192020216 -153412991 188486816\r\n', 'output': ['16447301']}, {'input': '53 50 -120558789 -138770904 4229051 102239338\r\n', 'output': ['3450925']}, {'input': '664 408 -151206136 -299481355 -385233545 310492602\r\n', 'output': ['1034315']}, {'input': '18 116 231579605 226020224 -214399491 -217631436\r\n', 'output': ['24711966']}, {'input': '70 110 221139524 -236077945 -236283510 205078897\r\n', 'output': ['4084454']}]
[{'input': '42 45 13921918 62207801 80023961 -85820354\r\n', 'output': ['2379224']}, {'input': '2571 2243 474188235 -306739018 48936920 -83297677\r\n', 'output': ['144603']}, {'input': '2033 1908 -480144210 482795119 496763189 -594064604\r\n', 'output': ['538199']}, {'input': '3 2 -8 -9 -14 -1\r\n', 'output': ['4']}, {'input': '868 969 245648369 212586392 258298826 -389155385\r\n', 'output': ['339339']}]
[{'input': '4 4 0 -3 11 -4\r\n', 'output': ['1']}, {'input': '20967 19929 821529452 892087465 -867106029 -836044344\r\n', 'output': ['81480']}, {'input': '1425 1444 516172942 520776621 -319341286 -488388923\r\n', 'output': ['647256']}, {'input': '72 75 182000846 -19533501 -166922752 -142084479\r\n', 'output': ['3274129']}, {'input': '34483 1001201 -483230679 -24466088 827887504 293189155\r\n', 'output': ['23617']}]
[{'input': '4 4 3 2 10 -1\r\n', 'output': ['1']}, {'input': '125 204 91089644 83192699 -300075653 54365352\r\n', 'output': ['1679971']}, {'input': '3 4 -8 5 6 -3\r\n', 'output': ['3']}, {'input': '101304499 148554333 -590787464 -890180401 -117457421 997140710\r\n', 'output': ['12']}, {'input': '3 5 -20 19 21 16\r\n', 'output': ['7']}]
[{'input': '783 827 -98613981 316213558 -275430891 455234090\r\n', 'output': ['190954']}, {'input': '10005 10008 -234169778 -592210597 -126329886 -812018105\r\n', 'output': ['16370']}, {'input': '1425 1444 516172942 520776621 -319341286 -488388923\r\n', 'output': ['647256']}, {'input': '3 2 8 -25 0 25\r\n', 'output': ['15']}, {'input': '1000000000 1000000000 871940474 991768763 -914352281 -886310260\r\n', 'output': ['1']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
206
100
100
100
["12"]
The only line of the input contains one integer n (1 ≀ n ≀ 1018) β€” the prediction on the number of people who will buy the game.
e392be5411ffccc1df50e65ec1f5c589
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); long res = (n / 2) + (n / 3) - (n / 6) + (n / 42) +(n / 5) + (n / 7) + (n/ 30) + (n / 70) + (n / 105) -(n / 10) - (n / 15) - (n / 14) - (n / 21) - (n / 35) - (n / 210); System.out.println(n - res); } }
["2"]
Java
null
Output one integer showing how many numbers from 1 to n are not divisible by any number from 2 to 10.
IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is not divisible by any number from 2 to 10 every developer of this game gets a small bonus.A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
[{"input": "12\r\n", "output": ["2"]}, {"input": "2519\r\n", "output": ["576"]}, {"input": "2521\r\n", "output": ["577"]}, {"input": "1\r\n", "output": ["1"]}, {"input": "314159265\r\n", "output": ["71807832"]}, {"input": "718281828459045235\r\n", "output": ["164178703647781768"]}, {"input": "1000000000000000000\r\n", "output": ["228571428571428571"]}, {"input": "987654321234567890\r\n", "output": ["225749559139329804"]}, {"input": "3628800\r\n", "output": ["829440"]}, {"input": "504000000000000000\r\n", "output": ["115200000000000000"]}]
100
100
100
[{'input': '1000000000000000000\r\n', 'output': ['228571428571428571']}, {'input': '12\r\n', 'output': ['2']}, {'input': '3628800\r\n', 'output': ['829440']}, {'input': '2519\r\n', 'output': ['576']}, {'input': '718281828459045235\r\n', 'output': ['164178703647781768']}]
[{'input': '314159265\r\n', 'output': ['71807832']}, {'input': '3628800\r\n', 'output': ['829440']}, {'input': '718281828459045235\r\n', 'output': ['164178703647781768']}, {'input': '1\r\n', 'output': ['1']}, {'input': '987654321234567890\r\n', 'output': ['225749559139329804']}]
[{'input': '2521\r\n', 'output': ['577']}, {'input': '12\r\n', 'output': ['2']}, {'input': '3628800\r\n', 'output': ['829440']}, {'input': '504000000000000000\r\n', 'output': ['115200000000000000']}, {'input': '987654321234567890\r\n', 'output': ['225749559139329804']}]
[{'input': '3628800\r\n', 'output': ['829440']}, {'input': '504000000000000000\r\n', 'output': ['115200000000000000']}, {'input': '314159265\r\n', 'output': ['71807832']}, {'input': '2521\r\n', 'output': ['577']}, {'input': '12\r\n', 'output': ['2']}]
[{'input': '12\r\n', 'output': ['2']}, {'input': '2521\r\n', 'output': ['577']}, {'input': '504000000000000000\r\n', 'output': ['115200000000000000']}, {'input': '2519\r\n', 'output': ['576']}, {'input': '987654321234567890\r\n', 'output': ['225749559139329804']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
207
100
100
100
["1 1 2", "3 4 5", "4 1 1"]
The single line of the input contains three space-separated integers a, b and c (1 ≀ a, b, c ≀ 106) β€” the valence numbers of the given atoms.
b3b986fddc3770fed64b878fa42ab1bc
import java.util.Scanner; public class SimpleMoecules { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); int a = input.nextInt(); int b = input.nextInt(); int c = input.nextInt(); if((c+b-a)%2==0){ int z = (c+b-a)/2; if(z<0){ System.out.println("Impossible"); return; } int y = c-z; if(y<0){ System.out.println("Impossible"); return; } int x = a-y; if(x<0){ System.out.println("Impossible"); return; } else System.out.println(x+" "+z+" "+y); } else System.out.println("Impossible"); } }
["0 1 1", "1 3 2", "Impossible"]
Java
NoteThe first sample corresponds to the first figure. There are no bonds between atoms 1 and 2 in this case.The second sample corresponds to the second figure. There is one or more bonds between each pair of atoms.The third sample corresponds to the third figure. There is no solution, because an atom cannot form bonds with itself.The configuration in the fourth figure is impossible as each atom must have at least one atomic bond.
If such a molecule can be built, print three space-separated integers β€” the number of bonds between the 1-st and the 2-nd, the 2-nd and the 3-rd, the 3-rd and the 1-st atoms, correspondingly. If there are multiple solutions, output any of them. If there is no solution, print "Impossible" (without the quotes).
Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule.A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number β€” the number of bonds the atom must form with other atoms. An atom can form one or multiple bonds with any other atom, but it cannot form a bond with itself. The number of bonds of an atom in the molecule must be equal to its valence number. Mike knows valence numbers of the three atoms. Find a molecule that can be built from these atoms according to the stated rules, or determine that it is impossible.
[{"input": "1 1 2\r\n", "output": ["0 1 1"]}, {"input": "3 4 5\r\n", "output": ["1 3 2"]}, {"input": "4 1 1\r\n", "output": ["Impossible"]}, {"input": "1 1 1\r\n", "output": ["Impossible"]}, {"input": "1000000 1000000 1000000\r\n", "output": ["500000 500000 500000"]}, {"input": "3 11 8\r\n", "output": ["3 8 0"]}, {"input": "8 5 12\r\n", "output": ["Impossible"]}, {"input": "1000000 500000 1\r\n", "output": ["Impossible"]}, {"input": "1000000 500000 2\r\n", "output": ["Impossible"]}, {"input": "2 2 2\r\n", "output": ["1 1 1"]}, {"input": "3 3 3\r\n", "output": ["Impossible"]}, {"input": "4 4 4\r\n", "output": ["2 2 2"]}, {"input": "2 4 2\r\n", "output": ["2 2 0"]}, {"input": "10 5 14\r\n", "output": ["Impossible"]}, {"input": "10 5 15\r\n", "output": ["0 5 10"]}, {"input": "10 4 16\r\n", "output": ["Impossible"]}, {"input": "3 3 6\r\n", "output": ["0 3 3"]}, {"input": "9 95 90\r\n", "output": ["7 88 2"]}, {"input": "3 5 8\r\n", "output": ["0 5 3"]}, {"input": "5 8 13\r\n", "output": ["0 8 5"]}, {"input": "6 1 5\r\n", "output": ["1 0 5"]}, {"input": "59 54 56\r\n", "output": ["Impossible"]}, {"input": "246 137 940\r\n", "output": ["Impossible"]}, {"input": "7357 3578 9123\r\n", "output": ["906 2672 6451"]}, {"input": "93952 49553 83405\r\n", "output": ["30050 19503 63902"]}, {"input": "688348 726472 442198\r\n", "output": ["486311 240161 202037"]}, {"input": "602752 645534 784262\r\n", "output": ["232012 413522 370740"]}, {"input": "741349 48244 642678\r\n", "output": ["Impossible"]}, {"input": "655754 418251 468390\r\n", "output": ["Impossible"]}, {"input": "310703 820961 326806\r\n", "output": ["Impossible"]}, {"input": "1 1 3\r\n", "output": ["Impossible"]}, {"input": "5 1 4\r\n", "output": ["1 0 4"]}]
100
100
100
[{'input': '3 11 8\r\n', 'output': ['3 8 0']}, {'input': '8 5 12\r\n', 'output': ['Impossible']}, {'input': '10 5 15\r\n', 'output': ['0 5 10']}, {'input': '9 95 90\r\n', 'output': ['7 88 2']}, {'input': '2 2 2\r\n', 'output': ['1 1 1']}]
[{'input': '59 54 56\r\n', 'output': ['Impossible']}, {'input': '10 4 16\r\n', 'output': ['Impossible']}, {'input': '9 95 90\r\n', 'output': ['7 88 2']}, {'input': '8 5 12\r\n', 'output': ['Impossible']}, {'input': '1 1 3\r\n', 'output': ['Impossible']}]
[{'input': '7357 3578 9123\r\n', 'output': ['906 2672 6451']}, {'input': '3 5 8\r\n', 'output': ['0 5 3']}, {'input': '5 8 13\r\n', 'output': ['0 8 5']}, {'input': '1000000 500000 2\r\n', 'output': ['Impossible']}, {'input': '741349 48244 642678\r\n', 'output': ['Impossible']}]
[{'input': '2 4 2\r\n', 'output': ['2 2 0']}, {'input': '1000000 1000000 1000000\r\n', 'output': ['500000 500000 500000']}, {'input': '1 1 3\r\n', 'output': ['Impossible']}, {'input': '4 4 4\r\n', 'output': ['2 2 2']}, {'input': '3 3 6\r\n', 'output': ['0 3 3']}]
[{'input': '5 8 13\r\n', 'output': ['0 8 5']}, {'input': '8 5 12\r\n', 'output': ['Impossible']}, {'input': '688348 726472 442198\r\n', 'output': ['486311 240161 202037']}, {'input': '246 137 940\r\n', 'output': ['Impossible']}, {'input': '1 1 1\r\n', 'output': ['Impossible']}]
100
100
100
100
100
71.43
80.95
80.95
71.43
71.43
62.5
75
75
62.5
62.5
208
100
75.238
67.5
["4"]
The only line contains an integer n (2 ≀ n ≀ 1012), the number of vertices in the graph.
a98f0d924ea52cafe0048f213f075891
// http://codeforces.com/contest/959/problem/E import java.io.*; import java.util.InputMismatchException; public class CF959E { public static void main(String[] args) throws IOException { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); final long N = in.readLong() - 1; long res = 0; long i = 1; for (i = 1; i <= N; i = i << 1) { res = res + ((N - i) / (i << 1) + 1) * i; } out.print(res); closeStreams(out, in); } private static void closeStreams(OutputWriter out, InputReader in) throws IOException { out.flush(); out.close(); in.close(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double readDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, readInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, readInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public long readLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public 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 boolean isEndOfLine(int c) { if (filter != null) { return filter.isEndOfLine(c); } return c == '\n' || c == '\r' || c == -1; } public String next() { return readString(); } public void close() throws IOException { this.stream.close(); } public interface SpaceCharFilter { boolean isSpaceChar(int ch); boolean isEndOfLine(int ch); } } static class IOUtils { public static int[] readIntArray(InputReader in, int elementCount) { return readIntArray(in, elementCount, 0); } public static int[] readIntArray(InputReader in, int elementCount, int startOffset) { int[] array = new int[elementCount + startOffset]; for (int i = 0; i < elementCount; i++) array[i + startOffset] = in.readInt(); return array; } public static long[] readLongArray(InputReader in, int elementCount) { return readLongArray(in, elementCount, 0); } public static long[] readLongArray(InputReader in, int elementCount, int startOffset) { long[] array = new long[elementCount + startOffset]; for (int i = 0; i < elementCount; i++) array[i + startOffset] = in.readLong(); return array; } } 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(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } }
["4"]
Java
NoteIn the first sample: The weight of the minimum spanning tree is 1+2+1=4.
The only line contains an integer x, the weight of the graph's minimum spanning tree.
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≀ u &lt; v &lt; n, vertex u and vertex v are connected with an undirected edge that has weight (where is the bitwise-xor operation). Can you find the weight of the minimum spanning tree of that graph?You can read about complete graphs in https://en.wikipedia.org/wiki/Complete_graphYou can read about the minimum spanning tree in https://en.wikipedia.org/wiki/Minimum_spanning_treeThe weight of the minimum spanning tree is the sum of the weights on the edges included in it.
[{"input": "4\r\n", "output": ["4"]}, {"input": "10\r\n", "output": ["21"]}, {"input": "2\r\n", "output": ["1"]}, {"input": "1000000000000\r\n", "output": ["20140978692096"]}, {"input": "999999999999\r\n", "output": ["20140978692095"]}, {"input": "23131234\r\n", "output": ["293058929"]}, {"input": "100000\r\n", "output": ["877968"]}, {"input": "1024\r\n", "output": ["5120"]}, {"input": "536870912\r\n", "output": ["7784628224"]}, {"input": "536870911\r\n", "output": ["7784628223"]}, {"input": "536870913\r\n", "output": ["8321499136"]}, {"input": "123456789\r\n", "output": ["1680249144"]}, {"input": "200\r\n", "output": ["844"]}, {"input": "3\r\n", "output": ["3"]}, {"input": "5\r\n", "output": ["8"]}, {"input": "6\r\n", "output": ["9"]}, {"input": "7\r\n", "output": ["11"]}, {"input": "1000\r\n", "output": ["5052"]}, {"input": "12000\r\n", "output": ["84624"]}, {"input": "65536\r\n", "output": ["524288"]}, {"input": "1048576\r\n", "output": ["10485760"]}, {"input": "8\r\n", "output": ["12"]}, {"input": "549755813888\r\n", "output": ["10720238370816"]}, {"input": "549755813887\r\n", "output": ["10720238370815"]}, {"input": "549755813889\r\n", "output": ["11269994184704"]}]
100
100
100
[{'input': '1048576\r\n', 'output': ['10485760']}, {'input': '999999999999\r\n', 'output': ['20140978692095']}, {'input': '23131234\r\n', 'output': ['293058929']}, {'input': '200\r\n', 'output': ['844']}, {'input': '7\r\n', 'output': ['11']}]
[{'input': '10\r\n', 'output': ['21']}, {'input': '123456789\r\n', 'output': ['1680249144']}, {'input': '536870912\r\n', 'output': ['7784628224']}, {'input': '6\r\n', 'output': ['9']}, {'input': '1048576\r\n', 'output': ['10485760']}]
[{'input': '200\r\n', 'output': ['844']}, {'input': '4\r\n', 'output': ['4']}, {'input': '6\r\n', 'output': ['9']}, {'input': '7\r\n', 'output': ['11']}, {'input': '1048576\r\n', 'output': ['10485760']}]
[{'input': '10\r\n', 'output': ['21']}, {'input': '1000000000000\r\n', 'output': ['20140978692096']}, {'input': '2\r\n', 'output': ['1']}, {'input': '999999999999\r\n', 'output': ['20140978692095']}, {'input': '549755813889\r\n', 'output': ['11269994184704']}]
[{'input': '549755813888\r\n', 'output': ['10720238370816']}, {'input': '4\r\n', 'output': ['4']}, {'input': '536870912\r\n', 'output': ['7784628224']}, {'input': '7\r\n', 'output': ['11']}, {'input': '3\r\n', 'output': ['3']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
209
100
100
100
["5", "3"]
The first and only line of the input contains a single integer n (3 ≀ n ≀ 54321) - the number of vertices of the regular polygon drawn by Ari.
efa8e7901a3084d34cfb1a6b18067f2b
import java.util.Scanner; public class cls_div2_328_B { public static void main(String[] args) { Scanner scan = new Scanner(System.in); long n = scan.nextInt(); scan.close(); long result = (n - 2) + ((n - 3) * (n - 2)); System.out.println(result); } }
["9", "1"]
Java
NoteOne of the possible solutions for the first sample is shown on the picture above.
Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after.
Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.Ari draws a regular convex polygon on the floor and numbers it's vertices 1, 2, ..., n in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other vertex. The ray stops when it reaches a vertex or intersects with another ray drawn before. Ari repeats this process for vertex 2, 3, ..., n (in this particular order). And then she puts a walnut in each region inside the polygon. Ada the squirrel wants to collect all the walnuts, but she is not allowed to step on the lines drawn by Ari. That means Ada have to perform a small jump if she wants to go from one region to another. Ada can jump from one region P to another region Q if and only if P and Q share a side or a corner.Assuming that Ada starts from outside of the picture, what is the minimum number of jumps she has to perform in order to collect all the walnuts?
[{"input": "5\r\n", "output": ["9"]}, {"input": "3\r\n", "output": ["1"]}, {"input": "54321\r\n", "output": ["2950553761"]}, {"input": "4\r\n", "output": ["4"]}, {"input": "6\r\n", "output": ["16"]}, {"input": "7\r\n", "output": ["25"]}, {"input": "8\r\n", "output": ["36"]}, {"input": "9\r\n", "output": ["49"]}, {"input": "10\r\n", "output": ["64"]}, {"input": "54320\r\n", "output": ["2950445124"]}, {"input": "54319\r\n", "output": ["2950336489"]}, {"input": "54318\r\n", "output": ["2950227856"]}, {"input": "54317\r\n", "output": ["2950119225"]}, {"input": "54316\r\n", "output": ["2950010596"]}, {"input": "54315\r\n", "output": ["2949901969"]}, {"input": "54314\r\n", "output": ["2949793344"]}, {"input": "8153\r\n", "output": ["66438801"]}, {"input": "51689\r\n", "output": ["2671545969"]}, {"input": "16659\r\n", "output": ["277455649"]}, {"input": "47389\r\n", "output": ["2245527769"]}, {"input": "314\r\n", "output": ["97344"]}, {"input": "23481\r\n", "output": ["551263441"]}, {"input": "20380\r\n", "output": ["415262884"]}, {"input": "1994\r\n", "output": ["3968064"]}]
100
100
100
[{'input': '4\r\n', 'output': ['4']}, {'input': '54314\r\n', 'output': ['2949793344']}, {'input': '8\r\n', 'output': ['36']}, {'input': '54320\r\n', 'output': ['2950445124']}, {'input': '8153\r\n', 'output': ['66438801']}]
[{'input': '20380\r\n', 'output': ['415262884']}, {'input': '16659\r\n', 'output': ['277455649']}, {'input': '23481\r\n', 'output': ['551263441']}, {'input': '54320\r\n', 'output': ['2950445124']}, {'input': '5\r\n', 'output': ['9']}]
[{'input': '54318\r\n', 'output': ['2950227856']}, {'input': '7\r\n', 'output': ['25']}, {'input': '10\r\n', 'output': ['64']}, {'input': '4\r\n', 'output': ['4']}, {'input': '54316\r\n', 'output': ['2950010596']}]
[{'input': '10\r\n', 'output': ['64']}, {'input': '4\r\n', 'output': ['4']}, {'input': '7\r\n', 'output': ['25']}, {'input': '20380\r\n', 'output': ['415262884']}, {'input': '3\r\n', 'output': ['1']}]
[{'input': '54317\r\n', 'output': ['2950119225']}, {'input': '5\r\n', 'output': ['9']}, {'input': '54315\r\n', 'output': ['2949901969']}, {'input': '6\r\n', 'output': ['16']}, {'input': '314\r\n', 'output': ['97344']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
210
100
100
100
["7\nABACABA", "5\nZZZAA"]
The first line of the input contains integer number $$$n$$$ ($$$2 \le n \le 100$$$) β€” the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ capital Latin letters.
e78005d4be93dbaa518f3b40cca84ab1
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); char c[]=s.toCharArray(); char aa='1',bb='1'; int max=-1; for(int i=0;i<c.length-1;i++){ char a=c[i],b=c[i+1]; int con=1; for(int j=i+1;j<c.length-1;j++){ if(c[j]==c[i]&&c[j+1]==c[i+1]){ con++; } } if(con>max){ max=con; aa=a;bb=b; }else if(con==max&&(a<aa||(a==aa&&b<bb))){ aa=a;bb=b; } } System.out.println(aa+""+bb); } }
["AB", "ZZ"]
Java
NoteIn the first example "BA" is also valid answer.In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times.
Print the only line containing exactly two capital Latin letters β€” any two-gram contained in the given string $$$s$$$ as a substring (i.e. two consecutive characters of the string) maximal number of times.
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" β€” three distinct two-grams.You are given a string $$$s$$$ consisting of $$$n$$$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string $$$s$$$ = "BBAABBBA" the answer is two-gram "BB", which contained in $$$s$$$ three times. In other words, find any most frequent two-gram.Note that occurrences of the two-gram can overlap with each other.
[{"input": "7\r\nABACABA\r\n", "output": ["BA", "AB"]}, {"input": "5\r\nZZZAA\r\n", "output": ["ZZ"]}, {"input": "26\r\nQWERTYUIOPASDFGHJKLZXCVBNM\r\n", "output": ["KL", "QW", "WE", "AS"]}, {"input": "2\r\nQA\r\n", "output": ["QA"]}, {"input": "2\r\nWW\r\n", "output": ["WW"]}, {"input": "11\r\nGGRRAATTZZZ\r\n", "output": ["ZZ"]}, {"input": "50\r\nNYQAHBYYOXLTRYQDMVENEMAQNBAKGLGQOLXNAIFNQTOCLNNQIA\r\n", "output": ["NQ", "YQ"]}, {"input": "100\r\nURXCAIZFIBNJTPCZHBQIBCILLPXZCFGMKKZMNPLCYGAVJVIBMCZEBSJWPSCPQDYCTTKPOKIJRSKIZPDGCHVOUTMPNECYORSFZFNC\r\n", "output": ["IB"]}, {"input": "100\r\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\n", "output": ["AA"]}, {"input": "10\r\nSQSQSQSQTG\r\n", "output": ["SQ"]}, {"input": "5\r\nAZAZA\r\n", "output": ["ZA", "AZ"]}, {"input": "15\r\nMIRZOYANOVECLOX\r\n", "output": ["AN", "IR", "MI", "NO"]}, {"input": "9\r\nEGORLETOV\r\n", "output": ["GO", "EG", "TO"]}, {"input": "8\r\nPUTINVOR\r\n", "output": ["PU", "IN", "UT", "NV"]}, {"input": "7\r\nKADUROV\r\n", "output": ["KA", "AD"]}, {"input": "6\r\nAZAZAZ\r\n", "output": ["AZ"]}, {"input": "3\r\nLOL\r\n", "output": ["OL", "LO"]}, {"input": "3\r\nKEK\r\n", "output": ["EK", "KE"]}, {"input": "5\r\nFUFEL\r\n", "output": ["UF", "EL", "FU"]}, {"input": "9\r\nMIKEPIDOR\r\n", "output": ["EP", "MI", "DO", "IK"]}, {"input": "9\r\nAAAAAAAAA\r\n", "output": ["AA"]}, {"input": "23\r\nAABBBAAACCCCCAAADDDDDDD\r\n", "output": ["DD"]}]
100
100
100
[{'input': '100\r\nURXCAIZFIBNJTPCZHBQIBCILLPXZCFGMKKZMNPLCYGAVJVIBMCZEBSJWPSCPQDYCTTKPOKIJRSKIZPDGCHVOUTMPNECYORSFZFNC\r\n', 'output': ['IB']}, {'input': '9\r\nAAAAAAAAA\r\n', 'output': ['AA']}, {'input': '23\r\nAABBBAAACCCCCAAADDDDDDD\r\n', 'output': ['DD']}, {'input': '7\r\nABACABA\r\n', 'output': ['BA', 'AB']}, {'input': '9\r\nEGORLETOV\r\n', 'output': ['GO', 'EG', 'TO']}]
[{'input': '3\r\nLOL\r\n', 'output': ['OL', 'LO']}, {'input': '9\r\nMIKEPIDOR\r\n', 'output': ['EP', 'MI', 'DO', 'IK']}, {'input': '2\r\nWW\r\n', 'output': ['WW']}, {'input': '11\r\nGGRRAATTZZZ\r\n', 'output': ['ZZ']}, {'input': '100\r\nURXCAIZFIBNJTPCZHBQIBCILLPXZCFGMKKZMNPLCYGAVJVIBMCZEBSJWPSCPQDYCTTKPOKIJRSKIZPDGCHVOUTMPNECYORSFZFNC\r\n', 'output': ['IB']}]
[{'input': '7\r\nKADUROV\r\n', 'output': ['KA', 'AD']}, {'input': '9\r\nEGORLETOV\r\n', 'output': ['GO', 'EG', 'TO']}, {'input': '50\r\nNYQAHBYYOXLTRYQDMVENEMAQNBAKGLGQOLXNAIFNQTOCLNNQIA\r\n', 'output': ['NQ', 'YQ']}, {'input': '5\r\nAZAZA\r\n', 'output': ['ZA', 'AZ']}, {'input': '15\r\nMIRZOYANOVECLOX\r\n', 'output': ['AN', 'IR', 'MI', 'NO']}]
[{'input': '11\r\nGGRRAATTZZZ\r\n', 'output': ['ZZ']}, {'input': '9\r\nAAAAAAAAA\r\n', 'output': ['AA']}, {'input': '2\r\nQA\r\n', 'output': ['QA']}, {'input': '9\r\nMIKEPIDOR\r\n', 'output': ['EP', 'MI', 'DO', 'IK']}, {'input': '5\r\nFUFEL\r\n', 'output': ['UF', 'EL', 'FU']}]
[{'input': '2\r\nWW\r\n', 'output': ['WW']}, {'input': '50\r\nNYQAHBYYOXLTRYQDMVENEMAQNBAKGLGQOLXNAIFNQTOCLNNQIA\r\n', 'output': ['NQ', 'YQ']}, {'input': '10\r\nSQSQSQSQTG\r\n', 'output': ['SQ']}, {'input': '5\r\nAZAZA\r\n', 'output': ['ZA', 'AZ']}, {'input': '5\r\nFUFEL\r\n', 'output': ['UF', 'EL', 'FU']}]
100
100
100
100
100
100
100
100
100
100
94.44
94.44
94.44
100
94.44
211
100
100
95.552
["10 2\n3 5\n11 13", "10 3\n3 5\n9 10\n11 13", "20 1\n3 19"]
The first line contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 100)Β β€” the number of seconds the cutlet should be cooked on each side and number of periods of time in which Arkady can flip it. The next k lines contain descriptions of these intervals. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 2Β·n), meaning that Arkady can flip the cutlet in any moment starting from li seconds after the beginning of cooking and finishing at ri seconds after beginning of cooking. In particular, if li = ri then Arkady can flip the cutlet only in the moment li = ri. It's guaranteed that li &gt; ri - 1 for all 2 ≀ i ≀ k.
2e0d1b1f1a7b8df2d2598c3cb2c869d5
import java.io.*; import java.util.*; public class CF939_D2_F { public static void main(String[] args)throws Throwable { MyScanner sc=new MyScanner(); PrintWriter pw=new PrintWriter(System.out); int n=sc.nextInt()*2; int k=sc.nextInt(); int [] l=new int [k+1]; int [] r=new int [k+1]; SparseTable [][] seg=new SparseTable [2][2]; for(int i=0;i<k;i++){ l[i]=sc.nextInt(); r[i]=sc.nextInt(); } l[k]=n; for(int j=0;j<2;j++){ int [] a=new int [n/2+2]; Arrays.fill(a, inf); a[n/2]=0; seg[1][j]=new SparseTable(a); } int p=0; for(int i=k-1;i>=0;i--){ for(int j=0;j<2;j++){ int [] a=new int [n/2+2]; Arrays.fill(a, inf); for(int c=0;c<=l[i] && c<a.length;c++){ int best=seg[1-p][j].query(c+l[i+1]-l[i], c+l[i+1]-l[i]); best=Math.min(best, 1+seg[1-p][1-j].query(l[i+1]-(c+r[i]-l[i]), l[i+1]-(c))); if(r[i]>l[i]) best=Math.min(best, 2+seg[1-p][j].query(c+l[i+1]-r[i], c+l[i+1]-l[i]-1)); a[c]=best; } seg[p][j]=new SparseTable(a); } p^=1; } p^=1; int ans=Math.min(seg[p][0].query(l[0], l[0]), seg[p][1].query(l[0], l[0])); if(ans>2*k) pw.println("Hungry"); else{ pw.println("Full"); pw.println(ans); } pw.flush(); pw.close(); } static int inf=(int)1e7; static class SparseTable { int [] a; int [][] st; //st[i][j] --> minimum of sub array starting at index i and of length 2^j SparseTable(int [] a){ int n=a.length; this.a=a; int k=(int)Math.floor(Math.log(n)/Math.log(2))+1; st=new int [n][k]; for(int i=0;i<n;i++) st[i][0]=i; //(1<<j)===(2^j) for(int j=1;(1<<j)<=n;j++) for(int i=0;i+(1<<j)-1<n;i++) if(a[st[i][j-1]] < a[st[i+(1<<(j-1))][j-1]]) st[i][j]=st[i][j-1]; // else st[i][j]=st[i+(1<<(j-1))][j-1]; } int query(int i,int j){ if(i>=a.length) return inf; j=Math.min(j, a.length-1); int k=(int)Math.floor(Math.log(j-i+1)/Math.log(2)); return Math.min(a[st[i][k]], a[st[j-(1<<k)+1][k]]); } } static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() {while (st == null || !st.hasMoreElements()) { try {st = new StringTokenizer(br.readLine());} catch (IOException e) {e.printStackTrace();}} return st.nextToken();} int nextInt() {return Integer.parseInt(next());} long nextLong() {return Long.parseLong(next());} double nextDouble() {return Double.parseDouble(next());} String nextLine(){String str = ""; try {str = br.readLine();} catch (IOException e) {e.printStackTrace();} return str;} } }
["Full\n2", "Full\n1", "Hungry"]
Java
NoteIn the first example Arkady should flip the cutlet in time moment 3 seconds after he starts cooking and in time moment 13 seconds after he starts cooking.In the second example, Arkady can flip the cutlet at 10 seconds after he starts cooking.
Output "Hungry" if Arkady won't be able to fry the cutlet for exactly n seconds on one side and exactly n seconds on the other side. Otherwise, output "Full" in the first line, and the minimum number of times he should flip the cutlet in the second line.
Arkady wants to have a dinner. He has just returned from a shop where he has bought a semifinished cutlet. He only needs to fry it. The cutlet should be fried for 2n seconds, in particular, it should be fried for n seconds on one side and n seconds on the other side. Arkady has already got a frying pan and turn on fire, but understood that maybe he won't be able to flip the cutlet exactly after n seconds after the beginning of cooking.Arkady is too busy with sorting sticker packs in his favorite messenger and can flip the cutlet only in some periods of time. Namely, there are k periods of time in which he can do it, the i-th of them is an interval of time from li seconds after he starts cooking till ri seconds, inclusive. Arkady decided that it's not required to flip the cutlet exactly in the middle of cooking, instead, he will flip it several times in such a way that the cutlet will be fried exactly n seconds on one side and n seconds on the other side in total.Help Arkady and find out if it's possible for him to cook the cutlet, if he is able to flip the cutlet only in given periods of time; and if yes, find the minimum number of flips he needs to cook the cutlet.
[{"input": "10 2\r\n3 5\r\n11 13\r\n", "output": ["Full\r\n2"]}, {"input": "10 3\r\n3 5\r\n9 10\r\n11 13\r\n", "output": ["Full\r\n1"]}, {"input": "20 1\r\n3 19\r\n", "output": ["Hungry"]}, {"input": "10 1\r\n0 20\r\n", "output": ["Full\r\n1"]}, {"input": "10 1\r\n0 1\r\n", "output": ["Hungry"]}, {"input": "10 1\r\n10 10\r\n", "output": ["Full\r\n1"]}, {"input": "10 2\r\n4 4\r\n14 14\r\n", "output": ["Full\r\n2"]}, {"input": "1 1\r\n0 0\r\n", "output": ["Hungry"]}, {"input": "10 5\r\n3 3\r\n5 5\r\n8 8\r\n13 13\r\n16 16\r\n", "output": ["Full\r\n2"]}, {"input": "10 7\r\n0 0\r\n2 6\r\n8 10\r\n12 12\r\n14 14\r\n17 17\r\n19 19\r\n", "output": ["Full\r\n1"]}, {"input": "100 10\r\n18 18\r\n30 30\r\n37 37\r\n59 59\r\n83 83\r\n90 90\r\n141 141\r\n149 149\r\n173 173\r\n189 189\r\n", "output": ["Full\r\n3"]}, {"input": "100000 3\r\n0 50000\r\n99999 99999\r\n199998 199998\r\n", "output": ["Full\r\n3"]}, {"input": "100000 17\r\n7247 18957\r\n56758 64403\r\n79823 83648\r\n83649 83715\r\n83732 84946\r\n84947 84963\r\n84964 84968\r\n84970 84978\r\n84982 84991\r\n84992 87130\r\n172421 176513\r\n176514 176596\r\n176629 176689\r\n176692 177213\r\n197692 199830\r\n199831 199993\r\n199997 200000\r\n", "output": ["Full\r\n3"]}, {"input": "100000 20\r\n1425 1425\r\n14050 14050\r\n17375 17375\r\n17609 17609\r\n22704 22704\r\n25922 25922\r\n37894 37894\r\n92308 92308\r\n94002 94002\r\n99619 99619\r\n103208 103208\r\n110194 110194\r\n114468 114468\r\n141214 141214\r\n145980 145980\r\n159553 159553\r\n168441 168441\r\n169633 169633\r\n182674 182674\r\n195738 195738\r\n", "output": ["Full\r\n8"]}, {"input": "100000 3\r\n54962 59962\r\n98273 103273\r\n174042 179042\r\n", "output": ["Full\r\n1"]}, {"input": "100000 20\r\n5000 9999\r\n14999 19998\r\n24998 29997\r\n34997 39996\r\n44996 49995\r\n54995 59994\r\n64994 69993\r\n74993 79992\r\n84992 89991\r\n94991 99990\r\n104990 109989\r\n114989 119988\r\n124988 129987\r\n134987 139986\r\n144986 149985\r\n154985 159984\r\n164984 169983\r\n174983 179982\r\n184982 189981\r\n194981 199980\r\n", "output": ["Full\r\n2"]}, {"input": "100 19\r\n1 1\r\n14 14\r\n16 16\r\n36 36\r\n45 45\r\n51 51\r\n67 67\r\n77 77\r\n90 90\r\n106 106\r\n116 116\r\n129 129\r\n142 142\r\n153 153\r\n168 169\r\n180 180\r\n183 183\r\n185 185\r\n191 191\r\n", "output": ["Full\r\n2"]}, {"input": "1000 10\r\n1 1\r\n122 122\r\n502 502\r\n687 687\r\n731 731\r\n737 737\r\n825 825\r\n878 878\r\n1159 1159\r\n1396 1396\r\n", "output": ["Hungry"]}, {"input": "1000 4\r\n184 196\r\n726 737\r\n1114 1131\r\n1571 1581\r\n", "output": ["Full\r\n4"]}, {"input": "1000 6\r\n292 304\r\n1135 1147\r\n1338 1350\r\n1472 1491\r\n1720 1732\r\n1773 1790\r\n", "output": ["Full\r\n4"]}, {"input": "1000 5\r\n509 528\r\n540 551\r\n1332 1347\r\n1732 1743\r\n1777 1787\r\n", "output": ["Full\r\n3"]}, {"input": "100000 1\r\n0 200000\r\n", "output": ["Full\r\n1"]}, {"input": "100000 1\r\n100000 100000\r\n", "output": ["Full\r\n1"]}, {"input": "100000 2\r\n234 234\r\n99766 99766\r\n", "output": ["Hungry"]}, {"input": "100000 2\r\n0 99999\r\n100001 200000\r\n", "output": ["Full\r\n2"]}, {"input": "511 18\r\n1 1\r\n2 2\r\n4 4\r\n6 6\r\n10 10\r\n14 14\r\n22 22\r\n30 30\r\n46 46\r\n62 62\r\n94 94\r\n126 126\r\n190 190\r\n254 254\r\n382 382\r\n510 510\r\n766 766\r\n1022 1022\r\n", "output": ["Full\r\n9"]}, {"input": "1000 20\r\n225 225\r\n429 429\r\n560 560\r\n632 632\r\n650 650\r\n704 704\r\n768 768\r\n797 797\r\n983 983\r\n991 991\r\n1046 1046\r\n1082 1082\r\n1233 1233\r\n1366 1366\r\n1394 1394\r\n1456 1456\r\n1459 1459\r\n1519 1519\r\n1967 1967\r\n1996 1996\r\n", "output": ["Full\r\n4"]}, {"input": "10000 10\r\n479 479\r\n1024 1024\r\n4388 4388\r\n4810 4810\r\n6557 6557\r\n9697 9697\r\n11393 11393\r\n12124 12124\r\n14600 14600\r\n17536 17536\r\n", "output": ["Full\r\n7"]}, {"input": "10000 20\r\n746 746\r\n1145 1145\r\n1897 1897\r\n4254 4254\r\n6893 6893\r\n7434 7434\r\n8130 8130\r\n9755 9755\r\n10033 10033\r\n10636 10636\r\n11342 11342\r\n11651 11651\r\n12005 12005\r\n14567 14567\r\n15196 15196\r\n15947 15947\r\n16385 16385\r\n17862 17862\r\n18540 18540\r\n18948 18948\r\n", "output": ["Full\r\n5"]}, {"input": "10000 12\r\n1407 1407\r\n1878 1878\r\n4636 4636\r\n5055 5055\r\n5640 5640\r\n6379 6379\r\n6490 6490\r\n10303 10303\r\n13028 13028\r\n13578 13578\r\n18040 18040\r\n19477 19477\r\n", "output": ["Full\r\n8"]}, {"input": "55 20\r\n1 1\r\n2 2\r\n4 4\r\n6 6\r\n9 9\r\n12 12\r\n16 16\r\n20 20\r\n25 25\r\n30 30\r\n36 36\r\n42 42\r\n49 49\r\n56 56\r\n64 64\r\n72 72\r\n81 81\r\n90 90\r\n100 100\r\n110 110\r\n", "output": ["Full\r\n2"]}, {"input": "6 6\r\n3 3\r\n5 5\r\n7 7\r\n8 8\r\n9 9\r\n12 12\r\n", "output": ["Full\r\n2"]}, {"input": "100000 4\r\n0 40000\r\n41000 80000\r\n99999 99999\r\n199998 199998\r\n", "output": ["Full\r\n3"]}, {"input": "100000 12\r\n1 1751\r\n23999 25007\r\n33798 37031\r\n37117 37426\r\n37428 37436\r\n37437 40132\r\n48648 51062\r\n51071 51743\r\n51763 54643\r\n116077 119442\r\n190627 195558\r\n197662 200000\r\n", "output": ["Full\r\n3"]}, {"input": "100000 14\r\n213 1640\r\n6778 14112\r\n62548 68221\r\n68495 68864\r\n68887 68889\r\n68890 68894\r\n68896 68988\r\n69034 71515\r\n73645 77764\r\n80059 81085\r\n81086 81589\r\n136294 151585\r\n194157 199448\r\n199559 200000\r\n", "output": ["Full\r\n3"]}, {"input": "100000 16\r\n1 7\r\n9 307\r\n405 5574\r\n50346 54067\r\n54069 54100\r\n54101 55097\r\n56093 61752\r\n77951 78580\r\n78585 80749\r\n85191 87424\r\n87485 87490\r\n87491 87694\r\n87715 94544\r\n136369 138773\r\n140012 143346\r\n195045 200000\r\n", "output": ["Full\r\n3"]}, {"input": "100000 2\r\n60000 81999\r\n120000 140000\r\n", "output": ["Full\r\n3"]}, {"input": "100000 12\r\n65418 84245\r\n86341 90510\r\n135508 139243\r\n139287 139389\r\n139393 139437\r\n139440 147819\r\n198670 199954\r\n199955 199963\r\n199968 199979\r\n199980 199985\r\n199986 199997\r\n199999 200000\r\n", "output": ["Full\r\n3"]}, {"input": "100000 11\r\n42866 45922\r\n45923 49957\r\n63729 84014\r\n115856 125872\r\n125988 126003\r\n126004 129147\r\n131201 134555\r\n183782 189949\r\n189955 189967\r\n189968 197363\r\n198291 200000\r\n", "output": ["Full\r\n2"]}, {"input": "100000 8\r\n69804 76492\r\n76493 78217\r\n129407 137816\r\n137817 139388\r\n142035 152201\r\n153150 162227\r\n196326 199996\r\n200000 200000\r\n", "output": ["Full\r\n3"]}, {"input": "100000 18\r\n16 46\r\n47 154\r\n445 526\r\n537 571\r\n572 573\r\n574 580\r\n582 5922\r\n70364 73612\r\n73625 80571\r\n81628 88168\r\n122927 127021\r\n127027 127056\r\n127204 127409\r\n127410 134203\r\n145658 155259\r\n155270 163684\r\n198635 199999\r\n200000 200000\r\n", "output": ["Full\r\n3"]}, {"input": "100000 15\r\n10387 11995\r\n12012 12188\r\n12297 14393\r\n14589 15140\r\n17771 26488\r\n68905 72975\r\n73509 73881\r\n73886 73886\r\n73887 79513\r\n143598 147981\r\n150145 152841\r\n189148 199265\r\n199597 199724\r\n199772 199994\r\n199999 200000\r\n", "output": ["Full\r\n3"]}, {"input": "100000 12\r\n589 2312\r\n2349 12326\r\n12499 12759\r\n12796 21228\r\n70394 77570\r\n77571 86238\r\n133314 135096\r\n135104 135113\r\n135118 135128\r\n135135 137324\r\n190272 199989\r\n199998 200000\r\n", "output": ["Full\r\n4"]}, {"input": "100000 14\r\n3182 5382\r\n5847 10785\r\n26776 36809\r\n36961 39608\r\n65919 72524\r\n73806 75651\r\n79173 81114\r\n81115 84538\r\n112469 113763\r\n113767 113771\r\n113777 113790\r\n113792 119192\r\n193181 198259\r\n199859 200000\r\n", "output": ["Full\r\n3"]}, {"input": "100000 18\r\n3 535\r\n551 7905\r\n74333 87542\r\n124358 135027\r\n135108 142254\r\n142265 143895\r\n144091 145169\r\n145255 145273\r\n145275 145275\r\n145279 145295\r\n145302 145336\r\n145337 145348\r\n145350 145429\r\n145430 145431\r\n145441 145459\r\n145460 147266\r\n198447 199999\r\n200000 200000\r\n", "output": ["Full\r\n3"]}, {"input": "100000 8\r\n244 293\r\n379 886\r\n68058 75221\r\n102015 112569\r\n140672 146088\r\n146090 146284\r\n146289 149770\r\n197995 200000\r\n", "output": ["Full\r\n3"]}, {"input": "100000 5\r\n18547 19547\r\n24249 25249\r\n58262 59262\r\n102965 103965\r\n109453 110453\r\n", "output": ["Full\r\n5"]}, {"input": "100000 9\r\n5071 6797\r\n6916 13337\r\n64413 72188\r\n72231 72441\r\n72458 74946\r\n122835 133275\r\n133562 134079\r\n134098 141894\r\n195543 200000\r\n", "output": ["Full\r\n4"]}, {"input": "100000 6\r\n8828 9828\r\n81857 82857\r\n88071 89071\r\n94010 95010\r\n141844 142844\r\n165669 166669\r\n", "output": ["Full\r\n6"]}, {"input": "100000 7\r\n5645 6645\r\n30563 31563\r\n75140 76140\r\n107764 108764\r\n108910 109910\r\n162122 163122\r\n169774 170774\r\n", "output": ["Full\r\n3"]}, {"input": "100000 7\r\n17993 18993\r\n30906 31906\r\n49354 50354\r\n60696 61696\r\n106638 107638\r\n188177 189177\r\n190333 191333\r\n", "output": ["Full\r\n3"]}, {"input": "100000 18\r\n299 2359\r\n2646 3120\r\n3122 3123\r\n3124 4562\r\n5401 5753\r\n5754 10619\r\n72022 81017\r\n81018 81019\r\n81020 81020\r\n81021 81573\r\n82730 83638\r\n83643 83648\r\n83663 83668\r\n83669 83673\r\n83678 83681\r\n83686 91779\r\n156345 158432\r\n194512 200000\r\n", "output": ["Full\r\n4"]}, {"input": "100000 6\r\n397 1397\r\n15892 16892\r\n35746 36746\r\n94193 95193\r\n166848 167848\r\n185228 186228\r\n", "output": ["Full\r\n5"]}, {"input": "100000 16\r\n41569 49839\r\n49854 54485\r\n59507 68882\r\n68884 69855\r\n69997 72083\r\n105481 108926\r\n108927 108944\r\n108969 109043\r\n109105 109306\r\n110096 110365\r\n110573 114375\r\n180359 187643\r\n191157 196987\r\n197083 197113\r\n197140 197892\r\n199113 200000\r\n", "output": ["Full\r\n3"]}, {"input": "1000 2\r\n909 961\r\n1820 1859\r\n", "output": ["Full\r\n3"]}, {"input": "1000 5\r\n123 174\r\n716 789\r\n1284 1360\r\n1415 1443\r\n1623 1648\r\n", "output": ["Full\r\n3"]}, {"input": "1000 5\r\n381 426\r\n1092 1122\r\n1462 1481\r\n1708 1756\r\n1799 1847\r\n", "output": ["Full\r\n3"]}, {"input": "1000 4\r\n241 259\r\n1127 1154\r\n1219 1239\r\n1739 1758\r\n", "output": ["Full\r\n4"]}, {"input": "1000 5\r\n388 407\r\n488 504\r\n640 658\r\n856 875\r\n1060 1074\r\n", "output": ["Full\r\n9"]}, {"input": "1000 5\r\n182 199\r\n444 460\r\n628 640\r\n693 708\r\n1107 1119\r\n", "output": ["Full\r\n7"]}, {"input": "1000 2\r\n771 837\r\n1015 1049\r\n", "output": ["Full\r\n3"]}, {"input": "1000 3\r\n581 617\r\n802 825\r\n1040 1080\r\n", "output": ["Full\r\n5"]}, {"input": "100000 7\r\n27522 27693\r\n47266 47410\r\n58768 58929\r\n64532 64665\r\n141173 141356\r\n150364 150551\r\n183020 183160\r\n", "output": ["Full\r\n9"]}]
100
100
100
[{'input': '100000 3\r\n54962 59962\r\n98273 103273\r\n174042 179042\r\n', 'output': ['Full\r\n1']}, {'input': '100000 1\r\n100000 100000\r\n', 'output': ['Full\r\n1']}, {'input': '1000 5\r\n123 174\r\n716 789\r\n1284 1360\r\n1415 1443\r\n1623 1648\r\n', 'output': ['Full\r\n3']}, {'input': '10 2\r\n4 4\r\n14 14\r\n', 'output': ['Full\r\n2']}, {'input': '1 1\r\n0 0\r\n', 'output': ['Hungry']}]
[{'input': '100000 2\r\n0 99999\r\n100001 200000\r\n', 'output': ['Full\r\n2']}, {'input': '100000 20\r\n5000 9999\r\n14999 19998\r\n24998 29997\r\n34997 39996\r\n44996 49995\r\n54995 59994\r\n64994 69993\r\n74993 79992\r\n84992 89991\r\n94991 99990\r\n104990 109989\r\n114989 119988\r\n124988 129987\r\n134987 139986\r\n144986 149985\r\n154985 159984\r\n164984 169983\r\n174983 179982\r\n184982 189981\r\n194981 199980\r\n', 'output': ['Full\r\n2']}, {'input': '10 1\r\n0 20\r\n', 'output': ['Full\r\n1']}, {'input': '1000 2\r\n909 961\r\n1820 1859\r\n', 'output': ['Full\r\n3']}, {'input': '100000 20\r\n1425 1425\r\n14050 14050\r\n17375 17375\r\n17609 17609\r\n22704 22704\r\n25922 25922\r\n37894 37894\r\n92308 92308\r\n94002 94002\r\n99619 99619\r\n103208 103208\r\n110194 110194\r\n114468 114468\r\n141214 141214\r\n145980 145980\r\n159553 159553\r\n168441 168441\r\n169633 169633\r\n182674 182674\r\n195738 195738\r\n', 'output': ['Full\r\n8']}]
[{'input': '100000 17\r\n7247 18957\r\n56758 64403\r\n79823 83648\r\n83649 83715\r\n83732 84946\r\n84947 84963\r\n84964 84968\r\n84970 84978\r\n84982 84991\r\n84992 87130\r\n172421 176513\r\n176514 176596\r\n176629 176689\r\n176692 177213\r\n197692 199830\r\n199831 199993\r\n199997 200000\r\n', 'output': ['Full\r\n3']}, {'input': '10 5\r\n3 3\r\n5 5\r\n8 8\r\n13 13\r\n16 16\r\n', 'output': ['Full\r\n2']}, {'input': '100000 5\r\n18547 19547\r\n24249 25249\r\n58262 59262\r\n102965 103965\r\n109453 110453\r\n', 'output': ['Full\r\n5']}, {'input': '100000 7\r\n17993 18993\r\n30906 31906\r\n49354 50354\r\n60696 61696\r\n106638 107638\r\n188177 189177\r\n190333 191333\r\n', 'output': ['Full\r\n3']}, {'input': '100000 6\r\n8828 9828\r\n81857 82857\r\n88071 89071\r\n94010 95010\r\n141844 142844\r\n165669 166669\r\n', 'output': ['Full\r\n6']}]
[{'input': '100000 6\r\n397 1397\r\n15892 16892\r\n35746 36746\r\n94193 95193\r\n166848 167848\r\n185228 186228\r\n', 'output': ['Full\r\n5']}, {'input': '20 1\r\n3 19\r\n', 'output': ['Hungry']}, {'input': '1000 5\r\n123 174\r\n716 789\r\n1284 1360\r\n1415 1443\r\n1623 1648\r\n', 'output': ['Full\r\n3']}, {'input': '1000 3\r\n581 617\r\n802 825\r\n1040 1080\r\n', 'output': ['Full\r\n5']}, {'input': '100000 17\r\n7247 18957\r\n56758 64403\r\n79823 83648\r\n83649 83715\r\n83732 84946\r\n84947 84963\r\n84964 84968\r\n84970 84978\r\n84982 84991\r\n84992 87130\r\n172421 176513\r\n176514 176596\r\n176629 176689\r\n176692 177213\r\n197692 199830\r\n199831 199993\r\n199997 200000\r\n', 'output': ['Full\r\n3']}]
[{'input': '1000 6\r\n292 304\r\n1135 1147\r\n1338 1350\r\n1472 1491\r\n1720 1732\r\n1773 1790\r\n', 'output': ['Full\r\n4']}, {'input': '100000 12\r\n589 2312\r\n2349 12326\r\n12499 12759\r\n12796 21228\r\n70394 77570\r\n77571 86238\r\n133314 135096\r\n135104 135113\r\n135118 135128\r\n135135 137324\r\n190272 199989\r\n199998 200000\r\n', 'output': ['Full\r\n4']}, {'input': '100000 17\r\n7247 18957\r\n56758 64403\r\n79823 83648\r\n83649 83715\r\n83732 84946\r\n84947 84963\r\n84964 84968\r\n84970 84978\r\n84982 84991\r\n84992 87130\r\n172421 176513\r\n176514 176596\r\n176629 176689\r\n176692 177213\r\n197692 199830\r\n199831 199993\r\n199997 200000\r\n', 'output': ['Full\r\n3']}, {'input': '20 1\r\n3 19\r\n', 'output': ['Hungry']}, {'input': '100000 16\r\n1 7\r\n9 307\r\n405 5574\r\n50346 54067\r\n54069 54100\r\n54101 55097\r\n56093 61752\r\n77951 78580\r\n78585 80749\r\n85191 87424\r\n87485 87490\r\n87491 87694\r\n87715 94544\r\n136369 138773\r\n140012 143346\r\n195045 200000\r\n', 'output': ['Full\r\n3']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
212
100
100
100
["4 2", "3 2"]
The input contains a single line consisting of $$$2$$$ integers $$$N$$$ and $$$M$$$ ($$$1 \le N \le 10^{18}$$$, $$$2 \le M \le 100$$$).
e7b9eec21d950f5d963ff50619c6f119
import java.util.*; public class issam{ static class consecutive{ long mod; long[][] matrix; long nbWays(long n,int m,long mod){ this.mod = mod; if(n<(long)m) return 1; if(n==(long)m) return 2; if(m==1) return nbPow(2,n); matrix = new long[m][m]; for(int i=1;i<m;i++) matrix[i][i-1] = 1; matrix[0][0] = 1; matrix[0][m-1] = 1; matrix = pow(matrix,n-(long)m+1); long ans = 0; for(int i=0;i<m;i++){ ans += matrix[0][i]; ans %= mod; } return ans; } long nbPow(long a,long n){ if(n==1) return a; if(n%2==0){ long ans = nbPow(a,n/2); return (ans*ans)%mod; } return (a*nbPow(a,n-1))%mod; } long[][] pow(long matrix[][], long m) { if (m == 1) return matrix; if (m % 2 == 0) { long mat[][] = pow(matrix, m / 2); return multiply(mat, mat); } return multiply(matrix, pow(matrix, m - 1)); } long[][] multiply(long matrix1[][], long matrix2[][]) { long ans[][] = new long[matrix1.length][matrix2[0].length]; for (int i = 0; i < matrix1.length; i++) { for (int j = 0; j < matrix2[0].length; j++) { for (int k = 0; k < matrix1[0].length; k++) { ans[i][j] += (matrix1[i][k] * matrix2[k][j]) % mod; ans[i][j] = ans[i][j] % mod; } } } return ans; } } public static void main(String[] args){ Scanner sc = new Scanner(System.in); long n = sc.nextLong(); int m = sc.nextInt(); consecutive c = new consecutive(); long mod = 1000; mod = mod*mod*mod+7; long res = c.nbWays(n,m,mod); System.out.println(res); } }
["5", "3"]
Java
NoteIn the first example each magic gem can split into $$$2$$$ normal gems, and we know that the total amount of gems are $$$4$$$.Let $$$1$$$ denote a magic gem, and $$$0$$$ denote a normal gem.The total configurations you can have is: $$$1 1 1 1$$$ (None of the gems split); $$$0 0 1 1$$$ (First magic gem splits into $$$2$$$ normal gems); $$$1 0 0 1$$$ (Second magic gem splits into $$$2$$$ normal gems); $$$1 1 0 0$$$ (Third magic gem splits into $$$2$$$ normal gems); $$$0 0 0 0$$$ (First and second magic gems split into total $$$4$$$ normal gems). Hence, answer is $$$5$$$.
Print one integer, the total number of configurations of the resulting set of gems, given that the total amount of space taken is $$$N$$$ units. Print the answer modulo $$$1000000007$$$ ($$$10^9+7$$$).
Reziba has many magic gems. Each magic gem can be split into $$$M$$$ normal gems. The amount of space each magic (and normal) gem takes is $$$1$$$ unit. A normal gem cannot be split.Reziba wants to choose a set of magic gems and split some of them, so the total space occupied by the resulting set of gems is $$$N$$$ units. If a magic gem is chosen and split, it takes $$$M$$$ units of space (since it is split into $$$M$$$ gems); if a magic gem is not split, it takes $$$1$$$ unit.How many different configurations of the resulting set of gems can Reziba have, such that the total amount of space taken is $$$N$$$ units? Print the answer modulo $$$1000000007$$$ ($$$10^9+7$$$). Two configurations are considered different if the number of magic gems Reziba takes to form them differs, or the indices of gems Reziba has to split differ.
[{"input": "4 2\r\n", "output": ["5"]}, {"input": "3 2\r\n", "output": ["3"]}, {"input": "1000000000000000000 2\r\n", "output": ["680057396"]}, {"input": "1000000000000000000 3\r\n", "output": ["615472476"]}, {"input": "1000000000000000000 5\r\n", "output": ["285726867"]}, {"input": "1000000000000000000 42\r\n", "output": ["683499162"]}, {"input": "1000000000000000000 69\r\n", "output": ["864131130"]}, {"input": "1000000000000000000 99\r\n", "output": ["847914677"]}, {"input": "1000000000000000000 100\r\n", "output": ["161502719"]}, {"input": "1 2\r\n", "output": ["1"]}, {"input": "1 3\r\n", "output": ["1"]}, {"input": "1 4\r\n", "output": ["1"]}, {"input": "1 5\r\n", "output": ["1"]}, {"input": "2 2\r\n", "output": ["2"]}, {"input": "2 3\r\n", "output": ["1"]}, {"input": "2 4\r\n", "output": ["1"]}, {"input": "2 5\r\n", "output": ["1"]}, {"input": "5 2\r\n", "output": ["8"]}, {"input": "5 3\r\n", "output": ["4"]}, {"input": "5 4\r\n", "output": ["3"]}, {"input": "5 5\r\n", "output": ["2"]}, {"input": "6 2\r\n", "output": ["13"]}, {"input": "6 3\r\n", "output": ["6"]}, {"input": "6 4\r\n", "output": ["4"]}, {"input": "6 5\r\n", "output": ["3"]}, {"input": "7 2\r\n", "output": ["21"]}, {"input": "7 3\r\n", "output": ["9"]}, {"input": "7 4\r\n", "output": ["5"]}, {"input": "7 5\r\n", "output": ["4"]}, {"input": "99 100\r\n", "output": ["1"]}, {"input": "99 99\r\n", "output": ["2"]}, {"input": "69 30\r\n", "output": ["96"]}, {"input": "69 2\r\n", "output": ["489376391"]}, {"input": "25 2\r\n", "output": ["121393"]}, {"input": "576460752303423487 100\r\n", "output": ["163029191"]}, {"input": "144115188075855871 100\r\n", "output": ["156647062"]}, {"input": "288230376151711743 100\r\n", "output": ["626842151"]}]
100
100
100
[{'input': '1000000000000000000 69\r\n', 'output': ['864131130']}, {'input': '1000000000000000000 99\r\n', 'output': ['847914677']}, {'input': '5 4\r\n', 'output': ['3']}, {'input': '69 2\r\n', 'output': ['489376391']}, {'input': '99 99\r\n', 'output': ['2']}]
[{'input': '5 5\r\n', 'output': ['2']}, {'input': '2 4\r\n', 'output': ['1']}, {'input': '25 2\r\n', 'output': ['121393']}, {'input': '1000000000000000000 2\r\n', 'output': ['680057396']}, {'input': '6 5\r\n', 'output': ['3']}]
[{'input': '2 5\r\n', 'output': ['1']}, {'input': '1000000000000000000 5\r\n', 'output': ['285726867']}, {'input': '1000000000000000000 69\r\n', 'output': ['864131130']}, {'input': '4 2\r\n', 'output': ['5']}, {'input': '7 2\r\n', 'output': ['21']}]
[{'input': '1000000000000000000 5\r\n', 'output': ['285726867']}, {'input': '1000000000000000000 3\r\n', 'output': ['615472476']}, {'input': '576460752303423487 100\r\n', 'output': ['163029191']}, {'input': '1000000000000000000 100\r\n', 'output': ['161502719']}, {'input': '5 5\r\n', 'output': ['2']}]
[{'input': '5 5\r\n', 'output': ['2']}, {'input': '2 5\r\n', 'output': ['1']}, {'input': '1000000000000000000 99\r\n', 'output': ['847914677']}, {'input': '5 3\r\n', 'output': ['4']}, {'input': '2 2\r\n', 'output': ['2']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
213
100
100
100
["3", "6", "100"]
The single line contains a single integer n (1 ≀ n ≀ 105).
63262317ba572d78163c91b853c05506
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashSet; import java.util.Arrays; import java.util.InputMismatchException; import java.io.IOException; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Sparsh Sanchorawala */ 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); CInterestingGame solver = new CInterestingGame(); solver.solve(1, in, out); out.close(); } static class CInterestingGame { public void solve(int testNumber, InputReader s, PrintWriter w) { int n = s.nextInt(); ArrayList<Pair>[] pair = new ArrayList[n + 1]; for (int i = 1; i <= n; i++) pair[i] = new ArrayList<>(); for (int k = 2; k <= n; k++) for (int a = 1; (long) (2 * a + k - 1) * k / 2 <= n; a++) pair[(2 * a + k - 1) * k / 2].add(new Pair(a, k)); int[] grundy = new int[n + 1]; int[] val = new int[n + 1]; Arrays.fill(val, Integer.MAX_VALUE); int[] pre = new int[n + 1]; for (int i = 2; i <= n; i++) { HashSet<Integer> hs = new HashSet<>(); for (Pair p : pair[i]) { hs.add(pre[p.a + p.n - 1] ^ pre[p.a - 1]); if ((pre[p.a + p.n - 1] ^ pre[p.a - 1]) == 0) val[i] = Math.min(p.n, val[i]); } while (hs.contains(grundy[i])) grundy[i]++; pre[i] = grundy[i] ^ pre[i - 1]; } w.println(val[n] != Integer.MAX_VALUE ? val[n] : -1); } class Pair { int a; int n; Pair(int a, int n) { this.a = a; this.n = n; } } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int 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 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); } } }
["2", "-1", "8"]
Java
null
If Serozha wins, print k, which represents the minimal number of piles into which he can split the initial one during the first move in order to win the game. If Gena wins, print "-1" (without the quotes).
Two best friends Serozha and Gena play a game.Initially there is one pile consisting of n stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of a1 &gt; a2 &gt; ... &gt; ak &gt; 0 stones. The piles should meet the condition a1 - a2 = a2 - a3 = ... = ak - 1 - ak = 1. Naturally, the number of piles k should be no less than two.The friends play in turns. The player who cannot make a move loses. Serozha makes the first move. Who will win if both players play in the optimal way?
[{"input": "3\r\n", "output": ["2"]}, {"input": "6\r\n", "output": ["-1"]}, {"input": "100\r\n", "output": ["8"]}, {"input": "33\r\n", "output": ["2"]}, {"input": "23\r\n", "output": ["-1"]}, {"input": "35\r\n", "output": ["-1"]}, {"input": "15\r\n", "output": ["2"]}, {"input": "99\r\n", "output": ["2"]}, {"input": "46\r\n", "output": ["4"]}, {"input": "78\r\n", "output": ["4"]}, {"input": "627\r\n", "output": ["2"]}, {"input": "250\r\n", "output": ["5"]}, {"input": "873\r\n", "output": ["18"]}, {"input": "871\r\n", "output": ["-1"]}, {"input": "684\r\n", "output": ["-1"]}, {"input": "303\r\n", "output": ["2"]}, {"input": "93764\r\n", "output": ["-1"]}, {"input": "39509\r\n", "output": ["-1"]}, {"input": "70878\r\n", "output": ["-1"]}, {"input": "7578\r\n", "output": ["3"]}, {"input": "31893\r\n", "output": ["3"]}, {"input": "57113\r\n", "output": ["2"]}, {"input": "66873\r\n", "output": ["2"]}, {"input": "9564\r\n", "output": ["3"]}, {"input": "42237\r\n", "output": ["18"]}, {"input": "92763\r\n", "output": ["22"]}, {"input": "38798\r\n", "output": ["76"]}, {"input": "63359\r\n", "output": ["34"]}, {"input": "573\r\n", "output": ["3"]}, {"input": "60879\r\n", "output": ["2"]}, {"input": "67341\r\n", "output": ["2"]}, {"input": "15748\r\n", "output": ["8"]}, {"input": "42602\r\n", "output": ["17"]}, {"input": "67817\r\n", "output": ["73"]}, {"input": "81207\r\n", "output": ["6"]}, {"input": "8149\r\n", "output": ["2"]}, {"input": "95298\r\n", "output": ["4"]}, {"input": "41385\r\n", "output": ["15"]}, {"input": "27443\r\n", "output": ["2"]}, {"input": "74424\r\n", "output": ["21"]}, {"input": "35708\r\n", "output": ["-1"]}, {"input": "36655\r\n", "output": ["-1"]}, {"input": "34378\r\n", "output": ["-1"]}, {"input": "63478\r\n", "output": ["-1"]}, {"input": "42863\r\n", "output": ["-1"]}, {"input": "19715\r\n", "output": ["-1"]}, {"input": "37317\r\n", "output": ["-1"]}, {"input": "96992\r\n", "output": ["-1"]}, {"input": "56056\r\n", "output": ["-1"]}, {"input": "45899\r\n", "output": ["-1"]}, {"input": "1\r\n", "output": ["-1"]}, {"input": "100000\r\n", "output": ["-1"]}, {"input": "56\r\n", "output": ["-1"]}, {"input": "38\r\n", "output": ["-1"]}, {"input": "1515\r\n", "output": ["2"]}]
100
100
100
[{'input': '41385\r\n', 'output': ['15']}, {'input': '6\r\n', 'output': ['-1']}, {'input': '573\r\n', 'output': ['3']}, {'input': '3\r\n', 'output': ['2']}, {'input': '38798\r\n', 'output': ['76']}]
[{'input': '42602\r\n', 'output': ['17']}, {'input': '66873\r\n', 'output': ['2']}, {'input': '684\r\n', 'output': ['-1']}, {'input': '35\r\n', 'output': ['-1']}, {'input': '42863\r\n', 'output': ['-1']}]
[{'input': '100000\r\n', 'output': ['-1']}, {'input': '9564\r\n', 'output': ['3']}, {'input': '35708\r\n', 'output': ['-1']}, {'input': '56\r\n', 'output': ['-1']}, {'input': '100\r\n', 'output': ['8']}]
[{'input': '45899\r\n', 'output': ['-1']}, {'input': '56\r\n', 'output': ['-1']}, {'input': '1515\r\n', 'output': ['2']}, {'input': '36655\r\n', 'output': ['-1']}, {'input': '63478\r\n', 'output': ['-1']}]
[{'input': '100000\r\n', 'output': ['-1']}, {'input': '39509\r\n', 'output': ['-1']}, {'input': '46\r\n', 'output': ['4']}, {'input': '63478\r\n', 'output': ['-1']}, {'input': '8149\r\n', 'output': ['2']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
214
100
100
100
["2 0 3 3 5 21", "2 4 3 0 6 17"]
The only line contains six integers a1, b1, a2, b2, L, R (0 &lt; a1, a2 ≀ 2Β·109,  - 2Β·109 ≀ b1, b2, L, R ≀ 2Β·109, L ≀ R).
b08ee0cd6f5cb574086fa02f07d457a4
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.math.BigInteger; import java.util.Random; import java.util.StringTokenizer; public class D { public static void main(String[] args) { FastScanner sc = new FastScanner(); long a1 = sc.nextLong(); long b1 = sc.nextLong(); long a2 = sc.nextLong(); long b2 = sc.nextLong(); long left = sc.nextLong(); long right = sc.nextLong(); long lcm = lcm(a1, a2); left = Math.max(left, Math.max(b1, b2)); // a1*x + b1 = a2*y + b2 // a1*x - a2*y = b1 - b2 long[] x_y_gcd = solveDiophantine(a1, -a2, b2 - b1); if (x_y_gcd == null) { System.out.println(0); } else { BigInteger a1Bi = BigInteger.valueOf(a1); BigInteger b1Bi = BigInteger.valueOf(b1); BigInteger leftBi = BigInteger.valueOf(left); BigInteger rightBi = BigInteger.valueOf(right); BigInteger lcmBi = BigInteger.valueOf(lcm); BigInteger firstEq = a1Bi.multiply(BigInteger.valueOf(x_y_gcd[0])).add(b1Bi); BigInteger diff = leftBi.subtract(firstEq).divide(lcmBi).subtract(BigInteger.ONE); firstEq = firstEq.add(diff.multiply(lcmBi)); while (firstEq.compareTo(leftBi) < 0) { firstEq = firstEq.add(lcmBi); } if (rightBi.compareTo(firstEq) < 0) { System.out.println(0); } else { long count = Math.max(rightBi.subtract(firstEq).divide(lcmBi).longValue() + 1, 0); System.out.println(count); } } } /** * Finds a single solution {x, y} to the LDE a*x + b*y = c. * Outputs an array of the form {x, y, d}, where d = GCD(a,b). */ private static long[] solveDiophantine(long a, long b, long c) { long[] e = extEuclid(a, b); long k = c / e[2]; //c not divisible by the GCD(a,b) -> no solution if (c - k * e[2] != 0) return null; long[] output = {e[0] * k, e[1] * k, e[2]}; return output; } /** * Extended Euclidean Algorithm finds {x, y, d} * where d=GCD(a,b) and x and y satisfy a*x + b*y = d * The output is an array of the form {x, y, d}. */ private static long[] extEuclid(long a, long b) { long s0 = 1, s1 = 0, sTemp; long t0 = 0, t1 = 1, tTemp; long r0 = a, r1 = b, rTemp; long q; while (r1 != 0) { q = r0 / r1; rTemp = r1; r1 = r0 - q * r1; r0 = rTemp; sTemp = s1; s1 = s0 - q * s1; s0 = sTemp; tTemp = t1; t1 = t0 - q * t1; t0 = tTemp; } long[] output = {s0, t0, r0}; return output; } static long lcm(long a, long b) { return a / gcd(a, b) * b; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } public static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(Reader in) { br = new BufferedReader(in); } public FastScanner() { this(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String readNextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readIntArray(int n) { int[] a = new int[n]; for (int idx = 0; idx < n; idx++) { a[idx] = nextInt(); } return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int idx = 0; idx < n; idx++) { a[idx] = nextLong(); } return a; } } }
["3", "2"]
Java
null
Print the desired number of integers x.
You are given two arithmetic progressions: a1k + b1 and a2l + b2. Find the number of integers x such that L ≀ x ≀ R and x = a1k' + b1 = a2l' + b2, for some integers k', l' β‰₯ 0.
[{"input": "2 0 3 3 5 21\r\n", "output": ["3"]}, {"input": "2 4 3 0 6 17\r\n", "output": ["2"]}, {"input": "2 0 4 2 -39 -37\r\n", "output": ["0"]}, {"input": "1 9 3 11 49 109\r\n", "output": ["20"]}, {"input": "3 81 5 72 -1761 501\r\n", "output": ["28"]}, {"input": "8 -89 20 67 8771 35222\r\n", "output": ["661"]}, {"input": "1 -221 894 86403 -687111 141371\r\n", "output": ["62"]}, {"input": "1 -1074 271 17741 -2062230 1866217\r\n", "output": ["6821"]}, {"input": "3 2408 819 119198 -8585197 7878219\r\n", "output": ["9474"]}, {"input": "1 341 8581 3946733 -59420141 33253737\r\n", "output": ["3416"]}, {"input": "1 10497 19135 2995296 -301164547 -180830773\r\n", "output": ["0"]}, {"input": "8 40306 2753 1809818 254464419 340812028\r\n", "output": ["3921"]}, {"input": "2 21697 9076 1042855 -319348358 236269755\r\n", "output": ["25918"]}, {"input": "4 2963 394 577593 125523962 628140505\r\n", "output": ["637839"]}, {"input": "75 61736 200 200511 160330870 609945842\r\n", "output": ["749358"]}, {"input": "34 64314 836 5976 591751179 605203191\r\n", "output": ["946"]}, {"input": "1 30929 25249 95822203 -1076436442 705164517\r\n", "output": ["24134"]}, {"input": "3 -1208 459 933808 603490653 734283665\r\n", "output": ["284952"]}, {"input": "1 35769 16801 47397023 -82531776 1860450454\r\n", "output": ["107914"]}, {"input": "1 -3078 36929 51253687 -754589746 -53412627\r\n", "output": ["0"]}, {"input": "1 -32720 3649 7805027 408032642 925337350\r\n", "output": ["141766"]}, {"input": "1 -2000000000 1 -2000000000 -2000000000 2000000000\r\n", "output": ["4000000001"]}, {"input": "1 -2000000000 2 -2000000000 -2000000000 2000000000\r\n", "output": ["2000000001"]}, {"input": "3 -2000000000 2 -2000000000 -2000000000 2000000000\r\n", "output": ["666666667"]}, {"input": "999999999 999999998 1000000000 999999999 1 10000\r\n", "output": ["0"]}, {"input": "1 -2000000000 1 2000000000 1 10\r\n", "output": ["0"]}, {"input": "1 -2000000000 2 2000000000 -2000000000 2000000000\r\n", "output": ["1"]}, {"input": "2 0 2 1 0 1000000000\r\n", "output": ["0"]}, {"input": "1000000000 0 1 0 0 2000000000\r\n", "output": ["3"]}, {"input": "4 0 4 1 5 100\r\n", "output": ["0"]}, {"input": "1000000000 1 999999999 0 1 100000000\r\n", "output": ["0"]}, {"input": "1 30929 1 1 1 1\r\n", "output": ["0"]}, {"input": "1 1 1 1 -2000000000 2000000000\r\n", "output": ["2000000000"]}, {"input": "4 0 4 1 0 100\r\n", "output": ["0"]}, {"input": "1 -2000000000 1 2000000000 5 5\r\n", "output": ["0"]}, {"input": "51 -1981067352 71 -414801558 -737219217 1160601982\r\n", "output": ["435075"]}, {"input": "2 -1500000000 4 -1499999999 1600000000 1700000000\r\n", "output": ["0"]}, {"input": "135 -1526277729 32 1308747737 895574 1593602399\r\n", "output": ["65938"]}, {"input": "1098197640 6 994625382 6 -474895292 -101082478\r\n", "output": ["0"]}, {"input": "12 -696575903 571708420 236073275 2 14\r\n", "output": ["0"]}, {"input": "1 -9 2 -10 -10 -9\r\n", "output": ["0"]}, {"input": "2 -11 2 -9 -11 -9\r\n", "output": ["1"]}, {"input": "40 54 15 74 -180834723 1373530127\r\n", "output": ["11446084"]}, {"input": "2 57 1 56 -1773410854 414679043\r\n", "output": ["207339494"]}, {"input": "9 12 1 40 624782492 883541397\r\n", "output": ["28750990"]}, {"input": "4 -1000000000 2 4 100 1000\r\n", "output": ["226"]}, {"input": "66 90 48 84 -1709970247 1229724777\r\n", "output": ["2329024"]}, {"input": "1000000000 1 2000000000 0 -2000000000 200000000\r\n", "output": ["0"]}, {"input": "2 0 2 1 -1000000000 1000000000\r\n", "output": ["0"]}, {"input": "2 -1000000000 2 -999999999 -1000000000 1000000000\r\n", "output": ["0"]}, {"input": "26 1885082760 30 -1612707510 -1113844607 1168679422\r\n", "output": ["0"]}, {"input": "76 -19386 86 -6257 164862270 1443198941\r\n", "output": ["0"]}, {"input": "5 -2000000000 5 1000000000 1000000000 2000000000\r\n", "output": ["200000001"]}, {"input": "505086589 -4 1288924334 -4 -5 -4\r\n", "output": ["1"]}, {"input": "91 -193581878 2 1698062870 -819102473 1893630769\r\n", "output": ["1074549"]}, {"input": "8 11047 45 12730 -45077355 1727233357\r\n", "output": ["4797835"]}, {"input": "35 8673 6 -19687 -111709844 1321584980\r\n", "output": ["6293220"]}, {"input": "71 1212885043 55 1502412287 970234397 1952605611\r\n", "output": ["115287"]}, {"input": "274497829 -12 9 -445460655 -5 4\r\n", "output": ["0"]}, {"input": "1509527550 3 7 -134101853 2 7\r\n", "output": ["1"]}, {"input": "43 -1478944506 45 494850401 634267177 1723176461\r\n", "output": ["562743"]}, {"input": "25 479638866 50 -874479027 -2000000000 2000000000\r\n", "output": ["0"]}, {"input": "11 -10 1 -878946597 -11127643 271407906\r\n", "output": ["24673447"]}, {"input": "15 -738862158 12 -3 -3 12\r\n", "output": ["1"]}, {"input": "70 -835526513 23 687193329 -1461506792 1969698938\r\n", "output": ["796587"]}, {"input": "124 1413 15321 312133 3424 1443242\r\n", "output": ["0"]}, {"input": "75 -13580 14 4508 -67634192 1808916097\r\n", "output": ["1722773"]}, {"input": "915583842 -15 991339476 -12 -15 -5\r\n", "output": ["0"]}, {"input": "85 -18257 47 -7345 -76967244 1349252598\r\n", "output": ["337737"]}, {"input": "178 331734603 162 -73813367 -577552570 1005832995\r\n", "output": ["46754"]}, {"input": "8 -17768 34 963 -2000000000 2000000000\r\n", "output": ["0"]}, {"input": "26 1885082760 30 -1612707510 -2000000000 2000000000\r\n", "output": ["294660"]}, {"input": "4 -1999999999 6 -1999999998 -999999999 1999999999\r\n", "output": ["0"]}, {"input": "121826 1323 1327 304172 -1521910750 860413213\r\n", "output": ["5"]}, {"input": "36281 170 1917 927519 -1767064448 -177975414\r\n", "output": ["0"]}, {"input": "37189 -436 464 797102 -1433652908 1847752465\r\n", "output": ["107"]}, {"input": "81427 -688 1720 -221771 -77602716 1593447723\r\n", "output": ["11"]}, {"input": "11 -1609620737 1315657088 -7 -162162918 287749240\r\n", "output": ["0"]}, {"input": "1480269313 -1048624081 1314841531 -8 295288505 358226461\r\n", "output": ["0"]}, {"input": "13 -15 19 -2 -334847526 1334632952\r\n", "output": ["5403373"]}, {"input": "1254161381 -7 821244830 -7 -698761303 941496965\r\n", "output": ["1"]}, {"input": "1269100557 -5 6 -5 -12 -6\r\n", "output": ["0"]}, {"input": "847666888 -6 1327933031 -6 -5 -2\r\n", "output": ["0"]}, {"input": "1465846675 1002489474 9 -1250811979 1030017372 1391560043\r\n", "output": ["0"]}, {"input": "8 -1915865359 867648990 9 -5 -4\r\n", "output": ["0"]}, {"input": "3 -1164702220 906446587 -1868913852 222249893 1493113759\r\n", "output": ["0"]}, {"input": "15 -8 17 3 -393290856 231975525\r\n", "output": ["909708"]}, {"input": "734963978 0 17 0 -12 -5\r\n", "output": ["0"]}, {"input": "1090004357 5 1124063714 -840327001 -448110704 128367602\r\n", "output": ["0"]}, {"input": "18 -1071025614 1096150070 0 -6 0\r\n", "output": ["1"]}, {"input": "451525105 -8 1256335024 -8 -718788747 928640626\r\n", "output": ["1"]}, {"input": "4 3 5 -1292190012 -97547955 250011754\r\n", "output": ["12500588"]}, {"input": "14 -7 14 -1488383431 -1044342357 842171605\r\n", "output": ["0"]}, {"input": "1384140089 5 16 -1661922737 442287491 1568124284\r\n", "output": ["0"]}, {"input": "16 -11 14 -1466771835 -1192555694 -2257860\r\n", "output": ["0"]}, {"input": "1676164235 -1589020998 1924931103 1189158232 6 12\r\n", "output": ["0"]}, {"input": "15 16 12 -5 11 23\r\n", "output": ["0"]}, {"input": "16 -16 5 20 -9 7\r\n", "output": ["0"]}, {"input": "4 -9 1 -2 -13 -1\r\n", "output": ["1"]}, {"input": "18 -17 9 -17 -29 17\r\n", "output": ["2"]}, {"input": "735463638 620656007 878587644 536507630 -1556948056 1714374073\r\n", "output": ["0"]}, {"input": "1789433851 -633540112 1286318222 -1728151682 1438333624 1538194890\r\n", "output": ["0"]}, {"input": "15 -1264610276 1157160166 -336457087 -496892962 759120142\r\n", "output": ["0"]}, {"input": "831644204 422087925 17 -1288230412 -1090082747 1271113499\r\n", "output": ["1"]}, {"input": "17 -13 223959272 -1081245422 -1756575771 38924201\r\n", "output": ["1"]}, {"input": "1228969457 -1826233120 11 -1063855654 -819177202 1039858319\r\n", "output": ["0"]}, {"input": "1186536442 -1691684240 17 -1 -702600351 1121394816\r\n", "output": ["1"]}, {"input": "1132421757 -1481846636 515765656 -12 -622203577 552143596\r\n", "output": ["0"]}, {"input": "18 -1123473160 1826212361 -10 -12 1\r\n", "output": ["1"]}, {"input": "1197045662 7 15 -1445473718 -1406137199 800415943\r\n", "output": ["1"]}, {"input": "18 565032929 13 735553852 107748471 1945959489\r\n", "output": ["5172673"]}, {"input": "1734271904 1 19 -1826828681 0 4\r\n", "output": ["1"]}, {"input": "1614979757 -1237127436 12 75067457 -933537920 451911806\r\n", "output": ["1"]}, {"input": "8 -335942902 1179386720 -723257398 -13 -12\r\n", "output": ["0"]}, {"input": "989432982 2 9 366779468 -1427636085 985664909\r\n", "output": ["0"]}, {"input": "7 -1390956935 1404528667 -4 -15 0\r\n", "output": ["1"]}, {"input": "1370475975 841789607 733784598 467967887 -7 15\r\n", "output": ["0"]}, {"input": "6 -7 9 -1 -10 1\r\n", "output": ["1"]}, {"input": "960716652 1417038753 1222139305 -4 -1570098546 -931528535\r\n", "output": ["0"]}, {"input": "1744394473 5 1523286739 629247513 -6 1\r\n", "output": ["0"]}, {"input": "2627 -4960 2627 -4960 -4960 4960\r\n", "output": ["4"]}, {"input": "6 -364562196 7 -803430276 0 11\r\n", "output": ["0"]}, {"input": "1955378240 -837482305 1743607821 -1623988108 -653286850 178227154\r\n", "output": ["0"]}, {"input": "9 -1642366642 1499382371 -6 -822052389 1405478033\r\n", "output": ["0"]}, {"input": "9 -1 8 -1 -711474975 237571596\r\n", "output": ["3299606"]}, {"input": "1497677869 -1313800455 11 12 -1157529918 1754001465\r\n", "output": ["1"]}, {"input": "11 -80049925 1600186381 -1454831688 -1384227392 1621203975\r\n", "output": ["0"]}, {"input": "1042015302 -56794440 1727095321 -1037110962 -9 11\r\n", "output": ["0"]}, {"input": "13 0 1419591662 -1360930956 343359607 1283114457\r\n", "output": ["0"]}, {"input": "752411560 -6 857048450 -405514986 -5 0\r\n", "output": ["0"]}, {"input": "12 2 18 2 -6 3\r\n", "output": ["1"]}, {"input": "11 -1 15 -1 -13 2\r\n", "output": ["1"]}, {"input": "1446642133 -7 9 -1719422944 -916435667 36154654\r\n", "output": ["1"]}, {"input": "1689390799 501112014 13 -1621132473 398367938 709483101\r\n", "output": ["0"]}, {"input": "1932547151 -725726769 782679113 -10 -184530763 498112212\r\n", "output": ["0"]}]
100
100
100
[{'input': '1 1 1 1 -2000000000 2000000000\r\n', 'output': ['2000000000']}, {'input': '1 10497 19135 2995296 -301164547 -180830773\r\n', 'output': ['0']}, {'input': '1689390799 501112014 13 -1621132473 398367938 709483101\r\n', 'output': ['0']}, {'input': '1228969457 -1826233120 11 -1063855654 -819177202 1039858319\r\n', 'output': ['0']}, {'input': '1614979757 -1237127436 12 75067457 -933537920 451911806\r\n', 'output': ['1']}]
[{'input': '16 -16 5 20 -9 7\r\n', 'output': ['0']}, {'input': '66 90 48 84 -1709970247 1229724777\r\n', 'output': ['2329024']}, {'input': '1446642133 -7 9 -1719422944 -916435667 36154654\r\n', 'output': ['1']}, {'input': '2 -1500000000 4 -1499999999 1600000000 1700000000\r\n', 'output': ['0']}, {'input': '18 -1123473160 1826212361 -10 -12 1\r\n', 'output': ['1']}]
[{'input': '989432982 2 9 366779468 -1427636085 985664909\r\n', 'output': ['0']}, {'input': '1480269313 -1048624081 1314841531 -8 295288505 358226461\r\n', 'output': ['0']}, {'input': '13 0 1419591662 -1360930956 343359607 1283114457\r\n', 'output': ['0']}, {'input': '70 -835526513 23 687193329 -1461506792 1969698938\r\n', 'output': ['796587']}, {'input': '15 16 12 -5 11 23\r\n', 'output': ['0']}]
[{'input': '1 1 1 1 -2000000000 2000000000\r\n', 'output': ['2000000000']}, {'input': '8 40306 2753 1809818 254464419 340812028\r\n', 'output': ['3921']}, {'input': '66 90 48 84 -1709970247 1229724777\r\n', 'output': ['2329024']}, {'input': '2 -1000000000 2 -999999999 -1000000000 1000000000\r\n', 'output': ['0']}, {'input': '1 -2000000000 2 2000000000 -2000000000 2000000000\r\n', 'output': ['1']}]
[{'input': '4 -9 1 -2 -13 -1\r\n', 'output': ['1']}, {'input': '1 -9 2 -10 -10 -9\r\n', 'output': ['0']}, {'input': '12 -696575903 571708420 236073275 2 14\r\n', 'output': ['0']}, {'input': '8 40306 2753 1809818 254464419 340812028\r\n', 'output': ['3921']}, {'input': '9 -1 8 -1 -711474975 237571596\r\n', 'output': ['3299606']}]
100
100
100
100
100
96.15
100
96.15
98.08
100
83.33
100
83.33
91.67
100
215
100
98.076
91.666
["3 2\n1 3\n2 1", "5 5\n3 3\n3 3", "4 2\n2 3\n1 2"]
The first line contains two space-separated numbers a1 and b1 β€” the sides of the board. Next two lines contain numbers a2, b2, a3 and b3 β€” the sides of the paintings. All numbers ai, bi in the input are integers and fit into the range from 1 to 1000.
2ff30d9c4288390fd7b5b37715638ad9
import java.util.*; public class CF560BGetaldIntoArts { public static void main(String[] args) { Scanner s = new Scanner(System.in); boolean b = true; int a1 = s.nextInt(); int b1 = s.nextInt(); int a2 = s.nextInt(); int b2 = s.nextInt(); int a3 = s.nextInt(); int b3 = s.nextInt(); if(a1 >= Math.max(a2,a3) && b2+b3<=b1) b = true; else if(a1 >= Math.max(a2,b3) && b2+a3<=b1) b = true; else if(a1 >= Math.max(a3,b2) && b3+a2<=b1) b = true; else if(a1 >= Math.max(b2,b3) && a2+a3<=b1) b = true; else b = false; if(b1 >= Math.max(a2,a3) && b2+b3<=a1) b = true; else if(b1 >= Math.max(a2,b3) && b2+a3<=a1) b = true; else if(b1>=Math.max(a3,b2) && b3+a2<=a1) b = true; else if(b1>=Math.max(b2,b3) && a2+a3<=a1) b = true; if(b == false){ System.out.println("NO"); } else System.out.println("YES"); } }
["YES", "NO", "YES"]
Java
NoteThat's how we can place the pictures in the first test:And that's how we can do it in the third one.
If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes).
Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an a1 × b1 rectangle, the paintings have shape of a a2 × b2 and a3 × b3 rectangles.Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be parallel to the floor. The paintings can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it is possible to place the paintings on the board, or is the board he bought not large enough?
[{"input": "3 2\r\n1 3\r\n2 1\r\n", "output": ["YES"]}, {"input": "5 5\r\n3 3\r\n3 3\r\n", "output": ["NO"]}, {"input": "4 2\r\n2 3\r\n1 2\r\n", "output": ["YES"]}, {"input": "3 3\r\n1 1\r\n1 1\r\n", "output": ["YES"]}, {"input": "1000 1000\r\n999 999\r\n1 1000\r\n", "output": ["YES"]}, {"input": "7 7\r\n5 5\r\n2 4\r\n", "output": ["YES"]}, {"input": "3 3\r\n2 2\r\n2 2\r\n", "output": ["NO"]}, {"input": "2 9\r\n5 1\r\n3 2\r\n", "output": ["YES"]}, {"input": "9 9\r\n3 8\r\n5 2\r\n", "output": ["YES"]}, {"input": "10 10\r\n10 5\r\n4 3\r\n", "output": ["YES"]}, {"input": "10 6\r\n10 1\r\n5 7\r\n", "output": ["YES"]}, {"input": "6 10\r\n6 3\r\n6 2\r\n", "output": ["YES"]}, {"input": "7 10\r\n7 5\r\n1 7\r\n", "output": ["YES"]}, {"input": "10 10\r\n7 4\r\n3 5\r\n", "output": ["YES"]}, {"input": "4 10\r\n1 1\r\n9 3\r\n", "output": ["YES"]}, {"input": "8 7\r\n1 7\r\n3 2\r\n", "output": ["YES"]}, {"input": "5 10\r\n5 2\r\n3 5\r\n", "output": ["YES"]}, {"input": "9 9\r\n9 7\r\n2 9\r\n", "output": ["YES"]}, {"input": "8 10\r\n3 8\r\n7 4\r\n", "output": ["YES"]}, {"input": "10 10\r\n6 6\r\n4 9\r\n", "output": ["YES"]}, {"input": "8 9\r\n7 6\r\n2 3\r\n", "output": ["YES"]}, {"input": "10 10\r\n9 10\r\n6 1\r\n", "output": ["YES"]}, {"input": "90 100\r\n52 76\r\n6 47\r\n", "output": ["YES"]}, {"input": "84 99\r\n82 54\r\n73 45\r\n", "output": ["YES"]}, {"input": "100 62\r\n93 3\r\n100 35\r\n", "output": ["YES"]}, {"input": "93 98\r\n75 32\r\n63 7\r\n", "output": ["YES"]}, {"input": "86 100\r\n2 29\r\n71 69\r\n", "output": ["YES"]}, {"input": "96 100\r\n76 21\r\n78 79\r\n", "output": ["YES"]}, {"input": "99 100\r\n95 68\r\n85 32\r\n", "output": ["YES"]}, {"input": "97 100\r\n95 40\r\n70 60\r\n", "output": ["YES"]}, {"input": "100 100\r\n6 45\r\n97 54\r\n", "output": ["YES"]}, {"input": "99 100\r\n99 72\r\n68 1\r\n", "output": ["YES"]}, {"input": "88 100\r\n54 82\r\n86 45\r\n", "output": ["YES"]}, {"input": "91 100\r\n61 40\r\n60 88\r\n", "output": ["YES"]}, {"input": "100 100\r\n36 32\r\n98 68\r\n", "output": ["YES"]}, {"input": "78 86\r\n63 8\r\n9 4\r\n", "output": ["YES"]}, {"input": "72 93\r\n38 5\r\n67 64\r\n", "output": ["YES"]}, {"input": "484 1000\r\n465 2\r\n9 535\r\n", "output": ["YES"]}, {"input": "808 1000\r\n583 676\r\n527 416\r\n", "output": ["YES"]}, {"input": "965 1000\r\n606 895\r\n533 394\r\n", "output": ["YES"]}, {"input": "824 503\r\n247 595\r\n151 570\r\n", "output": ["YES"]}, {"input": "970 999\r\n457 305\r\n542 597\r\n", "output": ["YES"]}, {"input": "332 834\r\n312 23\r\n505 272\r\n", "output": ["YES"]}, {"input": "886 724\r\n830 439\r\n102 594\r\n", "output": ["YES"]}, {"input": "958 1000\r\n326 461\r\n836 674\r\n", "output": ["YES"]}, {"input": "903 694\r\n104 488\r\n567 898\r\n", "output": ["YES"]}, {"input": "800 1000\r\n614 163\r\n385 608\r\n", "output": ["YES"]}, {"input": "926 1000\r\n813 190\r\n187 615\r\n", "output": ["YES"]}, {"input": "541 1000\r\n325 596\r\n403 56\r\n", "output": ["YES"]}, {"input": "881 961\r\n139 471\r\n323 731\r\n", "output": ["YES"]}, {"input": "993 1000\r\n201 307\r\n692 758\r\n", "output": ["YES"]}, {"input": "954 576\r\n324 433\r\n247 911\r\n", "output": ["YES"]}, {"input": "7 3\r\n7 8\r\n1 5\r\n", "output": ["NO"]}, {"input": "5 9\r\n2 7\r\n8 10\r\n", "output": ["NO"]}, {"input": "10 4\r\n4 3\r\n5 10\r\n", "output": ["NO"]}, {"input": "2 7\r\n8 3\r\n2 7\r\n", "output": ["NO"]}, {"input": "1 4\r\n7 2\r\n3 2\r\n", "output": ["NO"]}, {"input": "5 8\r\n5 1\r\n10 5\r\n", "output": ["NO"]}, {"input": "3 5\r\n3 6\r\n10 7\r\n", "output": ["NO"]}, {"input": "6 2\r\n6 6\r\n1 2\r\n", "output": ["NO"]}, {"input": "10 3\r\n6 6\r\n4 7\r\n", "output": ["NO"]}, {"input": "9 10\r\n4 8\r\n5 6\r\n", "output": ["YES"]}, {"input": "3 8\r\n3 2\r\n8 7\r\n", "output": ["NO"]}, {"input": "3 3\r\n3 4\r\n3 6\r\n", "output": ["NO"]}, {"input": "6 10\r\n1 8\r\n3 2\r\n", "output": ["YES"]}, {"input": "8 1\r\n7 5\r\n3 9\r\n", "output": ["NO"]}, {"input": "9 7\r\n5 2\r\n4 1\r\n", "output": ["YES"]}, {"input": "100 30\r\n42 99\r\n78 16\r\n", "output": ["NO"]}, {"input": "64 76\r\n5 13\r\n54 57\r\n", "output": ["YES"]}, {"input": "85 19\r\n80 18\r\n76 70\r\n", "output": ["NO"]}, {"input": "57 74\r\n99 70\r\n86 29\r\n", "output": ["NO"]}, {"input": "22 21\r\n73 65\r\n92 35\r\n", "output": ["NO"]}, {"input": "90 75\r\n38 2\r\n100 61\r\n", "output": ["NO"]}, {"input": "62 70\r\n48 12\r\n75 51\r\n", "output": ["NO"]}, {"input": "23 17\r\n34 71\r\n98 34\r\n", "output": ["NO"]}, {"input": "95 72\r\n65 31\r\n89 50\r\n", "output": ["NO"]}, {"input": "68 19\r\n39 35\r\n95 65\r\n", "output": ["NO"]}, {"input": "28 65\r\n66 27\r\n5 72\r\n", "output": ["NO"]}, {"input": "100 16\r\n41 76\r\n24 15\r\n", "output": ["NO"]}, {"input": "21 63\r\n28 73\r\n60 72\r\n", "output": ["NO"]}, {"input": "85 18\r\n37 84\r\n35 62\r\n", "output": ["NO"]}, {"input": "58 64\r\n98 30\r\n61 52\r\n", "output": ["NO"]}, {"input": "32 891\r\n573 351\r\n648 892\r\n", "output": ["NO"]}, {"input": "796 846\r\n602 302\r\n600 698\r\n", "output": ["NO"]}, {"input": "665 289\r\n608 360\r\n275 640\r\n", "output": ["NO"]}, {"input": "237 595\r\n318 161\r\n302 838\r\n", "output": ["NO"]}, {"input": "162 742\r\n465 429\r\n571 29\r\n", "output": ["NO"]}, {"input": "222 889\r\n491 923\r\n76 195\r\n", "output": ["NO"]}, {"input": "794 140\r\n166 622\r\n378 905\r\n", "output": ["NO"]}, {"input": "663 287\r\n193 212\r\n615 787\r\n", "output": ["NO"]}, {"input": "427 433\r\n621 441\r\n868 558\r\n", "output": ["NO"]}, {"input": "1000 388\r\n332 49\r\n735 699\r\n", "output": ["NO"]}, {"input": "868 535\r\n409 690\r\n761 104\r\n", "output": ["YES"]}, {"input": "632 786\r\n710 208\r\n436 290\r\n", "output": ["YES"]}, {"input": "501 932\r\n463 636\r\n363 918\r\n", "output": ["NO"]}, {"input": "73 79\r\n626 483\r\n924 517\r\n", "output": ["NO"]}, {"input": "190 34\r\n653 163\r\n634 314\r\n", "output": ["NO"]}, {"input": "2 4\r\n1 3\r\n1 4\r\n", "output": ["YES"]}, {"input": "3 10\r\n1 1\r\n1 11\r\n", "output": ["NO"]}, {"input": "5 4\r\n3 3\r\n2 6\r\n", "output": ["NO"]}, {"input": "3 4\r\n1 6\r\n2 3\r\n", "output": ["NO"]}]
100
100
100
[{'input': '9 10\r\n4 8\r\n5 6\r\n', 'output': ['YES']}, {'input': '3 3\r\n3 4\r\n3 6\r\n', 'output': ['NO']}, {'input': '7 10\r\n7 5\r\n1 7\r\n', 'output': ['YES']}, {'input': '78 86\r\n63 8\r\n9 4\r\n', 'output': ['YES']}, {'input': '9 7\r\n5 2\r\n4 1\r\n', 'output': ['YES']}]
[{'input': '7 3\r\n7 8\r\n1 5\r\n', 'output': ['NO']}, {'input': '993 1000\r\n201 307\r\n692 758\r\n', 'output': ['YES']}, {'input': '663 287\r\n193 212\r\n615 787\r\n', 'output': ['NO']}, {'input': '8 7\r\n1 7\r\n3 2\r\n', 'output': ['YES']}, {'input': '954 576\r\n324 433\r\n247 911\r\n', 'output': ['YES']}]
[{'input': '965 1000\r\n606 895\r\n533 394\r\n', 'output': ['YES']}, {'input': '32 891\r\n573 351\r\n648 892\r\n', 'output': ['NO']}, {'input': '9 7\r\n5 2\r\n4 1\r\n', 'output': ['YES']}, {'input': '91 100\r\n61 40\r\n60 88\r\n', 'output': ['YES']}, {'input': '162 742\r\n465 429\r\n571 29\r\n', 'output': ['NO']}]
[{'input': '8 7\r\n1 7\r\n3 2\r\n', 'output': ['YES']}, {'input': '95 72\r\n65 31\r\n89 50\r\n', 'output': ['NO']}, {'input': '99 100\r\n99 72\r\n68 1\r\n', 'output': ['YES']}, {'input': '32 891\r\n573 351\r\n648 892\r\n', 'output': ['NO']}, {'input': '58 64\r\n98 30\r\n61 52\r\n', 'output': ['NO']}]
[{'input': '97 100\r\n95 40\r\n70 60\r\n', 'output': ['YES']}, {'input': '868 535\r\n409 690\r\n761 104\r\n', 'output': ['YES']}, {'input': '100 100\r\n6 45\r\n97 54\r\n', 'output': ['YES']}, {'input': '10 10\r\n10 5\r\n4 3\r\n', 'output': ['YES']}, {'input': '501 932\r\n463 636\r\n363 918\r\n', 'output': ['NO']}]
100
100
100
100
100
100
100
100
100
100
76.47
76.47
73.53
88.24
70.59
216
100
100
77.06
["14 34", "50 34", "387420489 225159023", "5 5"]
The first line contains two integers a and c (0 ≀ a, c ≀ 109). Both numbers are written in decimal notation.
5fb635d52ddccf6a4d5103805da02a88
// ~/BAU/ACM-ICPC/Teams/A++/BlackBurn95 // ~/sudo apt-get Accpeted import java.io.*; import java.util.*; import java.math.*; import static java.lang.Math.*; import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.Double.parseDouble; import static java.lang.String.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringBuilder out = new StringBuilder(); StringTokenizer tk; tk = new StringTokenizer(in.readLine()); BigInteger a = new BigInteger(tk.nextToken()),c = new BigInteger(tk.nextToken()); String A = a.toString(3),C = c.toString(3) ; if(A.length() < C.length()) { String tmp = ""; for(int i=0; i<C.length()-A.length(); i++) tmp += "0"; A = tmp+A; } else if(A.length() > C.length()) { String tmp = ""; for(int i=0; i<A.length()-C.length(); i++) tmp += "0"; C = tmp+C; } char [] B = new char[A.length()]; for(int i=0; i<A.length(); i++) B[i] = (char)((C.charAt(i)-'0'-(A.charAt(i)-'0')+3)%3 + '0'); BigInteger b = new BigInteger(valueOf(B),3); System.out.println(b.toString(10)); } }
["50", "14", "1000000001", "0"]
Java
null
Print the single integer b, such that a tor b = c. If there are several possible numbers b, print the smallest one. You should print the number in decimal notation.
Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the xor operation is performed on this computer (and whether there is anything like it).It turned out that the operation does exist (however, it is called tor) and it works like this. Suppose that we need to calculate the value of the expression a tor b. Both numbers a and b are written in the ternary notation one under the other one (b under a). If they have a different number of digits, then leading zeroes are added to the shorter number until the lengths are the same. Then the numbers are summed together digit by digit. The result of summing each two digits is calculated modulo 3. Note that there is no carry between digits (i. e. during this operation the digits aren't transferred). For example: 1410 tor 5010 = 01123 tor 12123 = 10213 = 3410.Petya wrote numbers a and c on a piece of paper. Help him find such number b, that a tor b = c. If there are several such numbers, print the smallest one.
[{"input": "14 34\r\n", "output": ["50"]}, {"input": "50 34\r\n", "output": ["14"]}, {"input": "387420489 225159023\r\n", "output": ["1000000001"]}, {"input": "5 5\r\n", "output": ["0"]}, {"input": "23476 23875625\r\n", "output": ["23860906"]}, {"input": "11111 10101010\r\n", "output": ["10116146"]}, {"input": "1 23865354\r\n", "output": ["23865356"]}, {"input": "0 0\r\n", "output": ["0"]}, {"input": "2376234 0\r\n", "output": ["4732515"]}, {"input": "1 0\r\n", "output": ["2"]}, {"input": "581130733 0\r\n", "output": ["1162261466"]}, {"input": "581131733 1\r\n", "output": ["1162260467"]}, {"input": "0 1000000000\r\n", "output": ["1000000000"]}, {"input": "1000000000 0\r\n", "output": ["693711461"]}, {"input": "1000000000 100000000\r\n", "output": ["650219958"]}, {"input": "956747697 9487\r\n", "output": ["736688812"]}, {"input": "229485033 8860\r\n", "output": ["308580772"]}, {"input": "5341 813849430\r\n", "output": ["813850920"]}, {"input": "227927516 956217829\r\n", "output": ["872370713"]}, {"input": "390 380875228\r\n", "output": ["380874919"]}, {"input": "336391083 911759145\r\n", "output": ["1135529718"]}, {"input": "154618752 504073566\r\n", "output": ["753527130"]}, {"input": "6436017 645491133\r\n", "output": ["639142839"]}, {"input": "4232 755480607\r\n", "output": ["755485882"]}, {"input": "19079106 69880743\r\n", "output": ["56293527"]}, {"input": "460318555 440850074\r\n", "output": ["25179124"]}, {"input": "227651149 379776728\r\n", "output": ["168088492"]}, {"input": "621847819 8794\r\n", "output": ["1114556841"]}, {"input": "827112516 566664600\r\n", "output": ["908742057"]}, {"input": "460311350 820538776\r\n", "output": ["404875070"]}, {"input": "276659168 241268656\r\n", "output": ["358409486"]}, {"input": "9925 9952\r\n", "output": ["27"]}, {"input": "830218526 438129941\r\n", "output": ["784719357"]}, {"input": "630005197 848951646\r\n", "output": ["754665575"]}, {"input": "123256190 174927955\r\n", "output": ["243699845"]}, {"input": "937475611 769913258\r\n", "output": ["994719535"]}, {"input": "561666539 29904379\r\n", "output": ["1152454076"]}, {"input": "551731805 8515539\r\n", "output": ["1049769112"]}, {"input": "6560 96330685\r\n", "output": ["96330968"]}, {"input": "337894292 55\r\n", "output": ["243175169"]}, {"input": "479225038 396637601\r\n", "output": ["47143216"]}, {"input": "111174087 482024380\r\n", "output": ["430083082"]}, {"input": "785233275 1523\r\n", "output": ["393767834"]}, {"input": "47229813 6200\r\n", "output": ["89081162"]}, {"input": "264662333 6952\r\n", "output": ["141903557"]}, {"input": "523162963 922976263\r\n", "output": ["414184806"]}, {"input": "6347 7416\r\n", "output": ["10549"]}, {"input": "278014879 3453211\r\n", "output": ["171855414"]}, {"input": "991084922 66\r\n", "output": ["690049933"]}, {"input": "929361351 7373\r\n", "output": ["679915097"]}, {"input": "532643581 213098335\r\n", "output": ["842718489"]}, {"input": "69272798 718909239\r\n", "output": ["668771236"]}, {"input": "440760623 316634331\r\n", "output": ["1052493562"]}, {"input": "9001 9662\r\n", "output": ["1390"]}, {"input": "417584836 896784933\r\n", "output": ["481392203"]}, {"input": "640735701 335933492\r\n", "output": ["992169746"]}, {"input": "5440 6647\r\n", "output": ["10711"]}, {"input": "3545 6259\r\n", "output": ["3536"]}, {"input": "847932562 1405\r\n", "output": ["488901051"]}, {"input": "359103580 852\r\n", "output": ["201115550"]}, {"input": "406369748 625641695\r\n", "output": ["221459919"]}, {"input": "345157805 719310676\r\n", "output": ["504894191"]}, {"input": "9150 823789822\r\n", "output": ["823781437"]}, {"input": "8727 702561605\r\n", "output": ["702556127"]}, {"input": "931392186 677650263\r\n", "output": ["923604336"]}, {"input": "976954722 548418041\r\n", "output": ["862925051"]}, {"input": "168971531 697371009\r\n", "output": ["588009082"]}, {"input": "5849 7211\r\n", "output": ["10146"]}, {"input": "934045591 4156\r\n", "output": ["661009836"]}, {"input": "427471963 436868749\r\n", "output": ["67345761"]}, {"input": "702754885 762686553\r\n", "output": ["81198815"]}, {"input": "897312963 177161062\r\n", "output": ["620860447"]}, {"input": "268520356 1999\r\n", "output": ["135088146"]}, {"input": "635318406 289972012\r\n", "output": ["950864476"]}, {"input": "237819544 904440360\r\n", "output": ["857959352"]}, {"input": "44788825 4485\r\n", "output": ["89397617"]}, {"input": "7376 994270908\r\n", "output": ["994283218"]}, {"input": "893244884 654169485\r\n", "output": ["1095395095"]}, {"input": "960725158 342144655\r\n", "output": ["548529624"]}, {"input": "460645829 46697832\r\n", "output": ["792961330"]}, {"input": "8389 172682371\r\n", "output": ["172696203"]}, {"input": "294567098 631452590\r\n", "output": ["745235571"]}, {"input": "5573 8790\r\n", "output": ["13021"]}, {"input": "285938679 907528096\r\n", "output": ["1068058915"]}, {"input": "774578699 101087409\r\n", "output": ["940495066"]}, {"input": "153749013 598457896\r\n", "output": ["444892699"]}, {"input": "364059865 346004232\r\n", "output": ["40934348"]}, {"input": "237924125 573400957\r\n", "output": ["507664538"]}, {"input": "987310001 827978268\r\n", "output": ["275919178"]}, {"input": "922263603 387506683\r\n", "output": ["1064907553"]}, {"input": "5712 384487208\r\n", "output": ["384482225"]}, {"input": "9099 3208\r\n", "output": ["14035"]}, {"input": "948688087 38251290\r\n", "output": ["768385433"]}, {"input": "260153932 138945442\r\n", "output": ["271056231"]}, {"input": "497129325 766959165\r\n", "output": ["276817557"]}, {"input": "783390583 7679\r\n", "output": ["399664540"]}, {"input": "657244587 28654748\r\n", "output": ["921153434"]}, {"input": "455705795 757666961\r\n", "output": ["303798597"]}, {"input": "815932189 211656771\r\n", "output": ["562850021"]}, {"input": "511307975 307916669\r\n", "output": ["1137612240"]}, {"input": "274842194 1000000000\r\n", "output": ["1162261466"]}]
100
100
100
[{'input': '9925 9952\r\n', 'output': ['27']}, {'input': '2376234 0\r\n', 'output': ['4732515']}, {'input': '345157805 719310676\r\n', 'output': ['504894191']}, {'input': '69272798 718909239\r\n', 'output': ['668771236']}, {'input': '561666539 29904379\r\n', 'output': ['1152454076']}]
[{'input': '387420489 225159023\r\n', 'output': ['1000000001']}, {'input': '111174087 482024380\r\n', 'output': ['430083082']}, {'input': '294567098 631452590\r\n', 'output': ['745235571']}, {'input': '702754885 762686553\r\n', 'output': ['81198815']}, {'input': '50 34\r\n', 'output': ['14']}]
[{'input': '455705795 757666961\r\n', 'output': ['303798597']}, {'input': '987310001 827978268\r\n', 'output': ['275919178']}, {'input': '5341 813849430\r\n', 'output': ['813850920']}, {'input': '4232 755480607\r\n', 'output': ['755485882']}, {'input': '1000000000 100000000\r\n', 'output': ['650219958']}]
[{'input': '44788825 4485\r\n', 'output': ['89397617']}, {'input': '5341 813849430\r\n', 'output': ['813850920']}, {'input': '268520356 1999\r\n', 'output': ['135088146']}, {'input': '523162963 922976263\r\n', 'output': ['414184806']}, {'input': '154618752 504073566\r\n', 'output': ['753527130']}]
[{'input': '5440 6647\r\n', 'output': ['10711']}, {'input': '229485033 8860\r\n', 'output': ['308580772']}, {'input': '948688087 38251290\r\n', 'output': ['768385433']}, {'input': '657244587 28654748\r\n', 'output': ['921153434']}, {'input': '285938679 907528096\r\n', 'output': ['1068058915']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
90
217
100
100
98
["4 4\n5 2 4 1", "3 20\n199 41 299"]
The first line contains two integers n and m (1 ≀ n ≀ 35, 1 ≀ m ≀ 109). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109).
d3a8a3e69a55936ee33aedd66e5b7f4a
import java.util.Arrays; import java.util.Scanner; public class Main{ static int[] p = new int[(1<<18) + 10]; static int[] q = new int[(1<<18) + 10]; static int lenp = 0, lenq = 0; static int M = 0; public static void main(String[] args){ Scanner c = new Scanner(System.in); int n = c.nextInt(); int m = c.nextInt(); M = m; int[] nums = new int[n]; for(int i=0;i<n;i++){ nums[i] = c.nextInt() % m; } c.close(); if(m == 1){ System.out.println(0); return; } if(n == 1){ System.out.println(nums[0]); return; } if(n == 2){ int ans = Math.max(nums[0],nums[1]); if(nums[0]+nums[1] < M){ ans = Math.max(ans,nums[0]+nums[1]); } System.out.println(ans); return; } int mid = n >> 1; dfs1(nums,0,mid-1,0); dfs2(nums,mid,n-1,0); // System.out.println(Arrays.toString(p) + "-->" + lenp); // System.out.println(Arrays.toString(q) + "-->" + lenq); Arrays.sort(p,0,lenp); Arrays.sort(q,0,lenq); int i=0, j=lenq-1; int result = p[lenp-1] - M + q[lenq-1]; while(i < lenp){ while((p[i] + q[j]) >= M) j--; result = Math.max(result,p[i]+q[j]); i++; } System.out.println(result); } //ε·¦θΎΉηš„dfs private static void dfs1(int[] nums, int i, int end ,int sum){ if(i == end){ p[lenp++] = sum; p[lenp++] = ((sum+nums[i])%M); return; } dfs1(nums,i+1,end, sum); dfs1(nums,i+1,end, (sum+nums[i])%M); } //ε³θΎΉηš„dfs private static void dfs2(int[] nums, int i, int end ,int sum){ if(i == end){ q[lenq++] = sum; q[lenq++] = ((sum+nums[i])%M); return; } dfs2(nums,i+1,end, sum); dfs2(nums,i+1,end, (sum+nums[i])%M); } }
["3", "19"]
Java
NoteIn the first example you can choose a sequence b = {1, 2}, so the sum is equal to 7 (and that's 3 after taking it modulo 4).In the second example you can choose a sequence b = {3}.
Print the maximum possible value of .
You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≀ b1 &lt; b2 &lt; ... &lt; bk ≀ n) in such a way that the value of is maximized. Chosen sequence can be empty.Print the maximum possible value of .
[{"input": "4 4\r\n5 2 4 1\r\n", "output": ["3"]}, {"input": "3 20\r\n199 41 299\r\n", "output": ["19"]}, {"input": "5 10\r\n47 100 49 2 56\r\n", "output": ["9"]}, {"input": "5 1000\r\n38361 75847 14913 11499 8297\r\n", "output": ["917"]}, {"input": "10 10\r\n48 33 96 77 67 59 35 15 14 86\r\n", "output": ["9"]}, {"input": "10 1000\r\n16140 63909 7177 99953 35627 40994 29288 7324 44476 36738\r\n", "output": ["999"]}, {"input": "30 10\r\n99 44 42 36 43 82 99 99 10 79 97 84 5 78 37 45 87 87 11 11 79 66 47 100 8 50 27 98 32 27\r\n", "output": ["9"]}, {"input": "30 1000\r\n81021 18939 94456 90340 76840 78808 27921 71826 99382 1237 93435 35153 71691 25508 96732 23778 49073 60025 95231 88719 61650 50925 34416 73600 7295 14654 78340 72871 17324 77484\r\n", "output": ["999"]}, {"input": "35 10\r\n86 66 98 91 61 71 14 58 49 92 13 97 13 22 98 83 85 29 85 41 51 16 76 17 75 25 71 10 87 11 9 34 3 6 4\r\n", "output": ["9"]}, {"input": "35 1000\r\n33689 27239 14396 26525 30455 13710 37039 80789 26268 1236 89916 87557 90571 13710 59152 99417 39577 40675 25931 14900 86611 46223 7105 64074 41238 59169 81308 70534 99894 10332 72983 85414 73848 68378 98404\r\n", "output": ["999"]}, {"input": "35 1000000000\r\n723631245 190720106 931659134 503095294 874181352 712517040 800614682 904895364 256863800 39366772 763190862 770183843 774794919 55669976 329106527 513566505 207828535 258356470 816288168 657823769 5223226 865258331 655737365 278677545 880429272 718852999 810522025 229560899 544602508 195068526 878937336 739178504 474601895 54057210 432282541\r\n", "output": ["999999999"]}, {"input": "35 982451653\r\n27540278 680344696 757828533 487257472 581415866 897315944 104006244 109795853 24393319 840585536 643747159 864374693 675946278 27492061 172462571 484550119 801174500 94160579 818984382 53253720 966692115 811281559 154162995 890236127 799613478 611617443 787587569 606421577 91876376 464150101 671199076 108388038 342311910 974681791 862530363\r\n", "output": ["982451652"]}, {"input": "15 982451653\r\n384052103 7482105 882228352 582828798 992251028 892163214 687253903 951043841 277531875 402248542 499362766 919046434 350763964 288775999 982610665\r\n", "output": ["982368704"]}, {"input": "35 1000000000\r\n513 9778 5859 8149 297 7965 7152 917 243 4353 7248 4913 9403 6199 2930 7461 3888 1898 3222 9424 3960 1902 2933 5268 2650 1687 5319 5065 8450 141 4219 2586 2176 1118 9635\r\n", "output": ["158921"]}, {"input": "35 982451653\r\n5253 7912 3641 7428 6138 9613 9059 6352 9070 89 9030 1686 3098 7852 3316 8158 7497 5804 130 6201 235 64 3451 6104 4148 3446 6059 6802 7466 8781 1636 8291 8874 8924 5997\r\n", "output": ["197605"]}, {"input": "15 982451653\r\n7975 7526 1213 2318 209 7815 4153 1853 6651 2880 4535 587 8022 3365 5491\r\n", "output": ["64593"]}, {"input": "35 1730970\r\n141538 131452 93552 3046 119468 8282 166088 33782 36462 25246 178798 81434 180900 15102 175898 157782 155254 166352 60772 75162 102326 104854 181138 58618 123800 54458 157516 20658 25084 155276 194920 16680 15148 188292 88802\r\n", "output": ["1730968"]}, {"input": "35 346194136\r\n89792 283104 58936 184528 194768 253076 304368 140216 220836 69196 274604 68988 300412 242588 25328 183488 81712 374964 377696 317872 146208 147400 346276 14356 90432 347556 35452 119348 311320 126112 113200 98936 189500 363424 320164\r\n", "output": ["6816156"]}, {"input": "35 129822795\r\n379185 168630 1047420 892020 180690 1438200 168330 1328610 933930 936360 1065225 351990 1079190 681510 1336020 814590 365820 1493580 495825 809745 309585 190320 1148640 146790 1008900 365655 947265 1314060 1048770 1463535 1233420 969330 1324530 944130 1457160\r\n", "output": ["29838960"]}, {"input": "35 106920170\r\n36941450 53002950 90488020 66086895 77577045 16147985 26130825 84977690 87374560 59007480 61416705 100977415 43291920 56833000 12676230 50531950 5325005 54745005 105536410 76922230 9031505 121004870 104634495 16271535 55819890 47603815 85830185 65938635 33074335 40289655 889560 19829775 31653510 120671285 37843365\r\n", "output": ["106907815"]}, {"input": "35 200000000\r\n75420000 93400000 70560000 93860000 183600000 143600000 61780000 145000000 99360000 14560000 109280000 22040000 141220000 14360000 55140000 78580000 96940000 62400000 173220000 40420000 139600000 30100000 141640000 64780000 186080000 159220000 137780000 133640000 83560000 51280000 139100000 133020000 99460000 35900000 78980000\r\n", "output": ["199980000"]}, {"input": "4 1\r\n435 124 324 2\r\n", "output": ["0"]}, {"input": "1 12\r\n13\r\n", "output": ["1"]}, {"input": "1 1000000000\r\n1000000000\r\n", "output": ["0"]}, {"input": "7 19\r\n8 1 4 8 8 7 3\r\n", "output": ["18"]}, {"input": "6 7\r\n1 1 1 1 1 6\r\n", "output": ["6"]}, {"input": "3 5\r\n1 2 3\r\n", "output": ["4"]}, {"input": "4 36\r\n22 9 24 27\r\n", "output": ["33"]}, {"input": "2 8\r\n7 1\r\n", "output": ["7"]}, {"input": "2 12\r\n8 7\r\n", "output": ["8"]}, {"input": "4 10\r\n11 31 12 3\r\n", "output": ["7"]}, {"input": "2 8\r\n2 7\r\n", "output": ["7"]}, {"input": "4 19\r\n16 20 19 21\r\n", "output": ["18"]}, {"input": "3 4\r\n9 16 11\r\n", "output": ["3"]}, {"input": "2 3\r\n3 7\r\n", "output": ["1"]}, {"input": "2 20\r\n4 3\r\n", "output": ["7"]}, {"input": "3 299\r\n100 100 200\r\n", "output": ["200"]}]
100
100
100
[{'input': '4 4\r\n5 2 4 1\r\n', 'output': ['3']}, {'input': '35 1000000000\r\n513 9778 5859 8149 297 7965 7152 917 243 4353 7248 4913 9403 6199 2930 7461 3888 1898 3222 9424 3960 1902 2933 5268 2650 1687 5319 5065 8450 141 4219 2586 2176 1118 9635\r\n', 'output': ['158921']}, {'input': '35 346194136\r\n89792 283104 58936 184528 194768 253076 304368 140216 220836 69196 274604 68988 300412 242588 25328 183488 81712 374964 377696 317872 146208 147400 346276 14356 90432 347556 35452 119348 311320 126112 113200 98936 189500 363424 320164\r\n', 'output': ['6816156']}, {'input': '5 10\r\n47 100 49 2 56\r\n', 'output': ['9']}, {'input': '4 10\r\n11 31 12 3\r\n', 'output': ['7']}]
[{'input': '30 1000\r\n81021 18939 94456 90340 76840 78808 27921 71826 99382 1237 93435 35153 71691 25508 96732 23778 49073 60025 95231 88719 61650 50925 34416 73600 7295 14654 78340 72871 17324 77484\r\n', 'output': ['999']}, {'input': '35 106920170\r\n36941450 53002950 90488020 66086895 77577045 16147985 26130825 84977690 87374560 59007480 61416705 100977415 43291920 56833000 12676230 50531950 5325005 54745005 105536410 76922230 9031505 121004870 104634495 16271535 55819890 47603815 85830185 65938635 33074335 40289655 889560 19829775 31653510 120671285 37843365\r\n', 'output': ['106907815']}, {'input': '2 12\r\n8 7\r\n', 'output': ['8']}, {'input': '3 4\r\n9 16 11\r\n', 'output': ['3']}, {'input': '35 1730970\r\n141538 131452 93552 3046 119468 8282 166088 33782 36462 25246 178798 81434 180900 15102 175898 157782 155254 166352 60772 75162 102326 104854 181138 58618 123800 54458 157516 20658 25084 155276 194920 16680 15148 188292 88802\r\n', 'output': ['1730968']}]
[{'input': '6 7\r\n1 1 1 1 1 6\r\n', 'output': ['6']}, {'input': '35 982451653\r\n5253 7912 3641 7428 6138 9613 9059 6352 9070 89 9030 1686 3098 7852 3316 8158 7497 5804 130 6201 235 64 3451 6104 4148 3446 6059 6802 7466 8781 1636 8291 8874 8924 5997\r\n', 'output': ['197605']}, {'input': '2 8\r\n2 7\r\n', 'output': ['7']}, {'input': '3 20\r\n199 41 299\r\n', 'output': ['19']}, {'input': '10 10\r\n48 33 96 77 67 59 35 15 14 86\r\n', 'output': ['9']}]
[{'input': '15 982451653\r\n384052103 7482105 882228352 582828798 992251028 892163214 687253903 951043841 277531875 402248542 499362766 919046434 350763964 288775999 982610665\r\n', 'output': ['982368704']}, {'input': '4 4\r\n5 2 4 1\r\n', 'output': ['3']}, {'input': '35 106920170\r\n36941450 53002950 90488020 66086895 77577045 16147985 26130825 84977690 87374560 59007480 61416705 100977415 43291920 56833000 12676230 50531950 5325005 54745005 105536410 76922230 9031505 121004870 104634495 16271535 55819890 47603815 85830185 65938635 33074335 40289655 889560 19829775 31653510 120671285 37843365\r\n', 'output': ['106907815']}, {'input': '3 20\r\n199 41 299\r\n', 'output': ['19']}, {'input': '1 1000000000\r\n1000000000\r\n', 'output': ['0']}]
[{'input': '5 10\r\n47 100 49 2 56\r\n', 'output': ['9']}, {'input': '15 982451653\r\n7975 7526 1213 2318 209 7815 4153 1853 6651 2880 4535 587 8022 3365 5491\r\n', 'output': ['64593']}, {'input': '30 1000\r\n81021 18939 94456 90340 76840 78808 27921 71826 99382 1237 93435 35153 71691 25508 96732 23778 49073 60025 95231 88719 61650 50925 34416 73600 7295 14654 78340 72871 17324 77484\r\n', 'output': ['999']}, {'input': '30 10\r\n99 44 42 36 43 82 99 99 10 79 97 84 5 78 37 45 87 87 11 11 79 66 47 100 8 50 27 98 32 27\r\n', 'output': ['9']}, {'input': '35 982451653\r\n5253 7912 3641 7428 6138 9613 9059 6352 9070 89 9030 1686 3098 7852 3316 8158 7497 5804 130 6201 235 64 3451 6104 4148 3446 6059 6802 7466 8781 1636 8291 8874 8924 5997\r\n', 'output': ['197605']}]
100
100
100
100
100
82.69
90.38
90.38
86.54
82.69
72.22
83.33
83.33
77.78
72.22
218
100
86.536
77.776
["40047", "7747774", "1000000000000000000"]
The only line contains an integer n (1 ≀ n ≀ 1018). Please do not use the %lld specificator to read or write 64-bit numbers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator.
33b73fd9e7f19894ea08e98b790d07f1
import java.util.Scanner; public class test3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); long n = input.nextLong(); if(check(n) == 7 || check(n) == 4) System.out.println("YES"); else System.out.println("NO"); } public static int check(long n){ int digits = 0; String m = Long.toString(n); for(int i = 0; i < m.length(); i++){ if(n % 10 == 4 || n % 10 == 7){ digits++; } n = n / 10; } return digits; } }
["NO", "YES", "NO"]
Java
NoteIn the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".In the third sample there are no lucky digits, so the answer is "NO".
Print on the single line "YES" if n is a nearly lucky number. Otherwise, print "NO" (without the quotes).
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number n is a nearly lucky number.
[{"input": "40047\r\n", "output": ["NO"]}, {"input": "7747774\r\n", "output": ["YES"]}, {"input": "1000000000000000000\r\n", "output": ["NO"]}, {"input": "7\r\n", "output": ["NO"]}, {"input": "4\r\n", "output": ["NO"]}, {"input": "474404774\r\n", "output": ["NO"]}, {"input": "4744000695826\r\n", "output": ["YES"]}, {"input": "10000000004744744\r\n", "output": ["YES"]}, {"input": "446486416781684178\r\n", "output": ["YES"]}, {"input": "999999999\r\n", "output": ["NO"]}, {"input": "7777\r\n", "output": ["YES"]}, {"input": "87414417444\r\n", "output": ["NO"]}, {"input": "111222333444555667\r\n", "output": ["YES"]}, {"input": "1\r\n", "output": ["NO"]}, {"input": "4700\r\n", "output": ["NO"]}, {"input": "3794555488744477\r\n", "output": ["NO"]}, {"input": "444444444444444444\r\n", "output": ["NO"]}, {"input": "474447447774444774\r\n", "output": ["NO"]}, {"input": "777777777777777\r\n", "output": ["NO"]}, {"input": "34777745021000000\r\n", "output": ["NO"]}, {"input": "963\r\n", "output": ["NO"]}, {"input": "855474448854788540\r\n", "output": ["NO"]}, {"input": "999999999999994744\r\n", "output": ["YES"]}, {"input": "400000000474\r\n", "output": ["YES"]}, {"input": "123456789123456789\r\n", "output": ["YES"]}, {"input": "740577777584945874\r\n", "output": ["NO"]}, {"input": "7777777\r\n", "output": ["YES"]}, {"input": "4444000111222333\r\n", "output": ["YES"]}, {"input": "9847745885202111\r\n", "output": ["YES"]}, {"input": "123456000000\r\n", "output": ["NO"]}, {"input": "4744447444444\r\n", "output": ["NO"]}, {"input": "7477\r\n", "output": ["YES"]}, {"input": "4747477\r\n", "output": ["YES"]}, {"input": "777777777444444444\r\n", "output": ["NO"]}]
100
100
100
[{'input': '999999999999994744\r\n', 'output': ['YES']}, {'input': '474447447774444774\r\n', 'output': ['NO']}, {'input': '1\r\n', 'output': ['NO']}, {'input': '777777777444444444\r\n', 'output': ['NO']}, {'input': '444444444444444444\r\n', 'output': ['NO']}]
[{'input': '777777777444444444\r\n', 'output': ['NO']}, {'input': '40047\r\n', 'output': ['NO']}, {'input': '9847745885202111\r\n', 'output': ['YES']}, {'input': '4\r\n', 'output': ['NO']}, {'input': '1\r\n', 'output': ['NO']}]
[{'input': '7747774\r\n', 'output': ['YES']}, {'input': '400000000474\r\n', 'output': ['YES']}, {'input': '9847745885202111\r\n', 'output': ['YES']}, {'input': '999999999999994744\r\n', 'output': ['YES']}, {'input': '963\r\n', 'output': ['NO']}]
[{'input': '123456789123456789\r\n', 'output': ['YES']}, {'input': '474447447774444774\r\n', 'output': ['NO']}, {'input': '87414417444\r\n', 'output': ['NO']}, {'input': '4700\r\n', 'output': ['NO']}, {'input': '855474448854788540\r\n', 'output': ['NO']}]
[{'input': '9847745885202111\r\n', 'output': ['YES']}, {'input': '999999999\r\n', 'output': ['NO']}, {'input': '400000000474\r\n', 'output': ['YES']}, {'input': '474447447774444774\r\n', 'output': ['NO']}, {'input': '87414417444\r\n', 'output': ['NO']}]
100
100
100
100
100
100
100
100
100
100
90
90
100
90
90
219
100
100
92
["10\nrocesfedoc", "16\nplmaetwoxesisiht", "1\nz"]
The first line of input consists of a single integer $$$n$$$ ($$$1 \le n \le 100$$$) β€” the length of the string $$$t$$$. The second line of input consists of the string $$$t$$$. The length of $$$t$$$ is $$$n$$$, and it consists only of lowercase Latin letters.
1b0b2ee44c63cb0634cb63f2ad65cdd3
import java.util.Scanner; public class RevEncrypt { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(), i, j; String t = in.next(), s = ""; in.close(); for (i = 2; i <= n; i++) if (n % i == 0) { for (j = i - 1; j >= 0; j--) s += t.charAt(j); s += t.substring(i); t = s; s = ""; } System.out.println(t); } }
["codeforces", "thisisexampletwo", "z"]
Java
NoteThe first example is described in the problem statement.
Print a string $$$s$$$ such that the above algorithm results in $$$t$$$.
A string $$$s$$$ of length $$$n$$$ can be encrypted by the following algorithm: iterate over all divisors of $$$n$$$ in decreasing order (i.e. from $$$n$$$ to $$$1$$$), for each divisor $$$d$$$, reverse the substring $$$s[1 \dots d]$$$ (i.e. the substring which starts at position $$$1$$$ and ends at position $$$d$$$). For example, the above algorithm applied to the string $$$s$$$="codeforces" leads to the following changes: "codeforces" $$$\to$$$ "secrofedoc" $$$\to$$$ "orcesfedoc" $$$\to$$$ "rocesfedoc" $$$\to$$$ "rocesfedoc" (obviously, the last reverse operation doesn't change the string because $$$d=1$$$).You are given the encrypted string $$$t$$$. Your task is to decrypt this string, i.e., to find a string $$$s$$$ such that the above algorithm results in string $$$t$$$. It can be proven that this string $$$s$$$ always exists and is unique.
[{"input": "10\r\nrocesfedoc\r\n", "output": ["codeforces"]}, {"input": "16\r\nplmaetwoxesisiht\r\n", "output": ["thisisexampletwo"]}, {"input": "1\r\nz\r\n", "output": ["z"]}, {"input": "2\r\nir\r\n", "output": ["ri"]}, {"input": "3\r\nilj\r\n", "output": ["jli"]}, {"input": "4\r\njfyy\r\n", "output": ["yyjf"]}, {"input": "6\r\nkrdych\r\n", "output": ["hcyrkd"]}, {"input": "60\r\nfnebsopcvmlaoecpzmakqigyuutueuozjxutlwwiochekmhjgwxsgfbcrpqj\r\n", "output": ["jqprcbfgsxwgjhmkehcoiwwltuxjzokamzpalobnfespcvmoecqigyuutueu"]}, {"input": "64\r\nhnlzzhrvqnldswxfsrowfhmyzbxtyoxhogudasgywxycyhzgiseerbislcncvnwy\r\n", "output": ["ywnvcnclsibreesigzhycyxwygsadugofxwsdlnqzlhnzhrvsrowfhmyzbxtyoxh"]}, {"input": "97\r\nqnqrmdhmbubaijtwsecbidqouhlecladwgwcuxbigckrfzasnbfbslukoayhcgquuacygakhxoubibxtqkpyyhzjipylujgrc\r\n", "output": ["crgjulypijzhyypkqtxbibuoxhkagycauuqgchyaokulsbfbnsazfrkcgibxucwgwdalcelhuoqdibceswtjiabubmhdmrqnq"]}, {"input": "100\r\nedykhvzcntljuuoqghptioetqnfllwekzohiuaxelgecabvsbibgqodqxvyfkbyjwtgbyhvssntinkwsinwsmalusiwnjmtcoovf\r\n", "output": ["fvooctmjnwisulamswniswknitnssvhybgtwjybkfyvxqdoqgbqteoitnczvkyedhljuuoqghptnfllwekzohiuaxelgecabvsbi"]}, {"input": "96\r\nqtbcksuvxonzbkokhqlgkrvimzqmqnrvqlihrmksldyydacbtckfphenxszcnzhfjmpeykrvshgiboivkvabhrpphgavvprz\r\n", "output": ["zrpvvaghpprhbavkviobighsvrkyepmjfhznczsxnehpfkctvrnqmqzmkokbvuctqbksxonzhqlgkrviqlihrmksldyydacb"]}, {"input": "90\r\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm\r\n", "output": ["mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"]}, {"input": "89\r\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\r\n", "output": ["wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"]}, {"input": "99\r\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\r\n", "output": ["qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"]}, {"input": "100\r\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\r\n", "output": ["oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"]}, {"input": "60\r\nwwwwwxwwwwwwfhwwhwwwwwwawwwwwwwwwwwwwnwwwwwwwwwwwwwwwwwwwwww\r\n", "output": ["wwwwwwwwwwwwwwwwwwwwwwnwwwwwwwwwwhwwwxwwwwwwwwwfhwwwwawwwwww"]}, {"input": "90\r\ncccchccccccccccccccccccccccccccwcccccccccgcccccchccccccccccccccccccccccxccccccncccccccuccc\r\n", "output": ["cccucccccccnccccccxcccccccccccccccccccccchccccccccccccccccccccccchccccccccccwcccccccccgccc"]}, {"input": "97\r\nfwffffffffffffffffffffffffrffffffffffffffzfffffffffffffffftfcfffffffqffffffffffffffffffffffyfffff\r\n", "output": ["fffffyffffffffffffffffffffffqfffffffcftffffffffffffffffzffffffffffffffrffffffffffffffffffffffffwf"]}, {"input": "100\r\ndjjjjjjjjjjgjjjjjjjjjjjjjjsvjjjjjjjjjjmjjjjjjjjjjjjjajjjjjjajjjjjjrjjjjjjjjjjjjrjjtjjjjjjjjjjjjjojjj\r\n", "output": ["jjjojjjjjjjjjjjjjtjjrjjjjjjjjjjjjrjjjjjjajjjjjjajjjjjjjjjjjjjjdjjjgjjjjjjjjjsvjjjjjjjjjjmjjjjjjjjjjj"]}]
100
100
100
[{'input': '16\r\nplmaetwoxesisiht\r\n', 'output': ['thisisexampletwo']}, {'input': '90\r\ncccchccccccccccccccccccccccccccwcccccccccgcccccchccccccccccccccccccccccxccccccncccccccuccc\r\n', 'output': ['cccucccccccnccccccxcccccccccccccccccccccchccccccccccccccccccccccchccccccccccwcccccccccgccc']}, {'input': '89\r\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\r\n', 'output': ['wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww']}, {'input': '60\r\nwwwwwxwwwwwwfhwwhwwwwwwawwwwwwwwwwwwwnwwwwwwwwwwwwwwwwwwwwww\r\n', 'output': ['wwwwwwwwwwwwwwwwwwwwwwnwwwwwwwwwwhwwwxwwwwwwwwwfhwwwwawwwwww']}, {'input': '2\r\nir\r\n', 'output': ['ri']}]
[{'input': '4\r\njfyy\r\n', 'output': ['yyjf']}, {'input': '16\r\nplmaetwoxesisiht\r\n', 'output': ['thisisexampletwo']}, {'input': '90\r\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm\r\n', 'output': ['mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm']}, {'input': '89\r\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\r\n', 'output': ['wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww']}, {'input': '90\r\ncccchccccccccccccccccccccccccccwcccccccccgcccccchccccccccccccccccccccccxccccccncccccccuccc\r\n', 'output': ['cccucccccccnccccccxcccccccccccccccccccccchccccccccccccccccccccccchccccccccccwcccccccccgccc']}]
[{'input': '64\r\nhnlzzhrvqnldswxfsrowfhmyzbxtyoxhogudasgywxycyhzgiseerbislcncvnwy\r\n', 'output': ['ywnvcnclsibreesigzhycyxwygsadugofxwsdlnqzlhnzhrvsrowfhmyzbxtyoxh']}, {'input': '99\r\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\r\n', 'output': ['qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq']}, {'input': '6\r\nkrdych\r\n', 'output': ['hcyrkd']}, {'input': '97\r\nqnqrmdhmbubaijtwsecbidqouhlecladwgwcuxbigckrfzasnbfbslukoayhcgquuacygakhxoubibxtqkpyyhzjipylujgrc\r\n', 'output': ['crgjulypijzhyypkqtxbibuoxhkagycauuqgchyaokulsbfbnsazfrkcgibxucwgwdalcelhuoqdibceswtjiabubmhdmrqnq']}, {'input': '90\r\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm\r\n', 'output': ['mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm']}]
[{'input': '100\r\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\r\n', 'output': ['oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo']}, {'input': '100\r\ndjjjjjjjjjjgjjjjjjjjjjjjjjsvjjjjjjjjjjmjjjjjjjjjjjjjajjjjjjajjjjjjrjjjjjjjjjjjjrjjtjjjjjjjjjjjjjojjj\r\n', 'output': ['jjjojjjjjjjjjjjjjtjjrjjjjjjjjjjjjrjjjjjjajjjjjjajjjjjjjjjjjjjjdjjjgjjjjjjjjjsvjjjjjjjjjjmjjjjjjjjjjj']}, {'input': '90\r\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm\r\n', 'output': ['mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm']}, {'input': '90\r\ncccchccccccccccccccccccccccccccwcccccccccgcccccchccccccccccccccccccccccxccccccncccccccuccc\r\n', 'output': ['cccucccccccnccccccxcccccccccccccccccccccchccccccccccccccccccccccchccccccccccwcccccccccgccc']}, {'input': '100\r\nedykhvzcntljuuoqghptioetqnfllwekzohiuaxelgecabvsbibgqodqxvyfkbyjwtgbyhvssntinkwsinwsmalusiwnjmtcoovf\r\n', 'output': ['fvooctmjnwisulamswniswknitnssvhybgtwjybkfyvxqdoqgbqteoitnczvkyedhljuuoqghptnfllwekzohiuaxelgecabvsbi']}]
[{'input': '89\r\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\r\n', 'output': ['wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww']}, {'input': '99\r\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\r\n', 'output': ['qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq']}, {'input': '16\r\nplmaetwoxesisiht\r\n', 'output': ['thisisexampletwo']}, {'input': '64\r\nhnlzzhrvqnldswxfsrowfhmyzbxtyoxhogudasgywxycyhzgiseerbislcncvnwy\r\n', 'output': ['ywnvcnclsibreesigzhycyxwygsadugofxwsdlnqzlhnzhrvsrowfhmyzbxtyoxh']}, {'input': '6\r\nkrdych\r\n', 'output': ['hcyrkd']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
220
100
100
100
["0 0 0 0 9\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n7 0 0 0 0", "0 43 21 18 2\n3 0 21 11 65\n5 2 0 1 4\n54 62 12 0 99\n87 64 81 33 0"]
The input consists of five lines, each line contains five space-separated integers: the j-th number in the i-th line shows gij (0 ≀ gij ≀ 105). It is guaranteed that gii = 0 for all i. Assume that the students are numbered from 1 to 5.
be6d4df20e9a48d183dd8f34531df246
import java.io.*; import java.math.BigInteger; import java.util.*; public class Temp3 { public static void main(String[] args) throws Throwable { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int[][] arr = new int[5][5]; for (int i = 0; i < arr.length; i++) { StringTokenizer st = new StringTokenizer(br.readLine()); for (int j = 0; j < arr.length; j++) { arr[i][j] = Integer.parseInt(st.nextToken()); } } long ans = 0; for (int a = 0; a < 5; a++) { for (int b = 0; b < 5; b++) { if(b==a ) continue; for (int c = 0; c < 5; c++) { if(c==a || c==b ) continue; for (int d = 0; d < 5; d++) { if(d==a || d==b || d==c ) continue; for (int e = 0; e < 5; e++) { if(e==a || e==b || e==c || e==d ) continue; long cur = arr[a][b] + arr[b][a] + arr[c][d] + arr[d][c]; cur+= arr[b][c] + arr[c][b] + arr[d][e] + arr[e][d]; cur+= arr[d][c] + arr[c][d]; cur+= arr[e][d] + arr[d][e]; ans = Math.max(ans, cur); } } } } } System.out.println(ans); } }
["32", "620"]
Java
NoteIn the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals:(g23 + g32 + g15 + g51) + (g13 + g31 + g54 + g45) + (g15 + g51) + (g54 + g45) = 32.
Print a single integer β€” the maximum possible total happiness of the students.
Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks. There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower.Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the (2i - 1)-th man in the line (for the current moment) talks with the (2i)-th one. Let's look at this process in more detail. Let's number the people from 1 to 5. Let's assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn't talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn't talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5 enters the shower, and then 4 enters the shower.We know that if students i and j talk, then the i-th student's happiness increases by gij and the j-th student's happiness increases by gji. Your task is to find such initial order of students in the line that the total happiness of all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower.
[{"input": "0 0 0 0 9\r\n0 0 0 0 0\r\n0 0 0 0 0\r\n0 0 0 0 0\r\n7 0 0 0 0\r\n", "output": ["32"]}, {"input": "0 43 21 18 2\r\n3 0 21 11 65\r\n5 2 0 1 4\r\n54 62 12 0 99\r\n87 64 81 33 0\r\n", "output": ["620"]}, {"input": "0 4 2 4 9\r\n6 0 2 5 0\r\n2 5 0 6 3\r\n6 3 3 0 10\r\n0 3 1 3 0\r\n", "output": ["63"]}, {"input": "0 65 90 2 32\r\n69 0 9 97 67\r\n77 97 0 16 84\r\n18 50 94 0 63\r\n69 12 82 16 0\r\n", "output": ["947"]}, {"input": "0 70 10 0 0\r\n70 0 50 90 0\r\n10 50 0 80 0\r\n0 90 80 0 100\r\n0 0 0 100 0\r\n", "output": ["960"]}, {"input": "0 711 647 743 841\r\n29 0 109 38 682\r\n329 393 0 212 512\r\n108 56 133 0 579\r\n247 92 933 164 0\r\n", "output": ["6265"]}, {"input": "0 9699 6962 6645 7790\r\n9280 0 6215 8661 6241\r\n2295 7817 0 7373 9681\r\n693 6298 1381 0 4633\r\n7626 3761 694 4073 0\r\n", "output": ["93667"]}, {"input": "0 90479 71577 33797 88848\r\n45771 0 96799 78707 72708\r\n5660 26421 0 10991 22757\r\n78919 24804 90645 0 48665\r\n92787 43671 38727 17302 0\r\n", "output": ["860626"]}, {"input": "0 61256 85109 94834 32902\r\n55269 0 67023 1310 85444\r\n23497 84998 0 55618 80701\r\n30324 1713 62127 0 55041\r\n47799 52448 40072 28971 0\r\n", "output": ["822729"]}, {"input": "0 7686 20401 55871 74372\r\n29526 0 15486 2152 84700\r\n27854 30093 0 62418 14297\r\n43903 76036 36194 0 50522\r\n29743 9945 38831 75882 0\r\n", "output": ["605229"]}, {"input": "0 5271 65319 64976 13673\r\n80352 0 41169 66004 47397\r\n33603 44407 0 55079 36122\r\n4277 9834 92810 0 80276\r\n1391 1145 92132 51595 0\r\n", "output": ["744065"]}, {"input": "0 75763 33154 32389 12897\r\n5095 0 6375 61517 46063\r\n35354 82789 0 24814 310\r\n37373 45993 61355 0 76865\r\n24383 84258 71887 71430 0\r\n", "output": ["714904"]}, {"input": "0 89296 32018 98206 22395\r\n15733 0 69391 74253 50419\r\n80450 89589 0 20583 51716\r\n38629 93129 67730 0 69703\r\n44054 83018 21382 64478 0\r\n", "output": ["874574"]}, {"input": "0 14675 94714 27735 99544\r\n45584 0 43621 94734 66110\r\n72838 45781 0 47389 99394\r\n75870 95368 33311 0 63379\r\n21974 70489 53797 23747 0\r\n", "output": ["974145"]}, {"input": "0 9994 14841 63916 37926\r\n80090 0 90258 96988 18217\r\n674 69024 0 17641 54436\r\n35046 21380 14213 0 67188\r\n49360 19086 68337 70856 0\r\n", "output": ["801116"]}, {"input": "0 28287 52158 19163 10096\r\n93438 0 19260 88892 12429\r\n22525 60034 0 78163 18126\r\n11594 8506 56066 0 17732\r\n59561 82486 23419 57406 0\r\n", "output": ["654636"]}, {"input": "0 35310 30842 63415 91022\r\n30553 0 25001 38944 92355\r\n48906 33736 0 96880 80893\r\n80507 79652 45299 0 38212\r\n72488 77736 19203 56436 0\r\n", "output": ["953303"]}, {"input": "0 42865 18485 37168 43099\r\n41476 0 58754 73410 51163\r\n76093 44493 0 51611 93773\r\n87223 80979 58422 0 63327\r\n51215 63346 84797 52809 0\r\n", "output": ["864938"]}, {"input": "0 63580 51022 25392 84354\r\n39316 0 17516 63801 92440\r\n5447 2074 0 11758 4772\r\n26329 55642 62442 0 75330\r\n6164 83831 10741 15214 0\r\n", "output": ["738415"]}, {"input": "0 0 0 0 0\r\n0 0 0 0 0\r\n0 0 0 0 0\r\n0 0 0 0 0\r\n0 0 0 0 0\r\n", "output": ["0"]}, {"input": "0 1 1 1 0\r\n1 0 0 1 0\r\n0 1 0 0 1\r\n1 1 0 0 0\r\n1 0 0 1 0\r\n", "output": ["10"]}, {"input": "0 3 6 9 8\r\n2 0 8 7 7\r\n4 6 0 6 1\r\n9 0 3 0 6\r\n6 5 0 2 0\r\n", "output": ["90"]}, {"input": "0 97 67 53 6\r\n96 0 100 57 17\r\n27 79 0 66 16\r\n89 46 71 0 28\r\n27 26 27 12 0\r\n", "output": ["926"]}, {"input": "0 670 904 349 56\r\n446 0 941 590 993\r\n654 888 0 423 752\r\n16 424 837 0 433\r\n418 655 459 897 0\r\n", "output": ["9752"]}, {"input": "0 4109 129 1340 7124\r\n7815 0 8991 2828 909\r\n5634 799 0 5691 9604\r\n3261 7013 8062 0 5160\r\n2433 4742 694 4786 0\r\n", "output": ["69867"]}, {"input": "0 14299 32984 96001 30445\r\n77723 0 75669 14101 55389\r\n30897 9956 0 52675 29987\r\n36518 90812 92955 0 64020\r\n91242 50085 86272 62454 0\r\n", "output": ["783459"]}, {"input": "0 46183 30304 63049 13191\r\n37244 0 23076 12594 43885\r\n98470 1788 0 37335 7775\r\n33822 50804 27921 0 56734\r\n38313 67579 77714 46687 0\r\n", "output": ["666175"]}, {"input": "0 39037 87960 13497 38526\r\n5528 0 44220 23338 92550\r\n87887 86544 0 30269 82845\r\n24590 60325 90979 0 20186\r\n64959 69875 93564 68355 0\r\n", "output": ["950600"]}, {"input": "0 27677 88187 87515 82582\r\n98177 0 22852 28214 99977\r\n52662 14066 0 79760 68188\r\n56883 30561 91843 0 79777\r\n12461 14821 29284 54372 0\r\n", "output": ["878207"]}, {"input": "0 37330 91942 67667 42061\r\n1978 0 84218 17 10834\r\n11303 6279 0 48597 26591\r\n82688 5437 34983 0 92556\r\n79574 32231 23167 16637 0\r\n", "output": ["718057"]}, {"input": "0 3 0 0 0\r\n3 0 2 0 0\r\n0 2 0 1 0\r\n0 0 1 0 1\r\n0 0 0 1 0\r\n", "output": ["24"]}]
100
100
100
[{'input': '0 70 10 0 0\r\n70 0 50 90 0\r\n10 50 0 80 0\r\n0 90 80 0 100\r\n0 0 0 100 0\r\n', 'output': ['960']}, {'input': '0 43 21 18 2\r\n3 0 21 11 65\r\n5 2 0 1 4\r\n54 62 12 0 99\r\n87 64 81 33 0\r\n', 'output': ['620']}, {'input': '0 5271 65319 64976 13673\r\n80352 0 41169 66004 47397\r\n33603 44407 0 55079 36122\r\n4277 9834 92810 0 80276\r\n1391 1145 92132 51595 0\r\n', 'output': ['744065']}, {'input': '0 3 0 0 0\r\n3 0 2 0 0\r\n0 2 0 1 0\r\n0 0 1 0 1\r\n0 0 0 1 0\r\n', 'output': ['24']}, {'input': '0 0 0 0 9\r\n0 0 0 0 0\r\n0 0 0 0 0\r\n0 0 0 0 0\r\n7 0 0 0 0\r\n', 'output': ['32']}]
[{'input': '0 1 1 1 0\r\n1 0 0 1 0\r\n0 1 0 0 1\r\n1 1 0 0 0\r\n1 0 0 1 0\r\n', 'output': ['10']}, {'input': '0 27677 88187 87515 82582\r\n98177 0 22852 28214 99977\r\n52662 14066 0 79760 68188\r\n56883 30561 91843 0 79777\r\n12461 14821 29284 54372 0\r\n', 'output': ['878207']}, {'input': '0 28287 52158 19163 10096\r\n93438 0 19260 88892 12429\r\n22525 60034 0 78163 18126\r\n11594 8506 56066 0 17732\r\n59561 82486 23419 57406 0\r\n', 'output': ['654636']}, {'input': '0 65 90 2 32\r\n69 0 9 97 67\r\n77 97 0 16 84\r\n18 50 94 0 63\r\n69 12 82 16 0\r\n', 'output': ['947']}, {'input': '0 70 10 0 0\r\n70 0 50 90 0\r\n10 50 0 80 0\r\n0 90 80 0 100\r\n0 0 0 100 0\r\n', 'output': ['960']}]
[{'input': '0 3 0 0 0\r\n3 0 2 0 0\r\n0 2 0 1 0\r\n0 0 1 0 1\r\n0 0 0 1 0\r\n', 'output': ['24']}, {'input': '0 9699 6962 6645 7790\r\n9280 0 6215 8661 6241\r\n2295 7817 0 7373 9681\r\n693 6298 1381 0 4633\r\n7626 3761 694 4073 0\r\n', 'output': ['93667']}, {'input': '0 1 1 1 0\r\n1 0 0 1 0\r\n0 1 0 0 1\r\n1 1 0 0 0\r\n1 0 0 1 0\r\n', 'output': ['10']}, {'input': '0 97 67 53 6\r\n96 0 100 57 17\r\n27 79 0 66 16\r\n89 46 71 0 28\r\n27 26 27 12 0\r\n', 'output': ['926']}, {'input': '0 39037 87960 13497 38526\r\n5528 0 44220 23338 92550\r\n87887 86544 0 30269 82845\r\n24590 60325 90979 0 20186\r\n64959 69875 93564 68355 0\r\n', 'output': ['950600']}]
[{'input': '0 42865 18485 37168 43099\r\n41476 0 58754 73410 51163\r\n76093 44493 0 51611 93773\r\n87223 80979 58422 0 63327\r\n51215 63346 84797 52809 0\r\n', 'output': ['864938']}, {'input': '0 3 6 9 8\r\n2 0 8 7 7\r\n4 6 0 6 1\r\n9 0 3 0 6\r\n6 5 0 2 0\r\n', 'output': ['90']}, {'input': '0 28287 52158 19163 10096\r\n93438 0 19260 88892 12429\r\n22525 60034 0 78163 18126\r\n11594 8506 56066 0 17732\r\n59561 82486 23419 57406 0\r\n', 'output': ['654636']}, {'input': '0 46183 30304 63049 13191\r\n37244 0 23076 12594 43885\r\n98470 1788 0 37335 7775\r\n33822 50804 27921 0 56734\r\n38313 67579 77714 46687 0\r\n', 'output': ['666175']}, {'input': '0 90479 71577 33797 88848\r\n45771 0 96799 78707 72708\r\n5660 26421 0 10991 22757\r\n78919 24804 90645 0 48665\r\n92787 43671 38727 17302 0\r\n', 'output': ['860626']}]
[{'input': '0 3 0 0 0\r\n3 0 2 0 0\r\n0 2 0 1 0\r\n0 0 1 0 1\r\n0 0 0 1 0\r\n', 'output': ['24']}, {'input': '0 9994 14841 63916 37926\r\n80090 0 90258 96988 18217\r\n674 69024 0 17641 54436\r\n35046 21380 14213 0 67188\r\n49360 19086 68337 70856 0\r\n', 'output': ['801116']}, {'input': '0 39037 87960 13497 38526\r\n5528 0 44220 23338 92550\r\n87887 86544 0 30269 82845\r\n24590 60325 90979 0 20186\r\n64959 69875 93564 68355 0\r\n', 'output': ['950600']}, {'input': '0 35310 30842 63415 91022\r\n30553 0 25001 38944 92355\r\n48906 33736 0 96880 80893\r\n80507 79652 45299 0 38212\r\n72488 77736 19203 56436 0\r\n', 'output': ['953303']}, {'input': '0 70 10 0 0\r\n70 0 50 90 0\r\n10 50 0 80 0\r\n0 90 80 0 100\r\n0 0 0 100 0\r\n', 'output': ['960']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
221
100
100
100
["8.549e2", "8.549e3", "0.33e0"]
The first and only line of input contains a single string of form a.deb where a, d and b are integers and e is usual character 'e' (0 ≀ a ≀ 9, 0 ≀ d &lt; 10100, 0 ≀ b ≀ 100)Β β€” the scientific notation of the desired distance value. a and b contain no leading zeros and d contains no trailing zeros (but may be equal to 0). Also, b can not be non-zero if a is zero.
a79358099f08f3ec50c013d47d910eef
import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; /** * Created by kaaveh on 7/29/16. */ public class _697B_ { public static void main(String[] args) throws IOException { char tmp; int num; int zero; ArrayList<Character> data = new ArrayList<>(); kaaveh in = new kaaveh(); System.out.print((char) System.in.read()); System.in.read(); while(true){ tmp = (char) System.in.read(); if (tmp == 'e'){ break; } else { data.add(tmp); } } num = in.kint(); zero =num - data.size(); if (num > data.size()) num = data.size(); for (int i=0; i<num; i++){ System.out.print(data.get(i)); } if ((data.size() - num)!=0 && !(data.size() ==1 && data.get(0)=='0')) System.out.print('.'); if (!(data.size() ==1 && data.get(0)=='0')) for (int i= num; i<data.size(); i++){ System.out.print(data.get(i)); } while (zero > 0){ System.out.print('0'); zero--; } } } class kaaveh { static String kLine(int maxLg) { byte lin[] = new byte[maxLg]; int lg = 0, car = -1; String line = ""; try { while (lg < maxLg) { car = System.in.read(); if ((car < 0) || (car == '\n') || (car == '\r')) break; lin[lg++] += car; } } catch (IOException e) { return (null); } if ((car < 0) && (lg == 0)) return (null); // eof return (new String(lin, 0, lg)); } static String knex(int maxLg) { byte lin[] = new byte[maxLg]; int lg = 0, car = -1; String line = ""; try { while ((car < 0) || (car == '\n') || (car == ' ') || (car == '\t') || (car == '\r')) car = System.in.read(); while (lg < maxLg) { if ((car < 0) || (car == '\n') || (car == ' ') || (car == '\t') || (car == '\r')) break; lin[lg++] += car; car = System.in.read(); } } catch (IOException e) { return (null); } if ((car < 0) && (lg == 0)) return (null); // eof return (new String(lin, 0, lg)); } static int kint() { return Integer.parseInt(knex(11)); } static long kLong() { return Long.parseLong(knex(20)); } static double kdouble() { return Double.parseDouble(knex(100)); } }
["854.9", "8549", "0.33"]
Java
null
Print the only real number x (the desired distance value) in the only line in its decimal notation. Thus if x is an integer, print it's integer value without decimal part and decimal point and without leading zeroes. Otherwise print x in a form of p.q such that p is an integer that have no leading zeroes (but may be equal to zero), and q is an integer that have no trailing zeroes (and may not be equal to zero).
Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate. Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number x is the notation of form AeB, where A is a real number and B is an integer and x = A × 10B is true. In our case A is between 0 and 9 and B is non-negative.Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding.
[{"input": "8.549e2\r\n", "output": ["854.9"]}, {"input": "8.549e3\r\n", "output": ["8549"]}, {"input": "0.33e0\r\n", "output": ["0.33"]}, {"input": "1.31e1\r\n", "output": ["13.1"]}, {"input": "1.038e0\r\n", "output": ["1.038"]}, {"input": "8.25983e5\r\n", "output": ["825983"]}, {"input": "8.77056e6\r\n", "output": ["8770560"]}, {"input": "4.28522890224373996236468418851564462623381500262405e30\r\n", "output": ["4285228902243739962364684188515.64462623381500262405"]}, {"input": "4.09336275522154223604344399571355118601483591618747e85\r\n", "output": ["40933627552215422360434439957135511860148359161874700000000000000000000000000000000000"]}, {"input": "2.0629094807595491132306264747042243928486303384791951220362096240931158821630792563855724946791054152e85\r\n", "output": ["20629094807595491132306264747042243928486303384791951220362096240931158821630792563855.724946791054152"]}, {"input": "0.7e0\r\n", "output": ["0.7"]}, {"input": "0.75e0\r\n", "output": ["0.75"]}, {"input": "0.3299209894804593859495773277850971828150469972132991597085582244596065712639531451e0\r\n", "output": ["0.3299209894804593859495773277850971828150469972132991597085582244596065712639531451"]}, {"input": "0.1438410315232821898580886049593487999249997483354329425897344341660326482795266134253882860655873197e0\r\n", "output": ["0.1438410315232821898580886049593487999249997483354329425897344341660326482795266134253882860655873197"]}, {"input": "1.7282220592677586155528202123627915992640276211396528871e0\r\n", "output": ["1.7282220592677586155528202123627915992640276211396528871"]}, {"input": "1.91641639840522198229453882518758458881136053577016034847369545687354908120008812644841021662133251e89\r\n", "output": ["191641639840522198229453882518758458881136053577016034847369545687354908120008812644841021.662133251"]}, {"input": "7.0e100\r\n", "output": ["70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"]}, {"input": "1.7390193766535948887334396973270576641602486903095355363287177932797263236084900516267835886881779051e100\r\n", "output": ["17390193766535948887334396973270576641602486903095355363287177932797263236084900516267835886881779051"]}, {"input": "4.6329496401734172195e50\r\n", "output": ["463294964017341721950000000000000000000000000000000"]}, {"input": "2.806303180541991592302230754797823269634e39\r\n", "output": ["2806303180541991592302230754797823269634"]}, {"input": "5.8743505652112692964508303637002e64\r\n", "output": ["58743505652112692964508303637002000000000000000000000000000000000"]}, {"input": "6.8778661934058405217475274375560252344373481358834598914724956711e31\r\n", "output": ["68778661934058405217475274375560.252344373481358834598914724956711"]}, {"input": "9.4e100\r\n", "output": ["94000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"]}, {"input": "3.2371070627618799335840070613481911588919091676203766004638236894609230433739617153911544972468224113e50\r\n", "output": ["323710706276187993358400706134819115889190916762037.66004638236894609230433739617153911544972468224113"]}, {"input": "4.8133196117786711780806656271869913331127534865038175322117213586960112955982462632332925275690064929e0\r\n", "output": ["4.8133196117786711780806656271869913331127534865038175322117213586960112955982462632332925275690064929"]}, {"input": "7.7060200967648284035308242369118752594772564843152902469146249303976625961451358536989314351204406625e1\r\n", "output": ["77.060200967648284035308242369118752594772564843152902469146249303976625961451358536989314351204406625"]}, {"input": "8.1089882894234341219420177467603732503076124872188628349726911362800974096687340341040683238197289136e31\r\n", "output": ["81089882894234341219420177467603.732503076124872188628349726911362800974096687340341040683238197289136"]}, {"input": "9.6576660076120385279859051742522204516365367878315639937449558670629833997839913220859648564428655877e99\r\n", "output": ["9657666007612038527985905174252220451636536787831563993744955867062983399783991322085964856442865587.7"]}, {"input": "0.0e0\r\n", "output": ["0"]}, {"input": "1.0e0\r\n", "output": ["1"]}, {"input": "8.0e0\r\n", "output": ["8"]}, {"input": "3.0e0\r\n", "output": ["3"]}, {"input": "4.0e0\r\n", "output": ["4"]}, {"input": "2.0e0\r\n", "output": ["2"]}, {"input": "9.0e0\r\n", "output": ["9"]}, {"input": "0.888888e0\r\n", "output": ["0.888888"]}, {"input": "9.99999999999999999999999999999999999999999999999999999999999999999999999999999999e100\r\n", "output": ["99999999999999999999999999999999999999999999999999999999999999999999999999999999900000000000000000000"]}, {"input": "5.0e0\r\n", "output": ["5"]}, {"input": "1.0e10\r\n", "output": ["10000000000"]}, {"input": "1.0e5\r\n", "output": ["100000"]}, {"input": "6.0e0\r\n", "output": ["6"]}, {"input": "1.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111e1\r\n", "output": ["11.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"]}]
100
100
100
[{'input': '1.31e1\r\n', 'output': ['13.1']}, {'input': '3.0e0\r\n', 'output': ['3']}, {'input': '0.75e0\r\n', 'output': ['0.75']}, {'input': '5.8743505652112692964508303637002e64\r\n', 'output': ['58743505652112692964508303637002000000000000000000000000000000000']}, {'input': '7.7060200967648284035308242369118752594772564843152902469146249303976625961451358536989314351204406625e1\r\n', 'output': ['77.060200967648284035308242369118752594772564843152902469146249303976625961451358536989314351204406625']}]
[{'input': '1.91641639840522198229453882518758458881136053577016034847369545687354908120008812644841021662133251e89\r\n', 'output': ['191641639840522198229453882518758458881136053577016034847369545687354908120008812644841021.662133251']}, {'input': '8.549e2\r\n', 'output': ['854.9']}, {'input': '0.0e0\r\n', 'output': ['0']}, {'input': '1.038e0\r\n', 'output': ['1.038']}, {'input': '1.31e1\r\n', 'output': ['13.1']}]
[{'input': '0.0e0\r\n', 'output': ['0']}, {'input': '9.0e0\r\n', 'output': ['9']}, {'input': '0.7e0\r\n', 'output': ['0.7']}, {'input': '1.0e0\r\n', 'output': ['1']}, {'input': '2.0629094807595491132306264747042243928486303384791951220362096240931158821630792563855724946791054152e85\r\n', 'output': ['20629094807595491132306264747042243928486303384791951220362096240931158821630792563855.724946791054152']}]
[{'input': '4.0e0\r\n', 'output': ['4']}, {'input': '1.91641639840522198229453882518758458881136053577016034847369545687354908120008812644841021662133251e89\r\n', 'output': ['191641639840522198229453882518758458881136053577016034847369545687354908120008812644841021.662133251']}, {'input': '1.038e0\r\n', 'output': ['1.038']}, {'input': '1.0e0\r\n', 'output': ['1']}, {'input': '7.7060200967648284035308242369118752594772564843152902469146249303976625961451358536989314351204406625e1\r\n', 'output': ['77.060200967648284035308242369118752594772564843152902469146249303976625961451358536989314351204406625']}]
[{'input': '3.2371070627618799335840070613481911588919091676203766004638236894609230433739617153911544972468224113e50\r\n', 'output': ['323710706276187993358400706134819115889190916762037.66004638236894609230433739617153911544972468224113']}, {'input': '2.806303180541991592302230754797823269634e39\r\n', 'output': ['2806303180541991592302230754797823269634']}, {'input': '3.0e0\r\n', 'output': ['3']}, {'input': '1.0e5\r\n', 'output': ['100000']}, {'input': '0.888888e0\r\n', 'output': ['0.888888']}]
100
100
100
100
100
100
86.96
86.96
86.96
100
90
75
85
75
90
222
100
92.176
83
["11\n00000000008", "22\n0011223344556677889988", "11\n31415926535"]
The first line contains an integer $$$n$$$Β β€” the number of cards with digits that you have ($$$1 \leq n \leq 100$$$). The second line contains a string of $$$n$$$ digits (characters "0", "1", ..., "9") $$$s_1, s_2, \ldots, s_n$$$. The string will not contain any other characters, such as leading or trailing spaces.
259d01b81bef5536b969247ff2c2d776
import java.io.PrintWriter; import java.util.Scanner; public class PhoneNumbers { void solve(Scanner s, PrintWriter out) { s.next(); int e = 0, o = 0; for (char c : s.next().toCharArray()) if (c == '8') e++; else o++; out.println(Math.min(e, (o + e) / 11)); } public static void main(String[] args) { Scanner s = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); new PhoneNumbers().solve(s, out); out.close(); s.close(); } }
["1", "2", "0"]
Java
NoteIn the first example, one phone number, "8000000000", can be made from these cards.In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".In the third example you can't make any phone number from the given cards.
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.You have $$$n$$$ cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
[{"input": "11\r\n00000000008\r\n", "output": ["1"]}, {"input": "22\r\n0011223344556677889988\r\n", "output": ["2"]}, {"input": "11\r\n31415926535\r\n", "output": ["0"]}, {"input": "99\r\n097167815527663544905782574817314139311067328533970663873718450545467450059059869618211361469505108\r\n", "output": ["9"]}, {"input": "100\r\n8820286285185244938452488887088871457098945874486988698468788381417332842888928188688887641132194956\r\n", "output": ["9"]}, {"input": "99\r\n509170332523502565755650047942914747120102240396245453406790272793996913905060450414255616791704320\r\n", "output": ["0"]}, {"input": "100\r\n1976473621569903172721407763737179639055561746310369779167351419713916160700096173622427077757986026\r\n", "output": ["1"]}, {"input": "100\r\n8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888\r\n", "output": ["9"]}, {"input": "10\r\n8888888888\r\n", "output": ["0"]}, {"input": "20\r\n88888888888888888888\r\n", "output": ["1"]}, {"input": "30\r\n888888888888888888888888888888\r\n", "output": ["2"]}, {"input": "40\r\n8888888888888888888888888888888888888888\r\n", "output": ["3"]}, {"input": "50\r\n88888888888888888888888888888888888888888888888888\r\n", "output": ["4"]}, {"input": "60\r\n888888888888888888888888888888888888888888888888888888888888\r\n", "output": ["5"]}, {"input": "70\r\n8888888888888888888888888888888888888888888888888888888888888888888888\r\n", "output": ["6"]}, {"input": "80\r\n88888888888888888888888888888888888888888888888888888888888888888888888888888888\r\n", "output": ["7"]}, {"input": "90\r\n888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888\r\n", "output": ["8"]}, {"input": "11\r\n24572366390\r\n", "output": ["0"]}, {"input": "21\r\n582586788289484878588\r\n", "output": ["1"]}, {"input": "31\r\n0868889888343881888987888838808\r\n", "output": ["2"]}, {"input": "41\r\n78888884888874788841882882888088888588888\r\n", "output": ["3"]}, {"input": "51\r\n882889888888689888850888388887688788888888888858888\r\n", "output": ["4"]}, {"input": "61\r\n8880888836888988888988888887388888888888868898887888818888888\r\n", "output": ["5"]}, {"input": "71\r\n88888888888888888888888188888805848888788088888883888883187888838888888\r\n", "output": ["6"]}, {"input": "81\r\n808888883488887888888808888888888888188888888388888888888888868688888488888882888\r\n", "output": ["7"]}, {"input": "91\r\n8828880888888884883888488888888888888881888888888884888888848588888808888888888888888880888\r\n", "output": ["8"]}, {"input": "100\r\n8888888888828188888888888888888808888888888888888888891888888768888888888288888885886888838888888888\r\n", "output": ["9"]}, {"input": "22\r\n4215079217017196952791\r\n", "output": ["0"]}, {"input": "32\r\n88257478884887437239023185588797\r\n", "output": ["2"]}, {"input": "42\r\n885887846290886288816884858898812858495482\r\n", "output": ["3"]}, {"input": "52\r\n8878588869084488848898838898788838337877898817818888\r\n", "output": ["4"]}, {"input": "62\r\n18888883884288488882387888486858887882838885288886472818688888\r\n", "output": ["5"]}, {"input": "72\r\n888488888888823288848804883838888888887888888888228888218488897809784868\r\n", "output": ["6"]}, {"input": "82\r\n8889809888888888485881851986857288588888888881988888868888836888887858888888888878\r\n", "output": ["7"]}, {"input": "92\r\n86888880558884738878888381088888888895888881888888888368878888888884888768881888888888808888\r\n", "output": ["8"]}, {"input": "100\r\n8881888389882878867888888888888888888886388888888870888884878888089888883898887888808688888487888888\r\n", "output": ["9"]}, {"input": "33\r\n270375004567749549929235905225024\r\n", "output": ["0"]}, {"input": "43\r\n7404899846883344886153727489084158470112581\r\n", "output": ["3"]}, {"input": "53\r\n85838985300863473289888099788588319484149888886832906\r\n", "output": ["4"]}, {"input": "63\r\n728385948188688801288285888788852829888898565895847689806684688\r\n", "output": ["5"]}, {"input": "73\r\n2185806538483837898808836883483888818818988881880688028788888081888907898\r\n", "output": ["6"]}, {"input": "83\r\n88584458884288808888588388818938838468960248387898182887888867888888888886088895788\r\n", "output": ["7"]}, {"input": "93\r\n888088898748888038885888818882806848806887888888882087481868888888177809288888889648468888188\r\n", "output": ["8"]}, {"input": "100\r\n8088888818885808888888848829886788884187188858898888888788988688884828586988888888288078638898728181\r\n", "output": ["9"]}, {"input": "44\r\n15920309219313427633220119270900111650391207\r\n", "output": ["0"]}, {"input": "54\r\n438283821340622774637957966575424773837418828888614203\r\n", "output": ["4"]}, {"input": "64\r\n8885984815868480968883818886281846682409262501034555933863969284\r\n", "output": ["5"]}, {"input": "74\r\n70988894874867688968816582886488688881063425288316858438189808828755218508\r\n", "output": ["6"]}, {"input": "84\r\n181288888282608548858058871581888853888486785801381108858832882809848798828837386086\r\n", "output": ["7"]}, {"input": "94\r\n8188948828818938226378510887848897889883818858778688882933888883888898198978868888808082461388\r\n", "output": ["8"]}, {"input": "100\r\n2867878187889776883889958480848802884888888878218089281860321588888888987288888884288488988628618888\r\n", "output": ["9"]}, {"input": "55\r\n7271714707719515303911625619272900050990324951111943573\r\n", "output": ["0"]}, {"input": "65\r\n44542121362830719677175203560438858260878894083124543850593761845\r\n", "output": ["5"]}, {"input": "75\r\n878909759892888846183608689257806813376950958863798487856148633095072259838\r\n", "output": ["6"]}, {"input": "85\r\n6888887655188885918863889822590788834182048952565514598298586848861396753319582883848\r\n", "output": ["7"]}, {"input": "95\r\n29488352815808808845913584782288724288898869488882098428839370889284838688458247785878848884289\r\n", "output": ["8"]}, {"input": "100\r\n2833898888858387469888804083887280788584887487186899808436848018181838884988432785338497585788803883\r\n", "output": ["9"]}, {"input": "66\r\n747099435917145962031075767196746707764157706291155762576312312094\r\n", "output": ["0"]}, {"input": "76\r\n7900795570936733366353829649382870728119825830883973668601071678041634916557\r\n", "output": ["6"]}, {"input": "86\r\n84065885114540280210185082984888812185222886689129308815942798404861082196041321701260\r\n", "output": ["7"]}, {"input": "96\r\n812087553199958040928832802441581868680188987878748641868838838835609806814288472573117388803351\r\n", "output": ["8"]}, {"input": "77\r\n11233392925013001334679215120076714945221576003953746107506364475115045309091\r\n", "output": ["0"]}, {"input": "87\r\n311753415808202195240425076966761033489788093280714672959929008324554784724650182457298\r\n", "output": ["7"]}, {"input": "97\r\n4088468966684435599488804806521288358953088399738904557539253573051442198885776802972628197705081\r\n", "output": ["8"]}, {"input": "100\r\n6451941807833681891890004306065158148809856572066617888008875119881621810329816763604830895480467878\r\n", "output": ["9"]}, {"input": "88\r\n2694079127792970410465292300936220976260790323517221561516591792566791677970332966660472\r\n", "output": ["0"]}, {"input": "98\r\n87247250157776241281197787785951754485531639139778166755966603305697265958800376912432893847612736\r\n", "output": ["8"]}, {"input": "100\r\n1835563855281170226095294644116563180561156535623048783710060508361834822227075869575873675232708159\r\n", "output": ["9"]}, {"input": "11\r\n55814018693\r\n", "output": ["1"]}, {"input": "22\r\n6188156585823394680191\r\n", "output": ["2"]}, {"input": "33\r\n429980628264468835720540136177288\r\n", "output": ["3"]}, {"input": "44\r\n30153452341853403190257244993442815171970194\r\n", "output": ["2"]}, {"input": "55\r\n3982037603326093160114589190899881252765957832414122484\r\n", "output": ["5"]}, {"input": "66\r\n157941266854773786962397310504192100434183957442977444078457168272\r\n", "output": ["5"]}, {"input": "1\r\n0\r\n", "output": ["0"]}, {"input": "11\r\n80000000000\r\n", "output": ["1"]}, {"input": "27\r\n888000000000000000000000000\r\n", "output": ["2"]}, {"input": "10\r\n8000000000\r\n", "output": ["0"]}, {"input": "1\r\n8\r\n", "output": ["0"]}, {"input": "50\r\n88000000000000000000000000000000000000000000000000\r\n", "output": ["2"]}, {"input": "11\r\n81234567090\r\n", "output": ["1"]}, {"input": "32\r\n88000000000000000000000000000000\r\n", "output": ["2"]}, {"input": "57\r\n888888888888888888888888888888888888888888888888888888888\r\n", "output": ["5"]}, {"input": "22\r\n8899999999999999999999\r\n", "output": ["2"]}, {"input": "21\r\n881234567900123456790\r\n", "output": ["1"]}, {"input": "21\r\n888888555555555555555\r\n", "output": ["1"]}, {"input": "21\r\n888000000000000000000\r\n", "output": ["1"]}, {"input": "100\r\n8800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n", "output": ["2"]}, {"input": "21\r\n888888888888000000000\r\n", "output": ["1"]}, {"input": "8\r\n12345678\r\n", "output": ["0"]}, {"input": "21\r\n880000000000000000000\r\n", "output": ["1"]}, {"input": "11\r\n81234567123\r\n", "output": ["1"]}, {"input": "11\r\n88888888888\r\n", "output": ["1"]}, {"input": "32\r\n88888888888888888888888888888888\r\n", "output": ["2"]}, {"input": "33\r\n888800000000000000000000000000000\r\n", "output": ["3"]}, {"input": "100\r\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008\r\n", "output": ["1"]}, {"input": "21\r\n888111111111111111111\r\n", "output": ["1"]}, {"input": "77\r\n11111111111111111111111111111111111111111111111111111111111111111111111111111\r\n", "output": ["0"]}]
100
100
100
[{'input': '82\r\n8889809888888888485881851986857288588888888881988888868888836888887858888888888878\r\n', 'output': ['7']}, {'input': '1\r\n8\r\n', 'output': ['0']}, {'input': '52\r\n8878588869084488848898838898788838337877898817818888\r\n', 'output': ['4']}, {'input': '65\r\n44542121362830719677175203560438858260878894083124543850593761845\r\n', 'output': ['5']}, {'input': '11\r\n81234567123\r\n', 'output': ['1']}]
[{'input': '66\r\n157941266854773786962397310504192100434183957442977444078457168272\r\n', 'output': ['5']}, {'input': '50\r\n88888888888888888888888888888888888888888888888888\r\n', 'output': ['4']}, {'input': '92\r\n86888880558884738878888381088888888895888881888888888368878888888884888768881888888888808888\r\n', 'output': ['8']}, {'input': '55\r\n3982037603326093160114589190899881252765957832414122484\r\n', 'output': ['5']}, {'input': '53\r\n85838985300863473289888099788588319484149888886832906\r\n', 'output': ['4']}]
[{'input': '10\r\n8000000000\r\n', 'output': ['0']}, {'input': '41\r\n78888884888874788841882882888088888588888\r\n', 'output': ['3']}, {'input': '65\r\n44542121362830719677175203560438858260878894083124543850593761845\r\n', 'output': ['5']}, {'input': '33\r\n429980628264468835720540136177288\r\n', 'output': ['3']}, {'input': '66\r\n747099435917145962031075767196746707764157706291155762576312312094\r\n', 'output': ['0']}]
[{'input': '70\r\n8888888888888888888888888888888888888888888888888888888888888888888888\r\n', 'output': ['6']}, {'input': '54\r\n438283821340622774637957966575424773837418828888614203\r\n', 'output': ['4']}, {'input': '76\r\n7900795570936733366353829649382870728119825830883973668601071678041634916557\r\n', 'output': ['6']}, {'input': '40\r\n8888888888888888888888888888888888888888\r\n', 'output': ['3']}, {'input': '52\r\n8878588869084488848898838898788838337877898817818888\r\n', 'output': ['4']}]
[{'input': '63\r\n728385948188688801288285888788852829888898565895847689806684688\r\n', 'output': ['5']}, {'input': '8\r\n12345678\r\n', 'output': ['0']}, {'input': '51\r\n882889888888689888850888388887688788888888888858888\r\n', 'output': ['4']}, {'input': '75\r\n878909759892888846183608689257806813376950958863798487856148633095072259838\r\n', 'output': ['6']}, {'input': '21\r\n881234567900123456790\r\n', 'output': ['1']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
223
100
100
100
["7 3\n5 10\n2 5\n3 6", "3 3\n1 3\n2 2\n3 1"]
The first line of the input contains integer n (1 ≀ n ≀ 2Β·108) and integer m (1 ≀ m ≀ 20). The i + 1-th line contains a pair of numbers ai and bi (1 ≀ ai ≀ 108, 1 ≀ bi ≀ 10). All the input numbers are integer.
c052d85e402691b05e494b5283d62679
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import static java.util.Collections.reverseOrder; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Scanner; import java.util.Set; import java.util.stream.Collectors; /** * * @author Ahmed_Naser */ public class HelloWorld { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int matchboxes[] = new int[m]; int matches[]= new int[m]; for(int i = 0 ; i < m ; i++) { matchboxes[i] =in.nextInt(); matches[i] = in.nextInt(); } int max = matches[0]; int index = 0 ; int count = 0 ; while( n > 0) { for( int j = 0 ; j < m ; ++j) { if( matches[j] >= max) { max= matches[j]; index = j; } } if( matchboxes[index] <= n) { n = n - matchboxes[index]; count = count + (matches[index] * matchboxes[index] ); matches[index] = 0 ; } else { count = count + (n * matches[index]); n = 0 ; } max = matches[0]; } System.out.println(count); } }
["62", "7"]
Java
null
Output the only number β€” answer to the problem.
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than n matchboxes so that the total amount of matches in them is maximal.
[{"input": "7 3\r\n5 10\r\n2 5\r\n3 6\r\n", "output": ["62"]}, {"input": "3 3\r\n1 3\r\n2 2\r\n3 1\r\n", "output": ["7"]}, {"input": "1 1\r\n1 2\r\n", "output": ["2"]}, {"input": "1 2\r\n1 9\r\n1 6\r\n", "output": ["9"]}, {"input": "1 10\r\n1 1\r\n1 9\r\n1 3\r\n1 9\r\n1 7\r\n1 10\r\n1 4\r\n1 7\r\n1 3\r\n1 1\r\n", "output": ["10"]}, {"input": "2 1\r\n2 1\r\n", "output": ["2"]}, {"input": "2 2\r\n2 4\r\n1 4\r\n", "output": ["8"]}, {"input": "2 3\r\n1 7\r\n1 2\r\n1 5\r\n", "output": ["12"]}, {"input": "4 1\r\n2 2\r\n", "output": ["4"]}, {"input": "4 2\r\n1 10\r\n4 4\r\n", "output": ["22"]}, {"input": "4 3\r\n1 4\r\n6 4\r\n1 7\r\n", "output": ["19"]}, {"input": "5 1\r\n10 5\r\n", "output": ["25"]}, {"input": "5 2\r\n3 9\r\n2 2\r\n", "output": ["31"]}, {"input": "5 5\r\n2 9\r\n3 1\r\n2 1\r\n1 8\r\n2 8\r\n", "output": ["42"]}, {"input": "5 10\r\n1 3\r\n1 2\r\n1 9\r\n1 10\r\n1 1\r\n1 5\r\n1 10\r\n1 2\r\n1 3\r\n1 7\r\n", "output": ["41"]}, {"input": "10 1\r\n9 4\r\n", "output": ["36"]}, {"input": "10 2\r\n14 3\r\n1 3\r\n", "output": ["30"]}, {"input": "10 7\r\n4 8\r\n1 10\r\n1 10\r\n1 2\r\n3 3\r\n1 3\r\n1 10\r\n", "output": ["71"]}, {"input": "10 10\r\n1 8\r\n2 10\r\n1 9\r\n1 1\r\n1 9\r\n1 6\r\n1 4\r\n2 5\r\n1 2\r\n1 4\r\n", "output": ["70"]}, {"input": "10 4\r\n1 5\r\n5 2\r\n1 9\r\n3 3\r\n", "output": ["33"]}, {"input": "100 5\r\n78 6\r\n29 10\r\n3 6\r\n7 3\r\n2 4\r\n", "output": ["716"]}, {"input": "1000 7\r\n102 10\r\n23 6\r\n79 4\r\n48 1\r\n34 10\r\n839 8\r\n38 4\r\n", "output": ["8218"]}, {"input": "10000 10\r\n336 2\r\n2782 5\r\n430 10\r\n1893 7\r\n3989 10\r\n2593 8\r\n165 6\r\n1029 2\r\n2097 4\r\n178 10\r\n", "output": ["84715"]}, {"input": "100000 3\r\n2975 2\r\n35046 4\r\n61979 9\r\n", "output": ["703945"]}, {"input": "1000000 4\r\n314183 9\r\n304213 4\r\n16864 5\r\n641358 9\r\n", "output": ["8794569"]}, {"input": "10000000 10\r\n360313 10\r\n416076 1\r\n435445 9\r\n940322 7\r\n1647581 7\r\n4356968 10\r\n3589256 2\r\n2967933 5\r\n2747504 7\r\n1151633 3\r\n", "output": ["85022733"]}, {"input": "100000000 7\r\n32844337 7\r\n11210848 7\r\n47655987 1\r\n33900472 4\r\n9174763 2\r\n32228738 10\r\n29947408 5\r\n", "output": ["749254060"]}, {"input": "200000000 10\r\n27953106 7\r\n43325979 4\r\n4709522 1\r\n10975786 4\r\n67786538 8\r\n48901838 7\r\n15606185 6\r\n2747583 1\r\n100000000 1\r\n633331 3\r\n", "output": ["1332923354"]}, {"input": "200000000 9\r\n17463897 9\r\n79520463 1\r\n162407 4\r\n41017993 8\r\n71054118 4\r\n9447587 2\r\n5298038 9\r\n3674560 7\r\n20539314 5\r\n", "output": ["996523209"]}, {"input": "200000000 8\r\n6312706 6\r\n2920548 2\r\n16843192 3\r\n1501141 2\r\n13394704 6\r\n10047725 10\r\n4547663 6\r\n54268518 6\r\n", "output": ["630991750"]}, {"input": "200000000 7\r\n25621043 2\r\n21865270 1\r\n28833034 1\r\n22185073 5\r\n100000000 2\r\n13891017 9\r\n61298710 8\r\n", "output": ["931584598"]}, {"input": "200000000 6\r\n7465600 6\r\n8453505 10\r\n4572014 8\r\n8899499 3\r\n86805622 10\r\n64439238 6\r\n", "output": ["1447294907"]}, {"input": "200000000 5\r\n44608415 6\r\n100000000 9\r\n51483223 9\r\n44136047 1\r\n52718517 1\r\n", "output": ["1634907859"]}, {"input": "200000000 4\r\n37758556 10\r\n100000000 6\r\n48268521 3\r\n20148178 10\r\n", "output": ["1305347138"]}, {"input": "200000000 3\r\n65170000 7\r\n20790088 1\r\n74616133 4\r\n", "output": ["775444620"]}, {"input": "200000000 2\r\n11823018 6\r\n100000000 9\r\n", "output": ["970938108"]}, {"input": "200000000 1\r\n100000000 6\r\n", "output": ["600000000"]}, {"input": "200000000 10\r\n12097724 9\r\n41745972 5\r\n26982098 9\r\n14916995 7\r\n21549986 7\r\n3786630 9\r\n8050858 7\r\n27994924 4\r\n18345001 5\r\n8435339 5\r\n", "output": ["1152034197"]}, {"input": "200000000 10\r\n55649 8\r\n10980981 9\r\n3192542 8\r\n94994808 4\r\n3626106 1\r\n100000000 6\r\n5260110 9\r\n4121453 2\r\n15125061 4\r\n669569 6\r\n", "output": ["1095537357"]}, {"input": "10 20\r\n1 7\r\n1 7\r\n1 8\r\n1 3\r\n1 10\r\n1 7\r\n1 7\r\n1 9\r\n1 3\r\n1 1\r\n1 2\r\n1 1\r\n1 3\r\n1 10\r\n1 9\r\n1 8\r\n1 8\r\n1 6\r\n1 7\r\n1 5\r\n", "output": ["83"]}, {"input": "10000000 20\r\n4594 7\r\n520836 8\r\n294766 6\r\n298672 4\r\n142253 6\r\n450626 1\r\n1920034 9\r\n58282 4\r\n1043204 1\r\n683045 1\r\n1491746 5\r\n58420 4\r\n451217 2\r\n129423 4\r\n246113 5\r\n190612 8\r\n912923 6\r\n473153 6\r\n783733 6\r\n282411 10\r\n", "output": ["54980855"]}, {"input": "200000000 20\r\n15450824 5\r\n839717 10\r\n260084 8\r\n1140850 8\r\n28744 6\r\n675318 3\r\n25161 2\r\n5487 3\r\n6537698 9\r\n100000000 5\r\n7646970 9\r\n16489 6\r\n24627 3\r\n1009409 5\r\n22455 1\r\n25488456 4\r\n484528 9\r\n32663641 3\r\n750968 4\r\n5152 6\r\n", "output": ["939368573"]}, {"input": "200000000 20\r\n16896 2\r\n113 3\r\n277 2\r\n299 7\r\n69383562 2\r\n3929 8\r\n499366 4\r\n771846 5\r\n9 4\r\n1278173 7\r\n90 2\r\n54 7\r\n72199858 10\r\n17214 5\r\n3 10\r\n1981618 3\r\n3728 2\r\n141 8\r\n2013578 9\r\n51829246 5\r\n", "output": ["1158946383"]}, {"input": "200000000 20\r\n983125 2\r\n7453215 9\r\n9193588 2\r\n11558049 7\r\n28666199 1\r\n34362244 1\r\n5241493 5\r\n15451270 4\r\n19945845 8\r\n6208681 3\r\n38300385 7\r\n6441209 8\r\n21046742 7\r\n577198 10\r\n3826434 8\r\n9764276 8\r\n6264675 7\r\n8567063 3\r\n3610303 4\r\n2908232 3\r\n", "output": ["1131379312"]}, {"input": "10 15\r\n1 6\r\n2 6\r\n3 4\r\n1 3\r\n1 2\r\n1 5\r\n1 6\r\n1 2\r\n2 9\r\n1 10\r\n1 3\r\n1 7\r\n1 8\r\n1 2\r\n2 9\r\n", "output": ["79"]}, {"input": "10000000 15\r\n111 5\r\n914124 3\r\n3 9\r\n177790 1\r\n2352 3\r\n32138 9\r\n104477 1\r\n1223 4\r\n18 6\r\n6655580 4\r\n57643 10\r\n94309 2\r\n37 1\r\n227002 10\r\n1733193 7\r\n", "output": ["45116295"]}, {"input": "200000000 15\r\n7069868 1\r\n5567826 8\r\n2310059 10\r\n13539782 7\r\n38420939 4\r\n29911411 8\r\n52256316 1\r\n12265839 9\r\n2074265 1\r\n24896428 9\r\n72470695 5\r\n3236301 1\r\n3890243 2\r\n65168965 8\r\n65724 6\r\n", "output": ["1489289257"]}, {"input": "200000000 15\r\n12044094 7\r\n2475138 10\r\n944451 7\r\n4854766 2\r\n3809145 10\r\n7727571 2\r\n43908937 6\r\n2745883 1\r\n427511 2\r\n100000000 5\r\n190914 6\r\n554889 3\r\n288798 4\r\n1848572 5\r\n893874 3\r\n", "output": ["961871671"]}, {"input": "200000000 15\r\n6334191 7\r\n1927941 4\r\n5175933 10\r\n468389 1\r\n433043 10\r\n6863198 5\r\n7480646 4\r\n14774279 10\r\n2921129 8\r\n18325627 7\r\n6973152 9\r\n8277324 9\r\n21522856 2\r\n2058070 1\r\n2444742 4\r\n", "output": ["664376069"]}]
100
100
100
[{'input': '2 2\r\n2 4\r\n1 4\r\n', 'output': ['8']}, {'input': '2 1\r\n2 1\r\n', 'output': ['2']}, {'input': '200000000 6\r\n7465600 6\r\n8453505 10\r\n4572014 8\r\n8899499 3\r\n86805622 10\r\n64439238 6\r\n', 'output': ['1447294907']}, {'input': '4 1\r\n2 2\r\n', 'output': ['4']}, {'input': '200000000 10\r\n27953106 7\r\n43325979 4\r\n4709522 1\r\n10975786 4\r\n67786538 8\r\n48901838 7\r\n15606185 6\r\n2747583 1\r\n100000000 1\r\n633331 3\r\n', 'output': ['1332923354']}]
[{'input': '200000000 9\r\n17463897 9\r\n79520463 1\r\n162407 4\r\n41017993 8\r\n71054118 4\r\n9447587 2\r\n5298038 9\r\n3674560 7\r\n20539314 5\r\n', 'output': ['996523209']}, {'input': '200000000 6\r\n7465600 6\r\n8453505 10\r\n4572014 8\r\n8899499 3\r\n86805622 10\r\n64439238 6\r\n', 'output': ['1447294907']}, {'input': '10000000 15\r\n111 5\r\n914124 3\r\n3 9\r\n177790 1\r\n2352 3\r\n32138 9\r\n104477 1\r\n1223 4\r\n18 6\r\n6655580 4\r\n57643 10\r\n94309 2\r\n37 1\r\n227002 10\r\n1733193 7\r\n', 'output': ['45116295']}, {'input': '1 1\r\n1 2\r\n', 'output': ['2']}, {'input': '10 1\r\n9 4\r\n', 'output': ['36']}]
[{'input': '10 10\r\n1 8\r\n2 10\r\n1 9\r\n1 1\r\n1 9\r\n1 6\r\n1 4\r\n2 5\r\n1 2\r\n1 4\r\n', 'output': ['70']}, {'input': '1 2\r\n1 9\r\n1 6\r\n', 'output': ['9']}, {'input': '5 2\r\n3 9\r\n2 2\r\n', 'output': ['31']}, {'input': '10 4\r\n1 5\r\n5 2\r\n1 9\r\n3 3\r\n', 'output': ['33']}, {'input': '200000000 10\r\n55649 8\r\n10980981 9\r\n3192542 8\r\n94994808 4\r\n3626106 1\r\n100000000 6\r\n5260110 9\r\n4121453 2\r\n15125061 4\r\n669569 6\r\n', 'output': ['1095537357']}]
[{'input': '200000000 10\r\n55649 8\r\n10980981 9\r\n3192542 8\r\n94994808 4\r\n3626106 1\r\n100000000 6\r\n5260110 9\r\n4121453 2\r\n15125061 4\r\n669569 6\r\n', 'output': ['1095537357']}, {'input': '200000000 2\r\n11823018 6\r\n100000000 9\r\n', 'output': ['970938108']}, {'input': '200000000 20\r\n983125 2\r\n7453215 9\r\n9193588 2\r\n11558049 7\r\n28666199 1\r\n34362244 1\r\n5241493 5\r\n15451270 4\r\n19945845 8\r\n6208681 3\r\n38300385 7\r\n6441209 8\r\n21046742 7\r\n577198 10\r\n3826434 8\r\n9764276 8\r\n6264675 7\r\n8567063 3\r\n3610303 4\r\n2908232 3\r\n', 'output': ['1131379312']}, {'input': '1 2\r\n1 9\r\n1 6\r\n', 'output': ['9']}, {'input': '200000000 10\r\n12097724 9\r\n41745972 5\r\n26982098 9\r\n14916995 7\r\n21549986 7\r\n3786630 9\r\n8050858 7\r\n27994924 4\r\n18345001 5\r\n8435339 5\r\n', 'output': ['1152034197']}]
[{'input': '1 10\r\n1 1\r\n1 9\r\n1 3\r\n1 9\r\n1 7\r\n1 10\r\n1 4\r\n1 7\r\n1 3\r\n1 1\r\n', 'output': ['10']}, {'input': '10 10\r\n1 8\r\n2 10\r\n1 9\r\n1 1\r\n1 9\r\n1 6\r\n1 4\r\n2 5\r\n1 2\r\n1 4\r\n', 'output': ['70']}, {'input': '200000000 2\r\n11823018 6\r\n100000000 9\r\n', 'output': ['970938108']}, {'input': '10 15\r\n1 6\r\n2 6\r\n3 4\r\n1 3\r\n1 2\r\n1 5\r\n1 6\r\n1 2\r\n2 9\r\n1 10\r\n1 3\r\n1 7\r\n1 8\r\n1 2\r\n2 9\r\n', 'output': ['79']}, {'input': '10000000 10\r\n360313 10\r\n416076 1\r\n435445 9\r\n940322 7\r\n1647581 7\r\n4356968 10\r\n3589256 2\r\n2967933 5\r\n2747504 7\r\n1151633 3\r\n', 'output': ['85022733']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
224
100
100
100
["5 5 2", "6 7 4"]
A single line contains three space-separated integers a, b, r (1 ≀ a, b, r ≀ 100) β€” the table sides and the plates' radius, correspondingly.
90b9ef939a13cf29715bc5bce26c9896
//package com.example.hackerranksolutions; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Scanner; public class CodeforcesProblems { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] inputs = br.readLine().split(" "); int a = Integer.parseInt(inputs[0]); int b = Integer.parseInt(inputs[1]); int r = Integer.parseInt(inputs[2]); if(a>=2*r && b>=2*r) System.out.println("First"); else System.out.println("Second"); } }
["First", "Second"]
Java
NoteIn the first sample the table has place for only one plate. The first player puts a plate on the table, the second player can't do that and loses. In the second sample the table is so small that it doesn't have enough place even for one plate. So the first player loses without making a single move.
If wins the player who moves first, print "First" (without the quotes). Otherwise print "Second" (without the quotes).
You've got a rectangular table with length a and width b and the infinite number of plates of radius r. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch each other), and so that any point on any plate is located within the table's border. During the game one cannot move the plates that already lie on the table. The player who cannot make another move loses. Determine which player wins, the one who moves first or the one who moves second, provided that both players play optimally well.
[{"input": "5 5 2\r\n", "output": ["First"]}, {"input": "6 7 4\r\n", "output": ["Second"]}, {"input": "100 100 1\r\n", "output": ["First"]}, {"input": "1 1 100\r\n", "output": ["Second"]}, {"input": "13 7 3\r\n", "output": ["First"]}, {"input": "23 7 3\r\n", "output": ["First"]}, {"input": "9 9 2\r\n", "output": ["First"]}, {"input": "13 13 2\r\n", "output": ["First"]}, {"input": "21 21 10\r\n", "output": ["First"]}, {"input": "20 21 10\r\n", "output": ["First"]}, {"input": "20 20 10\r\n", "output": ["First"]}, {"input": "9 13 2\r\n", "output": ["First"]}, {"input": "19 7 3\r\n", "output": ["First"]}, {"input": "19 19 10\r\n", "output": ["Second"]}, {"input": "19 20 10\r\n", "output": ["Second"]}, {"input": "19 21 10\r\n", "output": ["Second"]}, {"input": "1 100 1\r\n", "output": ["Second"]}, {"input": "2 100 1\r\n", "output": ["First"]}, {"input": "3 100 1\r\n", "output": ["First"]}, {"input": "100 100 49\r\n", "output": ["First"]}, {"input": "100 100 50\r\n", "output": ["First"]}, {"input": "100 100 51\r\n", "output": ["Second"]}, {"input": "100 99 50\r\n", "output": ["Second"]}, {"input": "4 10 5\r\n", "output": ["Second"]}, {"input": "8 11 2\r\n", "output": ["First"]}, {"input": "3 12 5\r\n", "output": ["Second"]}, {"input": "14 15 5\r\n", "output": ["First"]}, {"input": "61 2 3\r\n", "output": ["Second"]}, {"input": "82 20 5\r\n", "output": ["First"]}, {"input": "16 80 10\r\n", "output": ["Second"]}, {"input": "2 1 20\r\n", "output": ["Second"]}, {"input": "78 82 5\r\n", "output": ["First"]}, {"input": "8 55 7\r\n", "output": ["Second"]}, {"input": "75 55 43\r\n", "output": ["Second"]}, {"input": "34 43 70\r\n", "output": ["Second"]}, {"input": "86 74 36\r\n", "output": ["First"]}, {"input": "86 74 37\r\n", "output": ["First"]}, {"input": "86 74 38\r\n", "output": ["Second"]}, {"input": "24 70 11\r\n", "output": ["First"]}, {"input": "24 70 12\r\n", "output": ["First"]}, {"input": "24 70 13\r\n", "output": ["Second"]}, {"input": "78 95 38\r\n", "output": ["First"]}, {"input": "78 95 39\r\n", "output": ["First"]}, {"input": "78 95 40\r\n", "output": ["Second"]}, {"input": "88 43 21\r\n", "output": ["First"]}, {"input": "88 43 22\r\n", "output": ["Second"]}, {"input": "88 43 23\r\n", "output": ["Second"]}, {"input": "30 40 14\r\n", "output": ["First"]}, {"input": "30 40 15\r\n", "output": ["First"]}, {"input": "30 40 16\r\n", "output": ["Second"]}, {"input": "2 5 2\r\n", "output": ["Second"]}, {"input": "5 100 3\r\n", "output": ["Second"]}, {"input": "44 58 5\r\n", "output": ["First"]}, {"input": "4 4 6\r\n", "output": ["Second"]}, {"input": "10 20 6\r\n", "output": ["Second"]}, {"input": "100 1 1\r\n", "output": ["Second"]}, {"input": "60 60 1\r\n", "output": ["First"]}, {"input": "100 1 2\r\n", "output": ["Second"]}, {"input": "2 4 2\r\n", "output": ["Second"]}, {"input": "10 90 11\r\n", "output": ["Second"]}, {"input": "20 5 6\r\n", "output": ["Second"]}, {"input": "1 44 2\r\n", "output": ["Second"]}, {"input": "10 5 5\r\n", "output": ["Second"]}, {"input": "5 100 4\r\n", "output": ["Second"]}, {"input": "99 99 50\r\n", "output": ["Second"]}, {"input": "1 100 2\r\n", "output": ["Second"]}, {"input": "100 20 12\r\n", "output": ["Second"]}, {"input": "10 2 4\r\n", "output": ["Second"]}, {"input": "1 50 2\r\n", "output": ["Second"]}, {"input": "10 4 3\r\n", "output": ["Second"]}, {"input": "74 1 1\r\n", "output": ["Second"]}, {"input": "6 6 1\r\n", "output": ["First"]}, {"input": "10 10 1\r\n", "output": ["First"]}, {"input": "21 41 5\r\n", "output": ["First"]}, {"input": "13 1 2\r\n", "output": ["Second"]}, {"input": "1 100 3\r\n", "output": ["Second"]}, {"input": "1 64 2\r\n", "output": ["Second"]}, {"input": "3 4 1\r\n", "output": ["First"]}, {"input": "15 15 1\r\n", "output": ["First"]}, {"input": "15 16 1\r\n", "output": ["First"]}, {"input": "16 15 1\r\n", "output": ["First"]}, {"input": "16 16 1\r\n", "output": ["First"]}, {"input": "15 15 2\r\n", "output": ["First"]}, {"input": "15 16 2\r\n", "output": ["First"]}, {"input": "16 15 2\r\n", "output": ["First"]}, {"input": "16 16 2\r\n", "output": ["First"]}, {"input": "15 15 3\r\n", "output": ["First"]}, {"input": "15 16 3\r\n", "output": ["First"]}, {"input": "16 15 3\r\n", "output": ["First"]}, {"input": "16 16 3\r\n", "output": ["First"]}, {"input": "15 17 3\r\n", "output": ["First"]}, {"input": "16 17 3\r\n", "output": ["First"]}, {"input": "17 17 3\r\n", "output": ["First"]}, {"input": "17 15 3\r\n", "output": ["First"]}, {"input": "17 16 3\r\n", "output": ["First"]}]
100
100
100
[{'input': '100 100 51\r\n', 'output': ['Second']}, {'input': '44 58 5\r\n', 'output': ['First']}, {'input': '24 70 13\r\n', 'output': ['Second']}, {'input': '10 2 4\r\n', 'output': ['Second']}, {'input': '19 20 10\r\n', 'output': ['Second']}]
[{'input': '16 17 3\r\n', 'output': ['First']}, {'input': '4 4 6\r\n', 'output': ['Second']}, {'input': '2 100 1\r\n', 'output': ['First']}, {'input': '100 100 50\r\n', 'output': ['First']}, {'input': '1 100 3\r\n', 'output': ['Second']}]
[{'input': '61 2 3\r\n', 'output': ['Second']}, {'input': '100 1 2\r\n', 'output': ['Second']}, {'input': '30 40 14\r\n', 'output': ['First']}, {'input': '17 16 3\r\n', 'output': ['First']}, {'input': '15 16 1\r\n', 'output': ['First']}]
[{'input': '74 1 1\r\n', 'output': ['Second']}, {'input': '2 100 1\r\n', 'output': ['First']}, {'input': '15 16 1\r\n', 'output': ['First']}, {'input': '100 99 50\r\n', 'output': ['Second']}, {'input': '100 20 12\r\n', 'output': ['Second']}]
[{'input': '10 10 1\r\n', 'output': ['First']}, {'input': '20 5 6\r\n', 'output': ['Second']}, {'input': '17 17 3\r\n', 'output': ['First']}, {'input': '100 100 49\r\n', 'output': ['First']}, {'input': '15 17 3\r\n', 'output': ['First']}]
100
100
100
100
100
100
100
100
100
100
100
75
75
75
75
225
100
100
80
["3", "4"]
A single line contains one non-negative integer $$$n$$$ ($$$0 \le n \leq 10^{18}$$$)Β β€” the number of Shiro's friends. The circular pizza has to be sliced into $$$n + 1$$$ pieces.
236177ff30dafe68295b5d33dc501828
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); //inputs long n = input.nextLong(); if(n == 0) System.out.println(0); else if((n + 1) % 2 == 0) System.out.println((n + 1) / 2); else System.out.println(n + 1); } }
["2", "5"]
Java
NoteTo cut the round pizza into quarters one has to make two cuts through the center with angle $$$90^{\circ}$$$ between them.To cut the round pizza into five equal parts one has to make five cuts.
A single integerΒ β€” the number of straight cuts Shiro needs.
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro.She has ordered a very big round pizza, in order to serve her many friends. Exactly $$$n$$$ of Shiro's friends are here. That's why she has to divide the pizza into $$$n + 1$$$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over.Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator.As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem?
[{"input": "3\r\n", "output": ["2"]}, {"input": "4\r\n", "output": ["5"]}, {"input": "10\r\n", "output": ["11"]}, {"input": "10000000000\r\n", "output": ["10000000001"]}, {"input": "1234567891\r\n", "output": ["617283946"]}, {"input": "7509213957\r\n", "output": ["3754606979"]}, {"input": "99999999999999999\r\n", "output": ["50000000000000000"]}, {"input": "21\r\n", "output": ["11"]}, {"input": "712394453192\r\n", "output": ["712394453193"]}, {"input": "172212168\r\n", "output": ["172212169"]}, {"input": "822981260158260519\r\n", "output": ["411490630079130260"]}, {"input": "28316250877914571\r\n", "output": ["14158125438957286"]}, {"input": "779547116602436424\r\n", "output": ["779547116602436425"]}, {"input": "578223540024979436\r\n", "output": ["578223540024979437"]}, {"input": "335408917861648766\r\n", "output": ["335408917861648767"]}, {"input": "74859962623690078\r\n", "output": ["74859962623690079"]}, {"input": "252509054433933439\r\n", "output": ["126254527216966720"]}, {"input": "760713016476190622\r\n", "output": ["760713016476190623"]}, {"input": "919845426262703496\r\n", "output": ["919845426262703497"]}, {"input": "585335723211047194\r\n", "output": ["585335723211047195"]}, {"input": "522842184971407769\r\n", "output": ["261421092485703885"]}, {"input": "148049062628894320\r\n", "output": ["148049062628894321"]}, {"input": "84324828731963974\r\n", "output": ["84324828731963975"]}, {"input": "354979173822804781\r\n", "output": ["177489586911402391"]}, {"input": "1312150450968413\r\n", "output": ["656075225484207"]}, {"input": "269587449430302150\r\n", "output": ["269587449430302151"]}, {"input": "645762258982631926\r\n", "output": ["645762258982631927"]}, {"input": "615812229161735895\r\n", "output": ["307906114580867948"]}, {"input": "0\r\n", "output": ["0"]}, {"input": "349993004923078531\r\n", "output": ["174996502461539266"]}, {"input": "891351282707723851\r\n", "output": ["445675641353861926"]}, {"input": "563324731189330734\r\n", "output": ["563324731189330735"]}, {"input": "520974001910286909\r\n", "output": ["260487000955143455"]}, {"input": "666729339802329204\r\n", "output": ["666729339802329205"]}, {"input": "856674611404539671\r\n", "output": ["428337305702269836"]}, {"input": "791809296303238499\r\n", "output": ["395904648151619250"]}, {"input": "711066337317063338\r\n", "output": ["711066337317063339"]}, {"input": "931356503492686566\r\n", "output": ["931356503492686567"]}, {"input": "234122432773361866\r\n", "output": ["234122432773361867"]}, {"input": "1000000000000000000\r\n", "output": ["1000000000000000001"]}, {"input": "1\r\n", "output": ["1"]}, {"input": "2\r\n", "output": ["3"]}, {"input": "7\r\n", "output": ["4"]}, {"input": "63\r\n", "output": ["32"]}, {"input": "24\r\n", "output": ["25"]}, {"input": "8\r\n", "output": ["9"]}, {"input": "15\r\n", "output": ["8"]}]
100
100
100
[{'input': '712394453192\r\n', 'output': ['712394453193']}, {'input': '760713016476190622\r\n', 'output': ['760713016476190623']}, {'input': '2\r\n', 'output': ['3']}, {'input': '269587449430302150\r\n', 'output': ['269587449430302151']}, {'input': '335408917861648766\r\n', 'output': ['335408917861648767']}]
[{'input': '711066337317063338\r\n', 'output': ['711066337317063339']}, {'input': '520974001910286909\r\n', 'output': ['260487000955143455']}, {'input': '1000000000000000000\r\n', 'output': ['1000000000000000001']}, {'input': '3\r\n', 'output': ['2']}, {'input': '760713016476190622\r\n', 'output': ['760713016476190623']}]
[{'input': '99999999999999999\r\n', 'output': ['50000000000000000']}, {'input': '779547116602436424\r\n', 'output': ['779547116602436425']}, {'input': '354979173822804781\r\n', 'output': ['177489586911402391']}, {'input': '269587449430302150\r\n', 'output': ['269587449430302151']}, {'input': '349993004923078531\r\n', 'output': ['174996502461539266']}]
[{'input': '2\r\n', 'output': ['3']}, {'input': '578223540024979436\r\n', 'output': ['578223540024979437']}, {'input': '856674611404539671\r\n', 'output': ['428337305702269836']}, {'input': '520974001910286909\r\n', 'output': ['260487000955143455']}, {'input': '99999999999999999\r\n', 'output': ['50000000000000000']}]
[{'input': '10\r\n', 'output': ['11']}, {'input': '28316250877914571\r\n', 'output': ['14158125438957286']}, {'input': '919845426262703496\r\n', 'output': ['919845426262703497']}, {'input': '4\r\n', 'output': ['5']}, {'input': '578223540024979436\r\n', 'output': ['578223540024979437']}]
100
100
100
100
100
75
87.5
87.5
87.5
87.5
50
75
75
75
75
226
100
85
70
["^ &gt;\n1", "&lt; ^\n3", "^ v\n6"]
There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), &lt; (ASCII code 60), ^ (ASCII code 94) or &gt; (ASCII code 62) (see the picture above for reference). Characters are separated by a single space. In the second strings, a single number n is given (0 ≀ n ≀ 109) – the duration of the rotation. It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
fb99ef80fd21f98674fe85d80a2e5298
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 pigsoft */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, Scanner in, PrintWriter out) { String a = in.nextLine(); int n = in.nextInt(); String cw = "^>v<"; String ccw = "^<v>"; boolean iscw = false; boolean isccw = false; int id = 0; for (int i = 0; i < 4; i++) { if (a.charAt(0) == cw.charAt(i)) id = i; } id = (id + n) % 4; if (cw.charAt(id) == a.charAt(2)) { iscw = true; } id = 0; for (int i = 0; i < 4; i++) { if (a.charAt(0) == ccw.charAt(i)) id = i; } id = (id + n) % 4; if (ccw.charAt(id) == a.charAt(2)) { isccw = true; } if (iscw == isccw) out.print("undefined"); else if (iscw) out.print("cw"); else out.print("ccw"); } } }
["cw", "ccw", "undefined"]
Java
null
Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one): After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
[{"input": "^ >\r\n1\r\n", "output": ["cw"]}, {"input": "< ^\r\n3\r\n", "output": ["ccw"]}, {"input": "^ v\r\n6\r\n", "output": ["undefined"]}, {"input": "^ >\r\n999999999\r\n", "output": ["ccw"]}, {"input": "> v\r\n1\r\n", "output": ["cw"]}, {"input": "v <\r\n1\r\n", "output": ["cw"]}, {"input": "< ^\r\n1\r\n", "output": ["cw"]}, {"input": "v <\r\n422435957\r\n", "output": ["cw"]}, {"input": "v >\r\n139018901\r\n", "output": ["ccw"]}, {"input": "v ^\r\n571728018\r\n", "output": ["undefined"]}, {"input": "^ ^\r\n0\r\n", "output": ["undefined"]}, {"input": "< >\r\n2\r\n", "output": ["undefined"]}, {"input": "> >\r\n1000000000\r\n", "output": ["undefined"]}, {"input": "v v\r\n8\r\n", "output": ["undefined"]}, {"input": "< <\r\n1568\r\n", "output": ["undefined"]}, {"input": "^ v\r\n2\r\n", "output": ["undefined"]}, {"input": "^ <\r\n1\r\n", "output": ["ccw"]}, {"input": "< v\r\n1\r\n", "output": ["ccw"]}, {"input": "v >\r\n1\r\n", "output": ["ccw"]}, {"input": "> ^\r\n1\r\n", "output": ["ccw"]}, {"input": "v v\r\n927162384\r\n", "output": ["undefined"]}, {"input": "^ <\r\n467441155\r\n", "output": ["cw"]}, {"input": "^ >\r\n822875521\r\n", "output": ["cw"]}, {"input": "^ <\r\n821690113\r\n", "output": ["ccw"]}, {"input": "^ <\r\n171288453\r\n", "output": ["ccw"]}, {"input": "^ <\r\n110821381\r\n", "output": ["ccw"]}, {"input": "^ ^\r\n539580280\r\n", "output": ["undefined"]}, {"input": "^ >\r\n861895563\r\n", "output": ["ccw"]}, {"input": "v v\r\n4\r\n", "output": ["undefined"]}, {"input": "^ ^\r\n4\r\n", "output": ["undefined"]}, {"input": "> >\r\n4\r\n", "output": ["undefined"]}, {"input": "< <\r\n8\r\n", "output": ["undefined"]}, {"input": "v v\r\n0\r\n", "output": ["undefined"]}, {"input": "^ <\r\n11\r\n", "output": ["cw"]}, {"input": "< <\r\n4\r\n", "output": ["undefined"]}, {"input": "< <\r\n0\r\n", "output": ["undefined"]}, {"input": "< v\r\n3\r\n", "output": ["cw"]}, {"input": "^ <\r\n3\r\n", "output": ["cw"]}, {"input": "^ <\r\n7\r\n", "output": ["cw"]}, {"input": "< >\r\n6\r\n", "output": ["undefined"]}, {"input": "v >\r\n3\r\n", "output": ["cw"]}, {"input": "> >\r\n300\r\n", "output": ["undefined"]}, {"input": "> >\r\n0\r\n", "output": ["undefined"]}, {"input": "v <\r\n3\r\n", "output": ["ccw"]}, {"input": "> >\r\n12\r\n", "output": ["undefined"]}]
100
100
100
[{'input': '^ >\r\n822875521\r\n', 'output': ['cw']}, {'input': 'v >\r\n3\r\n', 'output': ['cw']}, {'input': '^ v\r\n6\r\n', 'output': ['undefined']}, {'input': '> ^\r\n1\r\n', 'output': ['ccw']}, {'input': '< ^\r\n3\r\n', 'output': ['ccw']}]
[{'input': '^ ^\r\n0\r\n', 'output': ['undefined']}, {'input': 'v <\r\n1\r\n', 'output': ['cw']}, {'input': '^ <\r\n3\r\n', 'output': ['cw']}, {'input': 'v <\r\n3\r\n', 'output': ['ccw']}, {'input': '< ^\r\n1\r\n', 'output': ['cw']}]
[{'input': '^ <\r\n3\r\n', 'output': ['cw']}, {'input': '^ v\r\n6\r\n', 'output': ['undefined']}, {'input': '^ >\r\n822875521\r\n', 'output': ['cw']}, {'input': '^ >\r\n999999999\r\n', 'output': ['ccw']}, {'input': '> >\r\n12\r\n', 'output': ['undefined']}]
[{'input': '^ >\r\n861895563\r\n', 'output': ['ccw']}, {'input': '^ <\r\n11\r\n', 'output': ['cw']}, {'input': '< >\r\n6\r\n', 'output': ['undefined']}, {'input': 'v >\r\n139018901\r\n', 'output': ['ccw']}, {'input': 'v <\r\n422435957\r\n', 'output': ['cw']}]
[{'input': 'v v\r\n4\r\n', 'output': ['undefined']}, {'input': '< v\r\n1\r\n', 'output': ['ccw']}, {'input': '^ >\r\n999999999\r\n', 'output': ['ccw']}, {'input': '^ <\r\n11\r\n', 'output': ['cw']}, {'input': 'v <\r\n3\r\n', 'output': ['ccw']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
227
100
100
100
["4\n1001", "1\n1"]
The first line contains integer number n (1 ≀ n ≀ 100) β€” the length of string s. The second line contains the string s consisting of characters "0" and "1". It is guaranteed that the string s is correct.
ac244791f8b648d672ed3de32ce0074d
//package codeforces; import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int len = sc.nextInt(); String str = sc.next(); if (len < 2) { System.out.println(str); } else { String[] str_char = str.split(""); StringBuffer sb = new StringBuffer("1"); for (int i = 0; i < str_char.length; i++) { if(str_char[i].equals("0")){ sb.append("0"); } } System.out.println(sb); } } }
["100", "1"]
Java
NoteIn the first example you can obtain the answer by the following sequence of operations: "1001" "1010" "1100" "100".In the second example you can't obtain smaller answer no matter what operations you use.
Print one string β€” the minimum correct string that you can obtain from the given one.
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".You are given a correct string s.You can perform two different operations on this string: swap any pair of adjacent characters (for example, "101" "110"); replace "11" with "1" (for example, "110" "10"). Let val(s) be such a number that s is its binary representation.Correct string a is less than some other correct string b iff val(a) &lt; val(b).Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).
[{"input": "4\r\n1001\r\n", "output": ["100"]}, {"input": "1\r\n1\r\n", "output": ["1"]}, {"input": "100\r\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100\r\n", "output": ["1000000000000000000000000000000000000000"]}, {"input": "100\r\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n", "output": ["1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"]}, {"input": "100\r\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n", "output": ["1"]}, {"input": "100\r\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111\r\n", "output": ["10"]}, {"input": "1\r\n0\r\n", "output": ["0"]}, {"input": "8\r\n10101010\r\n", "output": ["10000"]}, {"input": "2\r\n10\r\n", "output": ["10"]}, {"input": "3\r\n111\r\n", "output": ["1"]}, {"input": "5\r\n11100\r\n", "output": ["100"]}, {"input": "2\r\n11\r\n", "output": ["1"]}, {"input": "3\r\n110\r\n", "output": ["10"]}, {"input": "50\r\n10010010000000000000000000000000000000001000000000\r\n", "output": ["10000000000000000000000000000000000000000000000"]}]
100
100
100
[{'input': '8\r\n10101010\r\n', 'output': ['10000']}, {'input': '5\r\n11100\r\n', 'output': ['100']}, {'input': '100\r\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n', 'output': ['1']}, {'input': '2\r\n11\r\n', 'output': ['1']}, {'input': '1\r\n0\r\n', 'output': ['0']}]
[{'input': '5\r\n11100\r\n', 'output': ['100']}, {'input': '100\r\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n', 'output': ['1']}, {'input': '100\r\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111\r\n', 'output': ['10']}, {'input': '2\r\n10\r\n', 'output': ['10']}, {'input': '3\r\n110\r\n', 'output': ['10']}]
[{'input': '5\r\n11100\r\n', 'output': ['100']}, {'input': '100\r\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n', 'output': ['1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000']}, {'input': '100\r\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100\r\n', 'output': ['1000000000000000000000000000000000000000']}, {'input': '3\r\n111\r\n', 'output': ['1']}, {'input': '1\r\n1\r\n', 'output': ['1']}]
[{'input': '8\r\n10101010\r\n', 'output': ['10000']}, {'input': '100\r\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100\r\n', 'output': ['1000000000000000000000000000000000000000']}, {'input': '100\r\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n', 'output': ['1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000']}, {'input': '3\r\n111\r\n', 'output': ['1']}, {'input': '2\r\n11\r\n', 'output': ['1']}]
[{'input': '100\r\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100\r\n', 'output': ['1000000000000000000000000000000000000000']}, {'input': '1\r\n1\r\n', 'output': ['1']}, {'input': '4\r\n1001\r\n', 'output': ['100']}, {'input': '100\r\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n', 'output': ['1']}, {'input': '100\r\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n', 'output': ['1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000']}]
100
100
100
100
100
100
91.67
100
91.67
100
100
83.33
100
83.33
100
228
100
96.668
93.332
["3000"]
The only line of the input contains one integer n (1 ≀ n ≀ 1018) β€” the prediction on the number of people who will buy the game.
8551308e5ff435e0fc507b89a912408a
import java.util.Scanner; public class Divisibility { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double a = sc.nextDouble(); double ans = Math.floor(a/2520); System.out.printf("%.0f",ans); } }
["1"]
Java
null
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
[{"input": "3000\r\n", "output": ["1"]}, {"input": "2520\r\n", "output": ["1"]}, {"input": "2519\r\n", "output": ["0"]}, {"input": "2521\r\n", "output": ["1"]}, {"input": "1\r\n", "output": ["0"]}, {"input": "314159265\r\n", "output": ["124666"]}, {"input": "718281828459045235\r\n", "output": ["285032471610732"]}, {"input": "1000000000000000000\r\n", "output": ["396825396825396"]}, {"input": "987654321234567890\r\n", "output": ["391926317950225"]}, {"input": "3628800\r\n", "output": ["1440"]}, {"input": "504000000000000000\r\n", "output": ["200000000000000"]}]
100
100
100
[{'input': '314159265\r\n', 'output': ['124666']}, {'input': '2521\r\n', 'output': ['1']}, {'input': '987654321234567890\r\n', 'output': ['391926317950225']}, {'input': '1\r\n', 'output': ['0']}, {'input': '1000000000000000000\r\n', 'output': ['396825396825396']}]
[{'input': '718281828459045235\r\n', 'output': ['285032471610732']}, {'input': '3628800\r\n', 'output': ['1440']}, {'input': '2521\r\n', 'output': ['1']}, {'input': '3000\r\n', 'output': ['1']}, {'input': '2519\r\n', 'output': ['0']}]
[{'input': '1\r\n', 'output': ['0']}, {'input': '3000\r\n', 'output': ['1']}, {'input': '2519\r\n', 'output': ['0']}, {'input': '1000000000000000000\r\n', 'output': ['396825396825396']}, {'input': '718281828459045235\r\n', 'output': ['285032471610732']}]
[{'input': '314159265\r\n', 'output': ['124666']}, {'input': '1\r\n', 'output': ['0']}, {'input': '3628800\r\n', 'output': ['1440']}, {'input': '504000000000000000\r\n', 'output': ['200000000000000']}, {'input': '1000000000000000000\r\n', 'output': ['396825396825396']}]
[{'input': '3000\r\n', 'output': ['1']}, {'input': '2521\r\n', 'output': ['1']}, {'input': '2519\r\n', 'output': ['0']}, {'input': '3628800\r\n', 'output': ['1440']}, {'input': '2520\r\n', 'output': ['1']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
229
100
100
100
["5\nabaca", "8\nabcddcba"]
The first line contains one integer $$$n$$$ ($$$1 \le n \le 500$$$) β€” the length of string $$$s$$$. The second line contains the string $$$s$$$ ($$$|s| = n$$$) consisting of lowercase Latin letters.
516a89f4d1ae867fc1151becd92471e6
import java.util.*; import java.io.*; public class code{ public static void main(String[] args)throws IOException{ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); char[] c = sc.next().toCharArray(); int[] d = new int[n]; for(int i=0;i<n;i++) d[i] = (int)c[i]; Coloring col = new Coloring(n,d); int res = col.get(0,n); System.out.println(res); } public static class Coloring{ int[][] dp; int[] q; int n; int[] c; Coloring(int l,int[] tab){ buildColor(l,tab); dp = new int[n][n]; for(int i=0;i<n;i++) dp[i][i] = 1; for(int i=1;i<n;i++){ for(int j=0;j<n-i;j++){ regle(dp,j,j+i); } } } void buildColor(int n,int[] tab){ int[] d = new int[n]; q = new int[n]; int cnt = 0; int l = 1; d[0] = tab[0]; for(int i=1;i<n;i++){ q[i] = i-cnt; if(tab[i]==tab[i-1]){ cnt++; q[i]--; continue; } d[l] = tab[i]; l++; } this.n = l; c = new int[l]; for(int i=0;i<l;i++) c[i] = d[i]; } void regle(int[][] dp,int l,int r){ dp[l][r] = Math.min(dp[l][r-1]+1,dp[l+1][r]+1); if(c[l]==c[l+1]||c[l]==c[r]) dp[l][r] = Math.min(dp[l][r],dp[l+1][r]); if(c[r]==c[r-1]||c[r]==c[l]) dp[l][r] = Math.min(dp[l][r],dp[l][r-1]); for(int i=l+2;i<r;i++){ if(c[l]==c[i]){ dp[l][r] = Math.min(dp[l][r],dp[l+1][i]+dp[i+1][r]); } } for(int i=r-2;i>l;i--){ if(c[r]==c[i]){ dp[l][r] = Math.min(dp[l][r],dp[l][i-1]+dp[i][r-1]); } } } int get(int l,int r){ return dp[q[l]][q[r-1]]; } } }
["3", "4"]
Java
null
Output a single integer β€” the minimal number of operation to delete string $$$s$$$.
You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase Latin letters. You may apply some operations to this string: in one operation you can delete some contiguous substring of this string, if all letters in the substring you delete are equal. For example, after deleting substring bbbb from string abbbbaccdd we get the string aaccdd.Calculate the minimum number of operations to delete the whole string $$$s$$$.
[{"input": "5\r\nabaca\r\n", "output": ["3"]}, {"input": "8\r\nabcddcba\r\n", "output": ["4"]}, {"input": "1\r\nx\r\n", "output": ["1"]}, {"input": "500\r\nbbababaabaabaabbbbbbaabbabbabbaabababababbbbabaaabbbbaaabbbbbbbabababaaaaabbbbabaababbababbaaaaaabbaaabbaabaaababbbbbabbaabaabaabbbaaabaabbaaabbaabababbaaabaaabaaaaabbbababaabbbbabbbbbababbbaabaabbabaabbabbababbbbbaababbaabbbbbbbbaabbabbbabababaaaaaaaaaabababaaabbaabbbabbabbbbabbbaabaaabbbaabbabbbbbbbaaabbbabaaaaaabaabbbabbbbaaaabbbbbbabaaaaaaabbbbbbabababbaabbbaabaabbbabbbbaaaabbbbbabaaababbababbbabaaabbbbaababaababaaaaabbbaabbababaabaaabaaabbbbbabbbabbaaabbbbbbbaaaaabaaabbabaabbabbbbbbbbabbbab\r\n", "output": ["121"]}, {"input": "500\r\nccacbbbbbbbccbccbccbacbabcaaaabbcbcaabbababcbbcbcbbcbabbacbacbacbcaccccaaccbabcbbbbccbbaacbcbcaaabbbbbaaabbabacacaabcaababcbbcbcababbbabbaaaccbcabcabbbcbcccbcbcacabbbbbacbcbabbcbaabcbcbcacacccabbbccacaacaaccbbabbbaaccabcaaaaacbbcacacbacabbccaaaccccaabbaacbabbcbccababbabacabbcacbcbaaccbcaccabbbbacabcbccbabacbcbaaaacbbcbccacaaaabacaabbaaccabacababcbcbcacbcccccbbabbccbaabcbaaabbcbacacbbbbabbacbabbabbaacccbaababccaaccbaaabcaccaaacbbbcaabcbcbcbccbbbbcbacbccbabcbbcbbbabbcbaccabacbbbabcbcbcbbbacccbabab\r\n", "output": ["174"]}, {"input": "500\r\ndadcbaaaabbddbbacdbabdcbcdcabacbddddbaabacbcabdccdcdadcbabdbcabcccbdcabdcaacdbabdcbbbdbacdddaaddccbacabbdbbcbbcadcdaadcababbbacabcdbbbadbdacbcddbccdbacbddbdababdcadbbabccbcdcccccadbbdbdbdcbcbdcddaacdababdddacadaddcdcbaabaddaadacbaadcdcacbdcbaddddbdbddacaadaaaaabdccccbccbcabddbbcaacadccdbcccdcdbbabbcbabdbccdcdbcbbadaaadddcbcbbbabbadcddbaaabbbdabbcbcacbbaaaddbcbaccaaadcdbcdbbbbbcdbbbcdadacdbcbbaaddbdabcbccabbadadbbbbdccacbbbacacadbcaadbccdbadacdaddacddcccbcbdbdbcbdbdaabdcdabbaadcdccdbdcccadabdbddd\r\n", "output": ["196"]}, {"input": "500\r\neebcacaadebcdebdeaaaceaabacabbaadaadebbceeabbdbdbaaeababdaeddabbeebccbcbbdbdecececebdcceaddbbabbcdadcacecedaabbeeaaddbbddddddadcaeeebabeaadbaabcecadaabbabcbeadbdaabebeeadbadcaadbecdcecaeeebeebbececdeddbdcdccacaeccbdcbbeeeedeabdceaaacdbbddaceccbeaedbadcebebdceeabadeceeedecaaeedeebabdadcaeabdadaeabcbccdacbabcacbcaeadbacbddbcecddebeabbedbcadeeeaebabbeccdbadceccaeecdaccccceeccbebabaaaacedaadbbaddacbaedccabeaddbedaadacedacdbcabddbeaaecaebddecddacbbceebeacadeeaadcbdcbccbccdcddabdcecaebadccccaeadddacbe\r\n", "output": ["217"]}, {"input": "500\r\nbceeccdebbecfffabeeeeaceaaeeecccfcafeefdadfbfceaacceacabefbceaaeefabaabaabcefdcdccabeddbdabebcbdfdbbfcefffcccedbbfbcbafcabaddcdfecedfdeafccbfbbabaabaccadfcaccdbdbbbacfcebebcadecabdfcefddffbffabbaaddbccdaadeadefebcdfefddceefcdeefbbeeebdcaacdcfafcdbadbaeadcbfbbcaacdeacbceddefebbaddbadaeebefcffcecbacfeabebfbeabdfbefeeeaaeebcdfecedecdeeeefcaeaeffcafcecedddcbbffbeaadfbfcccfbeacfddbbfccbafdfccebbbfadebbceedfafcbffbacafdbcaabdbcfdceffbbdbceaefcabfbbeedffecaafccaafbeadaaabedccfcecceebebfdfcbedaddfeefcea\r\n", "output": ["228"]}, {"input": "500\r\nafdfdcfebagfdcdbacdeggffebbcgfdbeeeegbgagaccbgegdfbffdbfaaeabebcgcabdebdeadbggadffdedfgadbdcdeacffebbceefedbeabeaefdcgddaccfaagcaedgdcfeafaaadfgcgcabdddgcccbbaeccgbfefaggabddeaffbaabadfbddcdafcfdaedbdfafgagddgdgdfdabbceddfcffafbabefeadecccadebbbfeegbfdgbbaaffgeaagegbbeddfbfeeecdagbfacffebbbfcfeffbcddaaecadfdbegfacbfeeggdbacfgecfbgfdfacffebfabddebgcdfdaacdedgeggdbaadagebbdbfdcbbbbbfabafddebfaffacffccdbccedbaadbdcgbedbddebbcadfbgdgfagffgacgeadbdgedcccgbcecadgbdcafbffggcccfffbffaefdbcdgdeefceceaagd\r\n", "output": ["246"]}, {"input": "500\r\ndbcbdhbacghbacfeaecddchgffchhbhheacheagadabedhfcgfbgfahgebdgdecfgeaggebahhbhaaeagdhbadegebdfbededdffdfcbebhchgahafdegbbhhgaecadcdhaecbbceaefbadgedfhgfdaeheeeabbehbeddhdgdhbegefdffdbeebdegdbefbadbehacecdaedbeeedehfhddeggdafaagehefcefbghadhbehgbdehaeaeeecbbagbdefafhcgffgcfeefehgddgggbegcaabcfehcdbfcbbccheeafebdfageefeafafhffdaadcddgbfaegafbhafdbhfgebaaebegcddgcadddfgfcddggbdffffhghcbghbhdcebeacagbdfadhdbghaeacadbccbbebhfeeaghgebghbabbfhcdfagccaadhhgdeechghceefaaeacheedhbdaedcffhcgfeagdgfdchghbbfbf\r\n", "output": ["261"]}, {"input": "500\r\nahecidbhaccbabcggeceaebgcbaeagehfhgiebafdcgiiehegggcdfbdccicbfficggabdhfihheadafdcccbbgbgfgehchdbihdidddagdafigbbbhgaiagiacbhhegdgchcfiabbiidhhfbabdfehcifgegieihfibheedfbiadbfdafdgbehfeifgcfhieiaheebeiiabggbecedchhicfeccfadhbfgahefdchibaecbifeadfdadfefifeibcbbibibbcchadbbbedcbgeiefdhedddedhfeecfafggghdffbcgigigeeieeafgciececicgeegafbcdahighgahgdeahfhfebegebfedfdfadiafdcdebgeacedeiecdcaghibhedaaecdaahdaecdbahcfchebiafcfhacabcgbaadibgfgbdcebifdafbgabageebfeebefhffdcdgehgfchiabfabcbefhccehffibaeiac\r\n", "output": ["273"]}, {"input": "500\r\ncachgdaghedbbfbcbicbabfcahhbeaafeaafgcaafcabeabccbbbjhjbjcabcfdcbjedeaijeebcabbfaiicebgfbchcaeachceigihhbifcdgdfhdjabjajfhhfajddghebbdiegadfahdahddfdeaagjfgafhjhfbeehbgahgeefggdgdcfcifagibijcgifehjccfggajjfajecbffdedfhgebfefibeiceigcddfjhgcghbbhjbhficggfighjdijjefcjchdihgfdcjgeeeiicihfdhbibijhgjdgdhcafdaafbfgjgcggidgebchbejiidjgbfcbcjejgfgeiaaebeajhdaijhgbebeefchahbbgcgegieagcdahgdfbidehbfafbigadjdedhdhaegbbcgifeahgchiafffjgfgaajjhedbiffbbjdijehdfiegiabeadfcifcbjjhidiieebaiffdjfhfidffgfchchegjed\r\n", "output": ["281"]}, {"input": "500\r\ndffchafckjeihjicjdebhahafcdcbbghebdedkdgihgdeddjijdadgaggfciedejdgicbjjjidfbfjecabddaggidbfaadbhcgddagkcdbhdakceidkaekefhcdjgadefidfjbcejeeghbaffkabeejidkkcdfkijeiehiedfacjbhbahkckidjdekbgkdfjkibhahegghbdaggcejbkkgkiaibbefjfkgfghikifaaeekjafdcgefibgfdhahicfidbgbcebfekjkikekjdedieiifddgcfekaifabgafahegkhjfjdjjefbebcigikafjcbcijbjfkdbiaaibbjejehhacejakikjfebabjffhcgikbcedhdefkakibdjbekdkdbhfaafcigahbabcjibbgkaikkagakakbcahfkgjfjiccicchggagifajggckjckffdaehdejfihcdkjkcahakibfbakhheiacgkhbhhbjjkcbke\r\n", "output": ["294"]}, {"input": "500\r\ndkhedelgflihgabkcjkjdjggkfahheklbffhaidljfikfjgbckejfahehkiieflelcifagakijiajjhhdglhibeaagehkiihcjgijlfdaejaacehejbilefhgijeebfefgbccfgdebkledbjbjilcggaiekacehlikekdcebeidhfbdgkahifgilhcdbikbfdlheefgbebikfcbihjlliegabgfjlbdallhjgdahffcdcblbjekfijalefkaklfglggaikcacllhdcfilbkbelcfdgaafahhdkcjgafddhfaijakffdhfafbgfhlaccbhjlaeaaajfaagdhfehdiflehghfiidjcachclgddkkgkllcdldekgflakgalekefffakklgjejjlfjblkjilhfdckahbedeckhfefkfjlgaflffgfkkhacchgjceelechdceehfhjbecgiflajlechkldhjgbeeijbadikbhiddjjbfficfa\r\n", "output": ["300"]}, {"input": "500\r\nghgbegjdahcmgdjgmbaehhgmmlbjgigielfbddkhfbfgbgcmdfekcaeejgidledgcghicgmmblbaljhgggkimcagblckjkimcglahiambbccefkbmlmdgmkglfdmjdflbfdbekmjbghjjikjgkmeigifllmmgijkcclgjkmcahdjgkcekeagklgfhgidbedbgkgkmbjbkbdhiijjbkcdeallkjmjfldamkcmiijmgfkmhkhcgggfbhldjehbmmebkfeibhimddigfbgflifgmcdhmhjcfcmijjeaaegagcikmglclcblacjfclghgfkfaflhggjdmdjlcheehfhekcbdfkihgfjgakjbaihdmkhjfcfhfbeeifaghmmhiijaeglkackhllehlmmjklcelggahhlilgmbemkkjdcmhakbfgjdakhgekhcddmafkidefbffjdcmcidjmllkeedgiikjdlggigchgckdijhjgfmmfekmdcm\r\n", "output": ["303"]}, {"input": "500\r\nfnfckgnagbnmhglkdliekejfciahennmjahibikiimkdfcblgcgegenjeaaiddhehkdemeibehbbnahfkdbhkddbgjamfakhgjefljbfnegkgbldkknmmlailkjmmimnfgnccghgnnemignlmnedminddglamlllaekjgjnfcjiaafgnmheedlknlgacebdkgccgkchjhacbbiddjhjhgdkedbcfnaniaaimibgkkdgmnegiandbdmnchehkcidfegaakndccljlganndfbnkenmgcflhammgiggcfmdcjnmncdgfaejaadelhjemekdnlbklcfjaeblhgbccjgechgniedfngfhjidjgangcfabnlblmiadabeeahfdfjhlkfmecnddbhcjgkjfejemfilhdcihfcenmbmblijkiilndnkafdejjnlgnadcllinjnfkfjnbleljledmjbleihgdicmcefaihhbmhnejmcieamkhebme\r\n", "output": ["314"]}, {"input": "500\r\nbfdalabnagjcojejahgifmbmgokfmmbnaflhbiiijnaidocachemkknjdbohmkciconnnigiciclgldngikjbmodfdfhegkcemlgngiadeffhliacnonnadnblkmmmbkicdemnjibokljonefjahllbkeaaecboadjfhnkhmmalnjfdmmkmjnabojdmfhelnkaehoaiojeajjahlhakikimbobejoeagkhcnadjogjocngaddbfekecokdhcjehenfegjjelekfjolajeibmaodkagkgfnjfinfgdcknbmgemobehekdcclmlfnkmodogedmhaieojgigklajkabjhcgldagaifoaggbibjajgilahejjcoaocncgmnefcglkjledcdcjehlondnilbnojikmomlfdagoaobmekadabiblijldngammojgkgjojhoanfclimkebkfdmoigjkmcnfmmddiahakdjdngffgdjaaklkecgj\r\n", "output": ["321"]}, {"input": "500\r\ndicdkeichmcjhbnkiglmnephogelfohjboiihaocmpaemlmbgjdaoblkkomngcelapdlmophamcnjihpfhadhaddhbinpinepkcnjpndfeiepiocepbdjchcenilbaccopfnpciglfcknjbmdbhcdgihbeniklehnonlnhooabbodnbmdoaafnedpffdnibdnijidpbngidabdncdfolpfnenbcmhhlenmjcbiacmilahlfpdgafcacnlgedkicmnknliemncdgoggjcdbhnmneljgjjemekndgdhddoiiflndklehceancaiadnicdoofciodhgphjgmchkehailolkhfbpdkoipcemoghegbbpedaafbeloccmgddphefjakjofldineohdgflhflmkiedfmkocbjablcofcmdfconlmhoiehlobdbfpelhaindhamnmbenldbmefgkmhjlloeendgdbeafncjohclenmdeppemplf\r\n", "output": ["331"]}, {"input": "500\r\nkjcllbkmamlbogkopfqhjfpejfeglpbdqjikbgakecolabphkmpnjfbhpdnlcqcfdaljmegiljlqpkdnomcglpkbaiencimbkehpiqmpafeabbohfajahfablplcpacngfpghjdhbonglhaedpihkbjbkcpjdkqkpdobjfqepolgdgjonaogkingfmacbflbmjhhjbnnffbmcohgmmfbjqojnocjlfhlhflpkddmiijomenhldcoijnqcomjnbbpnffkgelnigkcmnaqdnkpmoejllkilfdlqoqcbmbqdaobndpgjkffebhgmfclhncalfeamiqhclllpoefaaobhqfnljloimkdoaggjammqliommkllnhhqoagcpmlkddkclokjlccgfapodfolmfejdkofqncjkjhqcledaplificibodhddlhmqqckjenpjalokpllnldqppjceelgjbjqqqlcecjcjmkiklbbdikblddkikpfea\r\n", "output": ["325"]}, {"input": "500\r\nbfhofhrkimdpgpnjhelnqlgbjpddbanmdfqciedrdgednbjjinlmbormkckfcqghoibpcadmnigckajnklngnmpoaiaepajkhegipdadoipgmcncncbhcjkhfechneecqmchnqgpaqkrhipgnqcojhaliokihgqbadmkkcffkeorbjorqbbojiqlpdlohbmhmlmliadlbrpcdmfckfgdqcpflghdfkqceminjlollkbmqreeilffqigjelerjpiakllbgiogqdpkochbjpnppagaooqdgocnnrpkeiekhkibrfjdbkfmlnmbgejcfklgnaacrpnhakkpinnolnbikcrqlgfhcoqpaainlklpamdeapnqpcgflfnlgkpcicdbiodgdngaeaanbjhnfbgogclpherrqodalbbpjkfiohpqngmfialgdejlgddkqrhgnblbqkamajnehebbnkcrlhnrnlcoondjhhnghecmlqfogbiaggkl\r\n", "output": ["335"]}, {"input": "500\r\ncdmkfpciphakoplkedblrkgkeopflkqhokgfiehpjdbbjidapefhognhgheikdbaepqasmfdsbkdbbjaesoikmglimmabfbsreakbpnhsclohfbaqamjlhhaiqchpoaibqldehsprprscrinsdgrlsmidkdhbsgqnlhlbldrnqhgfhmcsmncqmohkcbkgnbrofccliqjpqdpesfnabndkkklmoemsfksqmjajbgheijcgjiinppnpqlilarocbphlogqrmcheflskedeomfsjkoojfjsdoibiadoeickchjhssjaqhsnbnahqcqnelemollsncrfhjrngeighcqirbphqharlgiblchqjgblkfemlhofrjjceeerolsndsncjksanpkcqiopkmqmlfginppbhkbbdshpbjblheolofkpcjjeedholrqklhiiohmdjbbseclssdlcbkjribjggfggsljidsngsgjpankfckidrpsjsgaq\r\n", "output": ["335"]}, {"input": "500\r\nfpkfjphbmbqmikncnatbjfldpcohbgamfjrceshfgffllbjcrkeemqboblbjtsgqbeplcrkstcginnjqqolijjbbcnabagheaaisdoiieesogomilkcookbsgebbbmqssrbgdmblmmccgeciaeiasbatraotjlafhmjmddsldfqgfeqkrmkafqdlikttmdtkdmmosqgfflseiibjnahjqsmhcmklgqrqdbccegjeschpcdnbjscqoifipbrfillscdqpjfaippqaloqpdfcmtmjptchiipedetijorrolndnehtkfjarpfqphmmmbeeeomfbshkehesalaeccpgpolhncijsihhdloesfjherreaclrplrtcbsrlefqeksgtdnkmdfcklgskqqkgcndthpgdkitiataqosqdrtjmirsicnrbblofqfsqsdksngrkaefmgnpaaroelimcpnnibekhompicrocopcscfajqdbfpqcrrnlm\r\n", "output": ["326"]}, {"input": "500\r\nraqqhocfiosbkfjtbjnbatojfmummlrghpkmcghfagdmmkbesdhtelromtkmdmltiljttepgeqdlhtgkpgljrmqjjtmretsdincjjqilahapcjcdlkrftoaeramgrudjbtpjblaksjjjburngarjitmebjiotofctgppktkqkianmucafsspbefuijcmsqamuenlrfrunfhgfqjhkjgrdjrkjgbpifadsjabktgdsgjsslipnqncbdfaphfndssljbthhcrfoijilodnuosmirctsjbhtlbehnljqcjdahcmjqsursqemcmtbgdaegdugqskskfdcffuilthtnjfhujgpifckubajoorllaruqfmbgrcutjushbflsqeiqdddenhurmunhsqqnbsfnjhgdodhmdugisalahiiedmhcgudjfhuumtlndkneauikebmgnrbdmegeotncdllcmmqfudldikeasisllapabefdubasndtobm\r\n", "output": ["339"]}, {"input": "500\r\ndkftkjtfjdrrjnruuafncvesfngrsrmpmursvssubifcmaeivkrocrhkujbldcgvpifnttfgvrppjpfogmietujqnierfoflmqgbpgsqnagqjqhdjmejllchtldrtrcgemvcalcabieheheagnsmvhrdeeonfckgkuhciivibchbqmvbcdugvcbnqbujgeljqclunbgpguufqhletqstbeabcuncibkdkntbunnvquqshmkqmpbaoaujofaraipvjirvvggrnlvonqsehduohpauqetcujmgutoqigpuqijnevgmcmanalrvsaivueouviobdmucsljnfocsbvlrvmnoevhbpamqqcupcrbfdcerhchteersfjafuiekuchemvhctjfgsgmssfsanrcfjlvithppcqauuepopjolbojemvqfjhjfbiflmihnnkkgmaeecpeaascsasokudhjtkgclbomlbaicffhhlslseaaihlipgiv\r\n", "output": ["339"]}, {"input": "500\r\nfropdpoauqarcbsnlpkwtcpabgsvcsfltusgobcghdbioeivlddcdadaawjhnljgsfjnfdebgucqmhivqvcrlnmogjapkocfffhdbtqcwauhfmlkwcdutvfwrhdclsjuqwsrrwgquducmguvlralvnspclfsgdpqudmishuwqhvfndqjrdiekbopjwqnbldtgafoqewwkwmdmvdwokekrqbbqfejrhervtbgsualsneufmohsrhwcvwoudfpofbnsbvqoogbrjjhmjiatfpsrvjdiohwhgkrwjcskibimsnlsgogbutccwjedroqtgumopbkshhsllkrlklihjicfaivckdsijgnvuraoiiwdhnoimwfgbslfoehwpdrknljsediqvmtkkgpfneuvjucgkochhbtcvnjhgafrhdhrpjchbociesjfmtwnckbobjimtbrfebdoronmeatuhtafvtssficqnwgdslcvmbmvaodutmpotjc\r\n", "output": ["351"]}, {"input": "500\r\nnjjiptmrcggwwtbcxbmmiqrqdhhgciaskwustnvmbkbvghlcnrctbcjlepnkqcktsbxgjnvhmndnbqnmhwrlfijpimlojsmvfjidtcmujmnoihwhlronmmpeiobmoperdwsranlbtqgbktpdtbtihnwlsvfefrugurkjbvajxsovpuwjoohmvtdlarbeabmejbrkmkfjwbgsisvxfakjphpmrtmwwwktroitlmstbwuilftpwqmqtitwgkwbpiaueqopotnfxhchsoqqlvwqlogbooqnmpvvtxmtdqqkjwhifmvltxxbwjjgaxjkuuraneqrucchncusshrwxhhdukkexwjrxgufkgmiqblonthwtqulftphghltqcarvfhkknpqxftvqscspvosxvguskdmfdocxrrjvcskjhtxwomiwiqjemdklldgnkeuelcjuudmhokbihwpibicfbjjoqbbqnbqmcsdwdeiisqfvvoxggqeqcfs\r\n", "output": ["338"]}, {"input": "500\r\njqpyiogllhoobjixnlhskgwowfrhkuotvjbmgatrspqreavqwsuljxqduutxudueenmvarsmqqaqxohtsmxdqdhcvydhuiqcchvvxroqieeffipvlumywcthdafsgnwyamumpknqittxakhlbrbhrtcfbrkvjrypxqochjnmyihuqtrrbgiiytifqeqbnssrmywtdghpekqjxkvoefiwpbepqstotqyiohuawpvawephiexxnofiipkwmshhyaprhrryspbvfoasagdldqeasajhqsurmduuusiwgyuroimbyfjogkxcgjorxpqblhtwvlgognnvisqdkheurkikjcgmoyvafiqhfcbmgmybefsmkroftstqmhkfkuxufghjhveuhhkecushenjqyvqhxcfqdcbkxufhxpbamaowjnuaxjcsuuryvjtnwrhwiurrsehusxwrjwsotefacjxjanphxngylkmjbvhfqghtlnlvdbcnkfjd\r\n", "output": ["350"]}, {"input": "500\r\nlkuvqevrlanaugfoadmkdqpljknwfoftofyxcvsfvprqxuwkfwunfilaqrzqhsjhsaoynbsuiqyzwqfkmbddngwydhrtimoerqpehjsgqojuhtxvaayzsbxmsqckibtcangzdnnpcpqkqgzbzbeaejuhprrqxdhyfrtzwhvnnrfocwrwfzbgtvdpwlkrqisjqpszykzhfjrstcvmmnebwgvwxsppyxihkepmndwgtzlsurasjfrkqqnxjqdsbmsggakyuouevxdxuwyxbhkmvpjqvoklaknxsmzqpjrftvzifnqjporbvtpdnzfhckjnwgeddpjycnqrtphjhqkfvpoerzkilpjuteidflpulppotglglarrwopryxbjjsroguskwzalrmasgcioovteyuukwnosswdwnqmrbdkssgnkaivtufoayaxgqpprnoyvoeqqpywboofudtutiweaaqzbneqmxgnfkxdnjdbijlveapyrybiw\r\n", "output": ["358"]}, {"input": "500\r\nccbbbbaabaabccaabcaaccaabbaaaaaaaabaacccbcbccbccbbaabcbbbaacbbbacbccabbabacbcccbbaabbaaccbaacbcbcbabccbacbccccccbcbcbaaaaacabaabbbacabaababbbccaababbacbcbbacbbbbccbacaaccaaccbccbaacbcaaaaabacabbaaabcccaaacccabababbcbacaababcaabbcbacaabbcccccbccbaacacbcabaacbbababacabbcccbccccaababacbcbbaabaabcbaacaccbaacbbcbcbacbbbbabbcbbccabaabbaaabccabbbbbbaaabbbaabcabbbbbbcaaaabcbcbbcbbbbbbcabaababcabbabcacbaccaacacabbbbbcbaccacbbbcaacbbacccaabaababcbbacccababaabcabbccbbbabbaabacabcbabcaabcaacabcaaccacbcbbcaa\r\n", "output": ["161"]}, {"input": "500\r\ncccaaccbcacbacccbcccbcabcccaaaaaabbccbbbacbacaaacbbcbbacaacbabababcaaacbcacacbacccccccbcccaaabbabccbccbcaabbcaccbbbbbccabcacccabbcbcacbcabaccabcbacacbbbcbaabacbcbbbbbabcbcabbccbbabbbbaccacaacabcacbacaaacacbbbccbcbaccaabbbcbcacbaaacaccaaabccbbabbaaabbbabacbaccaabbbaaacbacaabbaaaacccabbabbbcbcacbcccbbacaccacbcccacabbaabbbaaabbcbacaaaabbcccbacbbbaacacccccbccabbbaababbacccabaaabccbbccbbbbccacbccbcbbbcacaabacbcabaaababbaacaccbbbacbcabbbcacbaccacbcabbbcccbabbabbcaacbcbcaabaaaccacababbbaacacbbbcbabbcac\r\n", "output": ["164"]}, {"input": "500\r\nabccacbaabaabaaccaaaacacbbcbccaababacbbbccbbcbcccabbccacbacbbacabbcbccccbcbbaccbcaacbacbbaaababccaccbcacaccccabbcbcbaacccbccabccaacccccccccbcabaacaaabccaaaabcccbcbbaabccabbbaaccbbcccbcccbabacbcabbbbccaaacaabcbabbbacacacbcaabbbacaaaaaaacbcabbcaccbcbaabacccacccabbbcbcbacccabcabbaabaacbcbaacbbccccbbbccaabcbcbbbccccccbbabcbabbacbaabaccabcabcabcbbabccacbbaacbcccbaaabacaaacaccbccbccaccccaccbbaabbaabbbccccbbcababcaaaaacbaabcaaccacbbabbbbcabbbbabbabbcaaabccacbcaccbbcabbaaababaaaccbbcccababacaabbccacccab\r\n", "output": ["161"]}, {"input": "500\r\ncbbbcababbbbbcccbcccabbcaabcabcaaacccabcbbbaacabacbbbcbbccbacbbcabbbacbbabcbccabbababcaabcbabcbababbbaaaaaabcbcccaaaabaaaccaacbcbabccaaaccabccaaabcaacbcaacccccabbbbabaacacbbaabcbcabaaabbbabababccbacbcbbcccbcabacbbbbccbbcacbbbccacacacabccacbccabbbabbabcccabbccbabccccbbbcabcabcccabbababcbcccababccacbaaacaabcbbccbbcccbcbcabbacbabacaccaaacacbbacacbccaaccbbcabcbcacabbaccaccccbacbbcacccacabccbabbbbcbbbbabccbaabbabcaaccbbbaccbacaccbbbabaacabbcbbbaacaacaabaacbcbaaccbbaabbcabbacbcaabccbbccbcbcabbcbcbaaca\r\n", "output": ["174"]}, {"input": "500\r\naacaabcbaaacbbaacbccbbaacbabbaaabcacbcabaaaaaacccbabcbbbacaaacabbbbaaacaacaacbbbbbabccbcbabcabccbbaabccbccacccacbcbaaaaaaababbccccccacbaccaabcaccbacbccbacccacbacacbaabcabbbcbcbaaabbabbbbbcabbabcbbaabbcacccaaacaaccbaaabaccbaabbbababbabbbcababbcbbaaacacabbcccaaabcccabbbaababbacbaaccbbaabbcabbbbcabcaccbcbcbbbcabccacbcabbaacabbccccaacbbbbaccccbcabccbccbccbccacabaabbbbcbcbacabccbbcbaabacbacbacaabbcacbcacccacbbbcabcccabacbabbcbbacabcbcacbaaabcccaaaccaccaaccbbcabbbbbccaacccacbcccaaccaccaabaabcaabaacaac\r\n", "output": ["163"]}, {"input": "500\r\nabaabaccacaabbcbacbbbbaaaaacabaaaabbcbcbcccbacabcbabbccbcabacababbbbccbaaccaaccbacbbbbaaabacbbaccabaacacacabcbbcbbcbacccccaccbbacbbcbababaccbbbabbcbcbbbaccbccbbbcccbcbbacacabcccccbbaaaabbbcabbcaaacaccbaabacacacccabcccbabcbbabbaabaababbaaacbccbacacbcaabacccbaacbacabbbaaccbcbbcaaaabcbcccbcbcacabbbbacbbcaccaabbbcaccacbaacbcccbbbbbaccccacabcccccaabccabacabaccbbbaabcaaccacacccbaabbabccbaabbbbbababaaabbbbbaacbcbacaacbcbcbaacbcaacbbcaaacccccbbbbabaacbccbabacabcccabacacacbcaaababcbbcbacbccaabcccaabcbcbc\r\n", "output": ["170"]}, {"input": "500\r\nbbacbbaacbcabaabbaaccbbbbccacabacabbaaabcccaacbaaaaaaccbaabaaabcabbacbaacaaaabcbacbcbcbccaaccacbacbcbbcaccbccbabacbaacacacccabaabbacbcaacacbcbacaabbcacbcaccbbcbbacabacbbaccababacbccacaababbbacbbbbbaccacbaabbccccbbababaaccbbabbbcaabbbaacccacbcabbacbabbcbbbbbbcabcaabcbbcabbbcaabaaaaccaaacaccbbbcbabcacbacbacbcabccabbccaabacabbbbacacbbbabcbacbccccabcacbbbcabccacabaabcabababbbcbacabbbbccabccaacaabbbbacabaabcaccbaabcbccbabaaccbbabbbbcbcbcbcccbbbbbbbabbaaacabbaccacabcabbbabbaabcbcabacaabcabacbbbaaacabb\r\n", "output": ["172"]}, {"input": "500\r\nccbbbaaaabaccacaccbbccabaacbbcaacbabaabcaabbaaabacbccabbccbbbccbcbccbababacaccaabbaacbcbccaccccccbaaabbbbccbacabaacbabbbccaabaccabbbaabaaacaccaacbbacbbaacabaccbaccbccabbcbcccacaccbaabcacbabbaabccbaccbcbcbccbcaabaacbbcaacabcacaaacaaccccbcaaaabaaabaabbbcbbbbaabcbcbbbacbaacbbbbbaacbcabccbcacaacbbcbcbbbacbbcacbbbbabacaccbaaaacaaaabbcbcbaaccabbacccaabbabbacbccbacbaabbabcaababaaaabaacabacbaabccbbccbababbbcbacbbbcabacccacaababbabbcaaaaccababbacaacbcbbcaccbcaabcbcccacccabaabaabbcccabcaccbbcbccccbcacbaba\r\n", "output": ["170"]}, {"input": "500\r\ncaccacbcaababbbacaaaacacbbcaccaaaabaacbbaaaabbbaacbbcbbaaccbcabccbbaabbbcbccbacabaabacabbbcbbacbbcbcbcacacbacbbbcccbaccccacaaccbcbcbccbacccabaaccaaabaaacbcaacccaaacacacbcaccbbcccabccacacabbcababaacbccbcbcabbabbbccbbabbbabcccbabcbababccabcaccbabbbbbcccacaccaabcbbbbaacbccccccabcccaacccbccbaabaaccbbbaaccbcacbcaaaacabaacbbaaacbcbcaabbbaccabbbcbacbbbabcbcccbccccbbcccacacbccaccacaccccaabcabcbbacccccbccbbbabbbbbbcbcccababccabaaaabccabaabbcbcbcabbccabababcabaabbabcccaabacaaaabbabaccbbacaacaabcacccbbcbcc\r\n", "output": ["164"]}, {"input": "500\r\nbbabcacccbcbbcaaacacabababbbcacabccacbabcacccbccbccbabbbbbbccbbaabcccacabccbaaccacabaabcabcacbcccbaacccaabcacacaacabccbabccccbbaababcccbacbcbaacbccabbbbacbaabaccccccababcababccaabcbaaacacaccccbaacaabaacbaccacaacccabbbcabababbcabbacbccabbaaaabcabaabbbbaacacabbabcbaccbcbbcaaaaaabccccacacaaabccbabacacbcbbccacbacbccaacabcccbabbccbbababbccabcccbbbacabcbabbbcbbcbaabcaccaccaccaabbccaacaaccabbabcbccaccbcbbbcabcabcbbacccbabcbababcbbcacbbbabbacbcbbbaacccbbbaabbcaaabbbaccbaabcacbccbacabacacaaaaabcbacacccaa\r\n", "output": ["176"]}, {"input": "500\r\ncbdcdcbdbcdbbcbdbddadbadddcdacdadbcaaaaddcadabdbabbcbbcccbbbbdbbccdcdcccdcdccaacaabacbdddddaaabaaacbbabdbcaacdabdaddacbdccddbbacabaaadddcdddadbdadacbccdabccadaacdadcbdaadacacbcdddbadcaddcbcbddcbcccacbbaacdcdbbdbbbadbbdbbbdacbddcbaccaccbaddaaaabbcdccccadcdcccbcbdbdcdcbddbacacbddbaacbaaabbbaccadcbbbacbacddbcbdbbcbcdbcdbbcdbcbdcdddbcbbbdbcabbdaaacdbdcdbccddbdababadddcdcabcbcbcccbcccdcaccacaddcabadacabbddaaabbdbdacccacabcaccddbbbcabcdaabdbddaaadbddccacbbcbccdccaaccbacacbcdbbcbccadcdabdbadbcabccddaba\r\n", "output": ["195"]}, {"input": "500\r\ncbbdbdadbadbddaaabbaadbcaadaaabcccdacdcbaabcbadbcaccdccbacacaaadcaaccacbcccacdbcdbdabbcbacbadbccadabccccaacdccdcdcdaccccddbabdaccdabbcbaaacacdacccdbcbbbccaccdaddbddddadabbcbbaabcbdcadbdbdaddabaaccabcaaddbdbacddddbbacacbacbdaaadcbacbcdacbbddbcbaddbbbabbbbcbdcaaabdaadbdbdbabcbcbcaaaacaabddbaacadcbbbacbdccbabbbcdbdabdbdaccadcccbcbbadadccacdcbacaacaaccaddccdacdbbbcadbcdcccdbdddcbccccabdadcaaabddddaabcaddcddaaccdcbacacaabacacbcadbadbbbadbbaccddcadaaabbcadabdcaabbbcbbaacadbacdacdbbcdaacadbdaacbabaacdd\r\n", "output": ["196"]}, {"input": "500\r\ncbcbcaadaddabadbcddbabcbbaabbcaabcdaacdabdcacacbadacaccdddacdbdbbbbcbcddbbbcccccbbcadbcacbdbccdabcdbdadbccbcdcdcdbdbddccbbdcbbabbcadbbaadbbbaadbbabaddddaddcacabbddddaacacbcbaabaaababacaddaacbcbdbccbbdcccbddbacacbbbbddcaadacccbacbbdbadccbacbbbbdbacdddbcdaaadcdbacaccddbddaaaaaddaabdccdacbbaacddccbacadbbbcacdbaacbaddcadddcbbccaacdccdabdcdcdccbadbdbdbcbaabbacbcbcbabddcadbdaaacacbdccdadccbacaadbccccdaadbdbccaddbbadccbacbccbddababbbdcaadbacdaaddababbcabcdacbddccbccdabdcdbcdcacccaacbacbabbcdcbbbbbcbaac\r\n", "output": ["196"]}, {"input": "500\r\nccadaaddabcadcccbbbcbdaacabcbbcdacaababdbbdccdcacccbbccccadcdcddaccbaaababbacadcabaacbccaabbbdbcbcbbacaaaaababcddadcbddcccbabdabdabbbacbccaccacdacadbbbbcaccccbdcccaabbcaacbcdddcdcdcbbdabadbadadcacdbbbaaaadbcbbabdabcbcbddaccabdadabdbbabcbdcdbdccababcbadbdcaacbddabdadcdbddbdcdabddbdaccadacabddccbbdcbacdbbcbcbdbabbcbadddacddcddccaaaaacabccccccbdbdccacdcaaaababccbbddbbaadacdcbbbadccaacaaccaabbcbabdcdccdcbbbbcdaccbbdccabcbdbacadcbdcdcccdaaccdddbbbcbadcccbacadadaddaabdbacbcdbaadbaaabdcbcdddbcdbdbacdcb\r\n", "output": ["193"]}, {"input": "500\r\ncccabbcdddcacdbdddddbabadacdcdabadbaddcbcaabddbaaaabcdcabbcccdcbdadbdcbadbaccdaccbcabbcbbcdcaacabbdcbabddccaaacadcdddaacaadcbbaabcbdcdacaddcabbcdadccdadbbacacbbaabaaccbabcbccdaacabaccaadaccdabacabbcbadddddaddaaabacdcbbddbbbcdabdacdadbdccbbccccbcbbabddadcadacabcbdacabbddcbcacbdbcccccbdbcaabbdbcbbdcbaccaabdbbcccadbddcdccbabcdcbbcbdadababcccdcddbadacbadbddbddacdadaddbaabbdcddcbdacbaabdcdacabddacabccacbcadabbadabcddaacbddbaabddabbcabbbbdbcabccdcdaccccdccccbdcbaaabdbddbdaabcdcdcdbdcbcdabaaaacaaacdbdb\r\n", "output": ["201"]}, {"input": "500\r\ncddcdcbddbbdaaaabcbacccdabaacbcaddcbbcaadcbdadbacdbbddccacbcbabdcbabcacccadbdcbcbbbaabcddbbcabddbabccddcbabdbdbbdbdaaaabbbaaccaaaabacddcdacdccabbcbbdbcbdcdcdbbdbcaabacaacdadbdccacdcddbabbcdcbdcbdbdcbdbccddcabdaddacddabcdcdaacbbaacdabcbccabacadabcdcdcdbbcccbcddbdacaaddadbbbcbcbacccacadcacdbdabbabccbbcaaadcabadaaadbbbdbdbbdcababadbbdcddbcbcddbdbaadbbbbcccbccdcaabbdbaabacabacdbcbcbbaacaacaabbadaddbbcbdcdcdcabbcdacdbcacabddbadccbdcbadbdddbdaccbcabdabddbddccaacdcbccadbdaddcabaadcccdddabdaacbaacadadba\r\n", "output": ["201"]}, {"input": "500\r\ncdbdadbdcabdcbdbaadacaacbbbbcdaccddbdbbdabccacbaacdbbdcbddadabaaccbabccabadddbdcdcdddbbcbadddcabcddcdbabacacbdbcaadacbbbdccbcabacdbcccbdccbaacddaaaabdacbdccbbbbcaabbbdabadadacabdbbaaacadcbaacadadbbdbcdabcdabccacbdcaadaccdbdcaccaaddacddccdadddddddbacaccdbbbbcbbabbdcacbcaacaabdddbdccdaddcddbbaabaabdbcccadcacbdacabcdaddaabcbcaadabadbdaacacacaaddbbbcabccdbbcbaccbadcddaaccdbacaabbcdbcbdbcbacacdccccabaaabbcbccdcaabcadcaccadbbbcccabbbcdbaccaabdcbcdbcdcaddaabcdacaddcccaddabcbabdcabbdbaaaccbbabcdaddbbccd\r\n", "output": ["194"]}, {"input": "500\r\ncddbcaadccbdacccccbbdcbbcbcbdccbbadbaadbaddabcaacabbcacdbaddaddcbabaaaddbacbdaacccbdcbbaccbdcdbdcdbcbdbacadbccacacdbdbbbaaadccbdabbacbdabdabcdccdcddcbdadbacdbbdacdbccddbbadadcbdbddcabdabcbbddcbdcbcdabcdabddcaaabdddbbcabcaacaddcaadddaacddcabdcacbacdbcbdbadbcdaddcdaaaadaadcdcaabbadbadddaabdbdbdbaabdbdcbdcadbbcbaddbcccddbaddcbccadccccbbbdcacaabcbbcbdbdaaaacddbdcdaadbdadbacdddbbbddacbcaadcddcbdbabcadcddbbabccddbadddabacbbdacbbbcbcbdcadaccddbbbadddaaddddcddabaccaddbadcbcbabdcdbcaaabcadaacaddbabddcaad\r\n", "output": ["202"]}, {"input": "500\r\ncaadabddbaacdabdbadcadcadbdcdaadaaabcdbabcadcbaaadcadacbabcddacaabcadcabaabdddbcbcadbbbdabdabacbccddcbcdacbacbadabdcbccacbcbcabdcdbcdacadaacaabbbabbddbcccdcbabbbbcbcaacbdadacbdbabbabcaacdacbadcccbadaaabdbcbdbdadbddcdbdbcbccbbadbaaddcaaddadaaaabababdbbaddbadddbcaabcadbcacccadbdaaabcdcdbddcbbbdadaadbddddbdbacbccdaaabbdccaabcbbbaadaccdcbccdcabdccccabbbbadddccadddcbdddaddbdcaccbaadadbbdcaabdcdaacadddadbbbdadcdcdcbbabdcdbdbdddababaaabcdcbdccabbcaabbccadcdbdbbcdbbaabadacdaccaabbdabdcdbabcdbcbdacdbdcbc\r\n", "output": ["204"]}, {"input": "500\r\nddaabdcccadcabacacdbaabacbaadcbcaadcbccabdbddbabacdaccbadaccabcddadccbdcbbacddcdccaccbddcbcdadadaabcacbddcabbaabbbdddccbdccdaadcbcabadbdccbdabacbdcacdcdacadcaaaaaaabaccccaaabcccbdabdaadbdcbaccabccddabdbabcbabbbbaccdadaaabdbdbcbdccddcdbabdaabbbcaadaaccbcbbdabbddaaacaddbbbccbbaacadcdbcbdddaaccbbcadbccccddbddbadcbcdbcbdccbcabacbabbddadcdabcbcdccddcbcdcaddadbccdbabaacddbcdbbcdcbcbdaddbdabacbdbcdbabbbcdcaabbccbabbabccdadabdccaabdadaadcdcddbbcbccbdbbbddacacddbdcdabcdaddcacdabacdacabbaddbadabcdabccbcba\r\n", "output": ["202"]}, {"input": "500\r\naadbeaacbbbbccaaadabcebbadddcaeeadcddeabdaaddedeceadeaeedbeaddddacbeadeeeabdcdbdedcdebabeaeeddbadbbcedbadbeddebcabaaeccecaeeeadbeccbabdecddecaeecbcedccdcddbcbbcdcedbbcbbecdadbdbbceeeabaadbacaaddebccededacadeecdbcbbedcbaeaccadcaaabcddeaeecabdebaaccecababccacbeeeabceacbbeecaebdebeddaeaeaebcacdeccbeebceddabaeedccdbaeaeebdedeecdccdcbddedcedacdceaacbadbaadcaececacaaebecaecababedebcdaceeedbbaeeadaecaadbcabacbecaecdeaeaedddeecaceabbcdceecedeacaebaddbaeacbccddcdabdedbeacccbdbabdccebaecaacacaabaeacedaaea\r\n", "output": ["223"]}, {"input": "500\r\nebceccdebaaacaeecbcbaedbeebceaccabacdadbaebcbbdebeeacacdecdceddbbecebcaaeeddeabbbbdceedaebceeeadbdadacdbbddcdaaddeabedccdacdecabcebcdbdaaeeaedbabaeaedaddcdebdbcdebbcbccddbdbbcdedaccbbaedeeedacabbddcdeedbaeabebbdddcceaaacbdbdcbdeeeccadabeadddcebbededdebaaaedabadbabcddebeaeebcebbdddcbacbeeeedacbeaddbccebecdceeabebabbbbbcaaaaeadaaeccaebeedababbabedbdcadeeabaaeddbedddeadecaedbbeccdbcdadededcddceaccceeabadabcebdcbecdebcaaeadbcdbcbdcbbedbecbbccbedabcbedceccdbabdababddeeeaaaabcbdbcedcbbdecaeebedddccbaa\r\n", "output": ["217"]}, {"input": "500\r\ncdeaeeedacbedcbbbcaaeccebccdeeddccdceabbaccbdabdeecccaeebddabbcdbedaababeaddbbecbdeaacebaebbbddeeccdeaedbdebebecccebebacdeadebedbdddcdbceacdedadeddaaaaeaddceaecdbedcdeabcacbaddcaebebdccbdcaacbacabbdabceaacdedacbcdadadeeecbceadaaaeceacadcaebcbaadddadeedbcdebcdcaccbccedcacaebcaccaadedddddaedaddaacecccbeececdeeccaaaebddeecccabbbdcbceeeedaceddaecdadcedacbdaebcbdddcedbdeadddebbaacccbabbcbaebceebacaddecadcdbccdeebabaccdcbababaaedbabbdadebeeacbbccaeabdcdceecbbcaedcadaccdaabdeabbaabebedcacedbeeaabdeeecb\r\n", "output": ["214"]}, {"input": "500\r\nbdeadccaedebabcdeadedebdcacdcaebdeeadedbdccabeaddaaabdaeedbecdcbeacdaceeccdebecabeaedebdadadddccaabddeaddaddedaebccabeccbeeceeaecbaaabccabdccdbeeebcbccebbaeebcdcaabdabcabadbccdcbdebdabbeeeccddaadedddbddeebdacacddcaddccbebbbaeddcecccabcacceadacbdabaddbebbaecebeebabeabaddbbdddbddacaddedbaeaeedcccccbdbcdcadccaadabaacbeaddcabcccacabcdcaabadacdccabcdaceeacbbeeedeacbcaaabeaacaabaccdbddeabdbdabccdceeecbeeeecdddacbbebceaccdbccabebedaeceadaacaebacdaeceeacedbadebeadaaebaebcadcedabecdbedbbadbccabadbbcbcbda\r\n", "output": ["219"]}, {"input": "500\r\nacdccbcdabcabdeaceeacabdebeccabcabcaeaadeaaaaecdeecbaecdeebcaccdacddeabedbddcbbdbabbddaeeddebebdecceeebbcaecadbedbaaccadcacbbcbebceabbddbbccdcdcddebbdbbdebbcbbdadbedebacaecabbbedccebcaecbceadaeabbaeecceacaacbeaebdbaeedabbebbaaadeceabeccccbadcebbeccdeadddedcdeebcaeedddbdcccddbaeabeeacddbdcdbaebeedbdeadbcabaaeabcbeeadcabddeceedaececdadeadabdbabcbbeeaabddcbbdeeeeeacdebdbdcacbcdacdbccbbccdeabecedbadddebbcdccedaebacaedcdbceadbeababbcbdaccdecbbeaeedbdceebadeadbdccaccccdbdcdddaedaababcaeeaddbdbaabeaaaa\r\n", "output": ["217"]}, {"input": "500\r\nebeeeeabaebabbacacccbcddbdadabdaedbecadecacdcdeccabdbbddbccabeccbdebdebedbaedeeaecccdadbcabbcdacadaddacbbbdaaeceaaeabbacdecacbebebbbbededccbdbbeddabcbebdabcccedabdbcccbbeebaecabcacbcdadcbebbadcbeadebccedaceebcebceeaacbbdcdacdcdedaddeedaddedadbccccdddcddccceaabcadecbebdeeeebcbcadedbdddaadcdceceaadeeadddacacaedaebbcbabacabacaaeecaebbabbeaeabecbddaaeaeadccdeebcedbdcaadceaaaaebaaccecccdecdeeccaaeeeccbdcebedbcadabceedbcecbbeacbadcccdaebbdddacaacadcdbaeeecdadbccbebebbaddeecbceebaaacdecabeabdaecaeaceac\r\n", "output": ["215"]}, {"input": "500\r\ncbbbbbdeeaacadcbdcedeacaccbdababbeedcbbddacdaaacbabcedeccddeeecccddaedebcdadaacddeabbdacceedadeedacacecdcceecaaeaecbcaabdabaddabadecebdbddbadacbbcddedddadabbeddedeabdcaabccbbdadddeaecebaaeedbbbebddaecccebebcaebebddadceebedeecbbacadadcccdacecbdcebdcdcaceeedbcdddabdcabdeccadbdddabbbaebbdadadebadbeddeecebeddaaaadbaaebaeaebdaddccddbaddcadaeaacabcdeaddaedddbbacdcbeeaaecbecceadeeacceeaaddaecdadddbbeebeedecbaeacaceacccbdcbcaccaceccadcebacaebccdcacebbedeaaeccaddedccedceeedeecbaccbcebaeacbbcbeedabceaebdc\r\n", "output": ["213"]}, {"input": "500\r\nbbcbdedcadacabdcbacdabcedeebdbdeddedccceedcececcebddeacaeddbaabbaaaedccccabdccbbeacebbdecbdbaecabceedcdecdebbbaecddbbcecbbeaddbcdaddaecddeceeeedbcccedbabbdccbceecbccaebbcccbacdaeeecdedacbacabdceaaabcacceedeadeebbeeceebaeebcaddecccdeedeecaacebddedeeddccacccdaaaebecdbcbdcbaddceacbbedbcabbbedcadadbcbeeecaceddabdabeabbabddcabdecabdeccccaabaeebcddebdcdbdccccdecacaeccccbddcabbbeadccebddbccbcbecbaedabcdcceeabadbcabddecbccbdabbcccdebbaebbebadaceaceaebbbeaabeedeaabbdaadccdabbcbabcdceabdeabdaebbddedecdbcc\r\n", "output": ["216"]}, {"input": "500\r\ncefcddeacbbffacacefaaaceebbcdbafdbcfbcdbffddabfeccaffaaddeecfebebaaaccabedeceddbdebeadfeeecddceedbbebffbbcfcbbefcefafdefbadabafbbddddfcbcdfefeaaeddbbacaeafdeffbabddabdcefbbaadfdabcddfccffbbaacdbddedddeeabfffdafdbdbbcefeeafcaabcfccfccceaaefebcaabddcbaccdaafffccfdcfccdfdeccdcfeaaedbadfbbdedcddfecbdfafddaaecaaadadcdfbefcdffbccfbbcdbedfbfcefadffebbcaebbffccbdbabfcbadacdbebabccbadefdfccfccedcbdeffaaadafdfbadefadaabafceecaaebdeedcebbbacfcceadcfcfaddffcaeafeacebbffddbfddabddeaafdcfdaabacfcdeceeadfacaea\r\n", "output": ["228"]}, {"input": "500\r\nedfeaaaaddffdbfbcebefebdfdadbdadcbbdbdcabfdbdeccaeebcdebdddfedcacbbefeabdbbdeceeacadbbbebffcebbaffdcabcedccddeeccdfbdedfeddcbebdadffbaacbbedbdbfdbcaecccbbcfefdbddabdeadeeeecffdbcfcbeabcdeeaaddeeddeadccdefbeaabfabadaddbfaddbecaaeccbdefececdbebbddffbbfcfdddcadbccedcecabdcfceeefcdbbfcaeccbcdcddbfabcbedfdcdfafabadbbcdcfbfccafafacacbcbfbcabefacedadfdbdbaeeffbcfdbcabdbdedbfcbadfcaafbaeadecdedcddecfdfddaadaebacabafcdcdeecefeddcfcceeddebccafbdbafffbecdbbbaaeebdabddaadadbbdceffdbbefccfbcbcbdaaefcabdebfba\r\n", "output": ["236"]}, {"input": "500\r\ncffaebdcbfbfbacefefbaeedaddacbdcfaeadcadcacaaacaadedebeecaebfdbcffaceadeedddbdfadcebcdffbafefcaecafcafbfccdeefadecfcbafaedbcecdbabdfbbfdeebabdaecbababcebbbdaadffbeffeffcfeefaccdfeafffeaaedfbbdafedecfdefbcaadecbffaadeadfecffaffdeeddbbadeadcfafbceaffabfefcddceeefacaceeffeefbcfcadaeeeabeebfcabbebddcdcedddddbceadbdddfeadafabfebdbcdeedadbbfacaeedefeafedbecbaafecffbaffbbfadfdfcebabddebcedacaaaafdfdefbaafdcfacfbddbfbdefcebdabcfdfaeebcbfbacffabbbbbdbfedebabbedadbaecbedbdeadddcfffaebdececfcbbbbcdecaacddb\r\n", "output": ["238"]}, {"input": "500\r\ncbadfcecebaefcfbfbbaedbcfacdcbfcacfadbebdedaaffaaabffdeedbfbdececccfbaccddeffeeabaaffedfdcdfffdaabbafccaceedacdceabdabcebeddeaeeecbcabddebdfbcbecbffdbbcdaffacdacfbaafbacdbbbdacecabbaffacfbcbacdadafdbebcadeeabcfcfecaefecbbeaafcbaafabbbdbfaeaccedcdcfbbadfeddfcadcdafaeffdcdfceedeaacecaaafffeadcdfffbfedccbaefeebabeafddbddeacefcfbbbceacbcacaecddbcfadcdeafdedadddfefaadfdbbeaaaceacecfefefceeecaefeebfccdcffadbfbeacfbcfeecadcbbebaefaebcecbffaefbbcfacfddbdcdaaeddfdabbefbddcfdeaceafdddffffaffdcdebdacefbdba\r\n", "output": ["235"]}, {"input": "500\r\naaafbfcaaeeeadcaebfffbfdaccaccfceaccaebecbefbbfeafffecaaeeadefcdebddaebcccfffdfacbffeeeacdbbeebdcadceabbccecfcdeebfeafbadaadcaaefcececdedccefcadbdbeaffeebeccabacbeeaacbeefdafeaecedfacadceabaffffdcfbbdfdbbeddddffdfabfecafcefaaaafeacefdfdfccabeecaeeefcecdfdacadbffdcaabdecaededeadbdfeadcaabbfbccbcfeccbecedbcdebbbabebbcfeaaacdaecdafbaacdbfefabebcafedacbbabadaeeaffebcdcabefbfdbbaaddacfafadbecbbcddcafcaefbefeffbbebeaaefcfafffacbdacadbbfadeececcaafcaadacdbfefaddefebaeebefadcdccddaaccebdaafffefeeddbacae\r\n", "output": ["230"]}, {"input": "500\r\ncaebcfbedafeaedbedddbdecfafbbefdddcaedffbbddefacafdcfafddddfdaddddcbbaaddabadedacbbdfeaacabcbdebaadbbcacbcbdbfcfadfcfcfdabefacacdacccbebafdabdfcadcfbfdeacfccfbefebcbcadeccdcefdabcfffdbdaedeaabcdacfbaacfceafeaafcdfadcdfbdfbefdfedacecaaffefbaddbdbbbcaaddbabbeacfabceeaefeebedefbcfadbacdefeabdadcecacceaaaadfaaeaebebbdabbcbfbaddfbfcfddbaaccacabbbbcbbccedcfccffbbcededafcccbceeefcedafdebbbeebaafdbadebdfcfbbbebcbeccaccafbacffdccdcaecebcaadffffabeccfddeffcfedcadcefafcbeabcadabddbfaffbbffaccbafbacadbfbaaf\r\n", "output": ["233"]}, {"input": "500\r\naefceaacfeddedcdedacacfbeeedfabbebbeccadfaabfacceaacdcbdfeeaffebcadeecddeacadfcaffedccabdebccabbdbbbaefbfacecaacdefbddcfcbafeccfbaaadccbbccfbeaaeadebbaaafbebfaaccfbdddeedaaeddbfdadbacafcbfdffcceacceefecbcedacfbffddedcdeacbdbdedbcdcacfcbceddaadcfcdcdcaefbcbbafffccbabfdecaaeceeaaaceedaceeebdebbeaadecfefacaddefbbdaebedbfadeafdeccaeaffedefcebababceccfacceddabcecbebccdcabddfdeefcabdbddcccdbccdacddbbaeaeadcfeccbcaabfcabceadfababecccbbbcddddeabdbbeacdbcdfacaafeedeadcbabbfeffcebfcfaceaecdfddbdbbeeebaebe\r\n", "output": ["228"]}, {"input": "500\r\nabfaaffaaebbefbabfefacdddddafbbabdacebeeccfabcfaebaeabbfabfcceddbdaadeddbffcfedaebecbaccdfbfafabfceffceeaccdfebbdbdafdebfcafebededcfbbaefefcbefdfabdefafeaccdfaeeacdacddccfcfcadbafbdbbdfcfecfeaffdcceccabcfeaddabfbaddebdecdfabebaeefefecedeeadaeedcfabcbcfbfaadaddaabeedfdccbbfeffccfcceddebecabacaedaaceedfddebbeaefbbcfdcdcbdfadadfefcaaffdfeedbcaebccdfecbfccacadccecbdcbdabbeaebdcedfbfaffbccbeaeebacceedceaabebeddbeedbfafeecdfdceebaaecabbefcabbaffdacfcebdbfffeadabddccaebdeffaacfdfcfdffabeefaecafaccabfbd\r\n", "output": ["236"]}, {"input": "500\r\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": ["1"]}, {"input": "500\r\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": ["1"]}, {"input": "500\r\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\r\n", "output": ["1"]}]
100
100
100
[{'input': '500\r\nedfeaaaaddffdbfbcebefebdfdadbdadcbbdbdcabfdbdeccaeebcdebdddfedcacbbefeabdbbdeceeacadbbbebffcebbaffdcabcedccddeeccdfbdedfeddcbebdadffbaacbbedbdbfdbcaecccbbcfefdbddabdeadeeeecffdbcfcbeabcdeeaaddeeddeadccdefbeaabfabadaddbfaddbecaaeccbdefececdbebbddffbbfcfdddcadbccedcecabdcfceeefcdbbfcaeccbcdcddbfabcbedfdcdfafabadbbcdcfbfccafafacacbcbfbcabefacedadfdbdbaeeffbcfdbcabdbdedbfcbadfcaafbaeadecdedcddecfdfddaadaebacabafcdcdeecefeddcfcceeddebccafbdbafffbecdbbbaaeebdabddaadadbbdceffdbbefccfbcbcbdaaefcabdebfba\r\n', 'output': ['236']}, {'input': '5\r\nabaca\r\n', 'output': ['3']}, {'input': '500\r\nghgbegjdahcmgdjgmbaehhgmmlbjgigielfbddkhfbfgbgcmdfekcaeejgidledgcghicgmmblbaljhgggkimcagblckjkimcglahiambbccefkbmlmdgmkglfdmjdflbfdbekmjbghjjikjgkmeigifllmmgijkcclgjkmcahdjgkcekeagklgfhgidbedbgkgkmbjbkbdhiijjbkcdeallkjmjfldamkcmiijmgfkmhkhcgggfbhldjehbmmebkfeibhimddigfbgflifgmcdhmhjcfcmijjeaaegagcikmglclcblacjfclghgfkfaflhggjdmdjlcheehfhekcbdfkihgfjgakjbaihdmkhjfcfhfbeeifaghmmhiijaeglkackhllehlmmjklcelggahhlilgmbemkkjdcmhakbfgjdakhgekhcddmafkidefbffjdcmcidjmllkeedgiikjdlggigchgckdijhjgfmmfekmdcm\r\n', 'output': ['303']}, {'input': '500\r\njqpyiogllhoobjixnlhskgwowfrhkuotvjbmgatrspqreavqwsuljxqduutxudueenmvarsmqqaqxohtsmxdqdhcvydhuiqcchvvxroqieeffipvlumywcthdafsgnwyamumpknqittxakhlbrbhrtcfbrkvjrypxqochjnmyihuqtrrbgiiytifqeqbnssrmywtdghpekqjxkvoefiwpbepqstotqyiohuawpvawephiexxnofiipkwmshhyaprhrryspbvfoasagdldqeasajhqsurmduuusiwgyuroimbyfjogkxcgjorxpqblhtwvlgognnvisqdkheurkikjcgmoyvafiqhfcbmgmybefsmkroftstqmhkfkuxufghjhveuhhkecushenjqyvqhxcfqdcbkxufhxpbamaowjnuaxjcsuuryvjtnwrhwiurrsehusxwrjwsotefacjxjanphxngylkmjbvhfqghtlnlvdbcnkfjd\r\n', 'output': ['350']}, {'input': '500\r\nkjcllbkmamlbogkopfqhjfpejfeglpbdqjikbgakecolabphkmpnjfbhpdnlcqcfdaljmegiljlqpkdnomcglpkbaiencimbkehpiqmpafeabbohfajahfablplcpacngfpghjdhbonglhaedpihkbjbkcpjdkqkpdobjfqepolgdgjonaogkingfmacbflbmjhhjbnnffbmcohgmmfbjqojnocjlfhlhflpkddmiijomenhldcoijnqcomjnbbpnffkgelnigkcmnaqdnkpmoejllkilfdlqoqcbmbqdaobndpgjkffebhgmfclhncalfeamiqhclllpoefaaobhqfnljloimkdoaggjammqliommkllnhhqoagcpmlkddkclokjlccgfapodfolmfejdkofqncjkjhqcledaplificibodhddlhmqqckjenpjalokpllnldqppjceelgjbjqqqlcecjcjmkiklbbdikblddkikpfea\r\n', 'output': ['325']}]
[{'input': '500\r\nacdccbcdabcabdeaceeacabdebeccabcabcaeaadeaaaaecdeecbaecdeebcaccdacddeabedbddcbbdbabbddaeeddebebdecceeebbcaecadbedbaaccadcacbbcbebceabbddbbccdcdcddebbdbbdebbcbbdadbedebacaecabbbedccebcaecbceadaeabbaeecceacaacbeaebdbaeedabbebbaaadeceabeccccbadcebbeccdeadddedcdeebcaeedddbdcccddbaeabeeacddbdcdbaebeedbdeadbcabaaeabcbeeadcabddeceedaececdadeadabdbabcbbeeaabddcbbdeeeeeacdebdbdcacbcdacdbccbbccdeabecedbadddebbcdccedaebacaedcdbceadbeababbcbdaccdecbbeaeedbdceebadeadbdccaccccdbdcdddaedaababcaeeaddbdbaabeaaaa\r\n', 'output': ['217']}, {'input': '500\r\ncachgdaghedbbfbcbicbabfcahhbeaafeaafgcaafcabeabccbbbjhjbjcabcfdcbjedeaijeebcabbfaiicebgfbchcaeachceigihhbifcdgdfhdjabjajfhhfajddghebbdiegadfahdahddfdeaagjfgafhjhfbeehbgahgeefggdgdcfcifagibijcgifehjccfggajjfajecbffdedfhgebfefibeiceigcddfjhgcghbbhjbhficggfighjdijjefcjchdihgfdcjgeeeiicihfdhbibijhgjdgdhcafdaafbfgjgcggidgebchbejiidjgbfcbcjejgfgeiaaebeajhdaijhgbebeefchahbbgcgegieagcdahgdfbidehbfafbigadjdedhdhaegbbcgifeahgchiafffjgfgaajjhedbiffbbjdijehdfiegiabeadfcifcbjjhidiieebaiffdjfhfidffgfchchegjed\r\n', 'output': ['281']}, {'input': '500\r\nccadaaddabcadcccbbbcbdaacabcbbcdacaababdbbdccdcacccbbccccadcdcddaccbaaababbacadcabaacbccaabbbdbcbcbbacaaaaababcddadcbddcccbabdabdabbbacbccaccacdacadbbbbcaccccbdcccaabbcaacbcdddcdcdcbbdabadbadadcacdbbbaaaadbcbbabdabcbcbddaccabdadabdbbabcbdcdbdccababcbadbdcaacbddabdadcdbddbdcdabddbdaccadacabddccbbdcbacdbbcbcbdbabbcbadddacddcddccaaaaacabccccccbdbdccacdcaaaababccbbddbbaadacdcbbbadccaacaaccaabbcbabdcdccdcbbbbcdaccbbdccabcbdbacadcbdcdcccdaaccdddbbbcbadcccbacadadaddaabdbacbcdbaadbaaabdcbcdddbcdbdbacdcb\r\n', 'output': ['193']}, {'input': '500\r\nbdeadccaedebabcdeadedebdcacdcaebdeeadedbdccabeaddaaabdaeedbecdcbeacdaceeccdebecabeaedebdadadddccaabddeaddaddedaebccabeccbeeceeaecbaaabccabdccdbeeebcbccebbaeebcdcaabdabcabadbccdcbdebdabbeeeccddaadedddbddeebdacacddcaddccbebbbaeddcecccabcacceadacbdabaddbebbaecebeebabeabaddbbdddbddacaddedbaeaeedcccccbdbcdcadccaadabaacbeaddcabcccacabcdcaabadacdccabcdaceeacbbeeedeacbcaaabeaacaabaccdbddeabdbdabccdceeecbeeeecdddacbbebceaccdbccabebedaeceadaacaebacdaeceeacedbadebeadaaebaebcadcedabecdbedbbadbccabadbbcbcbda\r\n', 'output': ['219']}, {'input': '500\r\nahecidbhaccbabcggeceaebgcbaeagehfhgiebafdcgiiehegggcdfbdccicbfficggabdhfihheadafdcccbbgbgfgehchdbihdidddagdafigbbbhgaiagiacbhhegdgchcfiabbiidhhfbabdfehcifgegieihfibheedfbiadbfdafdgbehfeifgcfhieiaheebeiiabggbecedchhicfeccfadhbfgahefdchibaecbifeadfdadfefifeibcbbibibbcchadbbbedcbgeiefdhedddedhfeecfafggghdffbcgigigeeieeafgciececicgeegafbcdahighgahgdeahfhfebegebfedfdfadiafdcdebgeacedeiecdcaghibhedaaecdaahdaecdbahcfchebiafcfhacabcgbaadibgfgbdcebifdafbgabageebfeebefhffdcdgehgfchiabfabcbefhccehffibaeiac\r\n', 'output': ['273']}]
[{'input': '500\r\nebeeeeabaebabbacacccbcddbdadabdaedbecadecacdcdeccabdbbddbccabeccbdebdebedbaedeeaecccdadbcabbcdacadaddacbbbdaaeceaaeabbacdecacbebebbbbededccbdbbeddabcbebdabcccedabdbcccbbeebaecabcacbcdadcbebbadcbeadebccedaceebcebceeaacbbdcdacdcdedaddeedaddedadbccccdddcddccceaabcadecbebdeeeebcbcadedbdddaadcdceceaadeeadddacacaedaebbcbabacabacaaeecaebbabbeaeabecbddaaeaeadccdeebcedbdcaadceaaaaebaaccecccdecdeeccaaeeeccbdcebedbcadabceedbcecbbeacbadcccdaebbdddacaacadcdbaeeecdadbccbebebbaddeecbceebaaacdecabeabdaecaeaceac\r\n', 'output': ['215']}, {'input': '500\r\nedfeaaaaddffdbfbcebefebdfdadbdadcbbdbdcabfdbdeccaeebcdebdddfedcacbbefeabdbbdeceeacadbbbebffcebbaffdcabcedccddeeccdfbdedfeddcbebdadffbaacbbedbdbfdbcaecccbbcfefdbddabdeadeeeecffdbcfcbeabcdeeaaddeeddeadccdefbeaabfabadaddbfaddbecaaeccbdefececdbebbddffbbfcfdddcadbccedcecabdcfceeefcdbbfcaeccbcdcddbfabcbedfdcdfafabadbbcdcfbfccafafacacbcbfbcabefacedadfdbdbaeeffbcfdbcabdbdedbfcbadfcaafbaeadecdedcddecfdfddaadaebacabafcdcdeecefeddcfcceeddebccafbdbafffbecdbbbaaeebdabddaadadbbdceffdbbefccfbcbcbdaaefcabdebfba\r\n', 'output': ['236']}, {'input': '500\r\nraqqhocfiosbkfjtbjnbatojfmummlrghpkmcghfagdmmkbesdhtelromtkmdmltiljttepgeqdlhtgkpgljrmqjjtmretsdincjjqilahapcjcdlkrftoaeramgrudjbtpjblaksjjjburngarjitmebjiotofctgppktkqkianmucafsspbefuijcmsqamuenlrfrunfhgfqjhkjgrdjrkjgbpifadsjabktgdsgjsslipnqncbdfaphfndssljbthhcrfoijilodnuosmirctsjbhtlbehnljqcjdahcmjqsursqemcmtbgdaegdugqskskfdcffuilthtnjfhujgpifckubajoorllaruqfmbgrcutjushbflsqeiqdddenhurmunhsqqnbsfnjhgdodhmdugisalahiiedmhcgudjfhuumtlndkneauikebmgnrbdmegeotncdllcmmqfudldikeasisllapabefdubasndtobm\r\n', 'output': ['339']}, {'input': '500\r\ncccaaccbcacbacccbcccbcabcccaaaaaabbccbbbacbacaaacbbcbbacaacbabababcaaacbcacacbacccccccbcccaaabbabccbccbcaabbcaccbbbbbccabcacccabbcbcacbcabaccabcbacacbbbcbaabacbcbbbbbabcbcabbccbbabbbbaccacaacabcacbacaaacacbbbccbcbaccaabbbcbcacbaaacaccaaabccbbabbaaabbbabacbaccaabbbaaacbacaabbaaaacccabbabbbcbcacbcccbbacaccacbcccacabbaabbbaaabbcbacaaaabbcccbacbbbaacacccccbccabbbaababbacccabaaabccbbccbbbbccacbccbcbbbcacaabacbcabaaababbaacaccbbbacbcabbbcacbaccacbcabbbcccbabbabbcaacbcbcaabaaaccacababbbaacacbbbcbabbcac\r\n', 'output': ['164']}, {'input': '500\r\ndadcbaaaabbddbbacdbabdcbcdcabacbddddbaabacbcabdccdcdadcbabdbcabcccbdcabdcaacdbabdcbbbdbacdddaaddccbacabbdbbcbbcadcdaadcababbbacabcdbbbadbdacbcddbccdbacbddbdababdcadbbabccbcdcccccadbbdbdbdcbcbdcddaacdababdddacadaddcdcbaabaddaadacbaadcdcacbdcbaddddbdbddacaadaaaaabdccccbccbcabddbbcaacadccdbcccdcdbbabbcbabdbccdcdbcbbadaaadddcbcbbbabbadcddbaaabbbdabbcbcacbbaaaddbcbaccaaadcdbcdbbbbbcdbbbcdadacdbcbbaaddbdabcbccabbadadbbbbdccacbbbacacadbcaadbccdbadacdaddacddcccbcbdbdbcbdbdaabdcdabbaadcdccdbdcccadabdbddd\r\n', 'output': ['196']}]
[{'input': '500\r\ncdbdadbdcabdcbdbaadacaacbbbbcdaccddbdbbdabccacbaacdbbdcbddadabaaccbabccabadddbdcdcdddbbcbadddcabcddcdbabacacbdbcaadacbbbdccbcabacdbcccbdccbaacddaaaabdacbdccbbbbcaabbbdabadadacabdbbaaacadcbaacadadbbdbcdabcdabccacbdcaadaccdbdcaccaaddacddccdadddddddbacaccdbbbbcbbabbdcacbcaacaabdddbdccdaddcddbbaabaabdbcccadcacbdacabcdaddaabcbcaadabadbdaacacacaaddbbbcabccdbbcbaccbadcddaaccdbacaabbcdbcbdbcbacacdccccabaaabbcbccdcaabcadcaccadbbbcccabbbcdbaccaabdcbcdbcdcaddaabcdacaddcccaddabcbabdcabbdbaaaccbbabcdaddbbccd\r\n', 'output': ['194']}, {'input': '500\r\nlkuvqevrlanaugfoadmkdqpljknwfoftofyxcvsfvprqxuwkfwunfilaqrzqhsjhsaoynbsuiqyzwqfkmbddngwydhrtimoerqpehjsgqojuhtxvaayzsbxmsqckibtcangzdnnpcpqkqgzbzbeaejuhprrqxdhyfrtzwhvnnrfocwrwfzbgtvdpwlkrqisjqpszykzhfjrstcvmmnebwgvwxsppyxihkepmndwgtzlsurasjfrkqqnxjqdsbmsggakyuouevxdxuwyxbhkmvpjqvoklaknxsmzqpjrftvzifnqjporbvtpdnzfhckjnwgeddpjycnqrtphjhqkfvpoerzkilpjuteidflpulppotglglarrwopryxbjjsroguskwzalrmasgcioovteyuukwnosswdwnqmrbdkssgnkaivtufoayaxgqpprnoyvoeqqpywboofudtutiweaaqzbneqmxgnfkxdnjdbijlveapyrybiw\r\n', 'output': ['358']}, {'input': '500\r\nedfeaaaaddffdbfbcebefebdfdadbdadcbbdbdcabfdbdeccaeebcdebdddfedcacbbefeabdbbdeceeacadbbbebffcebbaffdcabcedccddeeccdfbdedfeddcbebdadffbaacbbedbdbfdbcaecccbbcfefdbddabdeadeeeecffdbcfcbeabcdeeaaddeeddeadccdefbeaabfabadaddbfaddbecaaeccbdefececdbebbddffbbfcfdddcadbccedcecabdcfceeefcdbbfcaeccbcdcddbfabcbedfdcdfafabadbbcdcfbfccafafacacbcbfbcabefacedadfdbdbaeeffbcfdbcabdbdedbfcbadfcaafbaeadecdedcddecfdfddaadaebacabafcdcdeecefeddcfcceeddebccafbdbafffbecdbbbaaeebdabddaadadbbdceffdbbefccfbcbcbdaaefcabdebfba\r\n', 'output': ['236']}, {'input': '500\r\ncachgdaghedbbfbcbicbabfcahhbeaafeaafgcaafcabeabccbbbjhjbjcabcfdcbjedeaijeebcabbfaiicebgfbchcaeachceigihhbifcdgdfhdjabjajfhhfajddghebbdiegadfahdahddfdeaagjfgafhjhfbeehbgahgeefggdgdcfcifagibijcgifehjccfggajjfajecbffdedfhgebfefibeiceigcddfjhgcghbbhjbhficggfighjdijjefcjchdihgfdcjgeeeiicihfdhbibijhgjdgdhcafdaafbfgjgcggidgebchbejiidjgbfcbcjejgfgeiaaebeajhdaijhgbebeefchahbbgcgegieagcdahgdfbidehbfafbigadjdedhdhaegbbcgifeahgchiafffjgfgaajjhedbiffbbjdijehdfiegiabeadfcifcbjjhidiieebaiffdjfhfidffgfchchegjed\r\n', 'output': ['281']}, {'input': '500\r\ncbdcdcbdbcdbbcbdbddadbadddcdacdadbcaaaaddcadabdbabbcbbcccbbbbdbbccdcdcccdcdccaacaabacbdddddaaabaaacbbabdbcaacdabdaddacbdccddbbacabaaadddcdddadbdadacbccdabccadaacdadcbdaadacacbcdddbadcaddcbcbddcbcccacbbaacdcdbbdbbbadbbdbbbdacbddcbaccaccbaddaaaabbcdccccadcdcccbcbdbdcdcbddbacacbddbaacbaaabbbaccadcbbbacbacddbcbdbbcbcdbcdbbcdbcbdcdddbcbbbdbcabbdaaacdbdcdbccddbdababadddcdcabcbcbcccbcccdcaccacaddcabadacabbddaaabbdbdacccacabcaccddbbbcabcdaabdbddaaadbddccacbbcbccdccaaccbacacbcdbbcbccadcdabdbadbcabccddaba\r\n', 'output': ['195']}]
[{'input': '500\r\nabccacbaabaabaaccaaaacacbbcbccaababacbbbccbbcbcccabbccacbacbbacabbcbccccbcbbaccbcaacbacbbaaababccaccbcacaccccabbcbcbaacccbccabccaacccccccccbcabaacaaabccaaaabcccbcbbaabccabbbaaccbbcccbcccbabacbcabbbbccaaacaabcbabbbacacacbcaabbbacaaaaaaacbcabbcaccbcbaabacccacccabbbcbcbacccabcabbaabaacbcbaacbbccccbbbccaabcbcbbbccccccbbabcbabbacbaabaccabcabcabcbbabccacbbaacbcccbaaabacaaacaccbccbccaccccaccbbaabbaabbbccccbbcababcaaaaacbaabcaaccacbbabbbbcabbbbabbabbcaaabccacbcaccbbcabbaaababaaaccbbcccababacaabbccacccab\r\n', 'output': ['161']}, {'input': '500\r\nccbbbbaabaabccaabcaaccaabbaaaaaaaabaacccbcbccbccbbaabcbbbaacbbbacbccabbabacbcccbbaabbaaccbaacbcbcbabccbacbccccccbcbcbaaaaacabaabbbacabaababbbccaababbacbcbbacbbbbccbacaaccaaccbccbaacbcaaaaabacabbaaabcccaaacccabababbcbacaababcaabbcbacaabbcccccbccbaacacbcabaacbbababacabbcccbccccaababacbcbbaabaabcbaacaccbaacbbcbcbacbbbbabbcbbccabaabbaaabccabbbbbbaaabbbaabcabbbbbbcaaaabcbcbbcbbbbbbcabaababcabbabcacbaccaacacabbbbbcbaccacbbbcaacbbacccaabaababcbbacccababaabcabbccbbbabbaabacabcbabcaabcaacabcaaccacbcbbcaa\r\n', 'output': ['161']}, {'input': '500\r\nlkuvqevrlanaugfoadmkdqpljknwfoftofyxcvsfvprqxuwkfwunfilaqrzqhsjhsaoynbsuiqyzwqfkmbddngwydhrtimoerqpehjsgqojuhtxvaayzsbxmsqckibtcangzdnnpcpqkqgzbzbeaejuhprrqxdhyfrtzwhvnnrfocwrwfzbgtvdpwlkrqisjqpszykzhfjrstcvmmnebwgvwxsppyxihkepmndwgtzlsurasjfrkqqnxjqdsbmsggakyuouevxdxuwyxbhkmvpjqvoklaknxsmzqpjrftvzifnqjporbvtpdnzfhckjnwgeddpjycnqrtphjhqkfvpoerzkilpjuteidflpulppotglglarrwopryxbjjsroguskwzalrmasgcioovteyuukwnosswdwnqmrbdkssgnkaivtufoayaxgqpprnoyvoeqqpywboofudtutiweaaqzbneqmxgnfkxdnjdbijlveapyrybiw\r\n', 'output': ['358']}, {'input': '500\r\ndbcbdhbacghbacfeaecddchgffchhbhheacheagadabedhfcgfbgfahgebdgdecfgeaggebahhbhaaeagdhbadegebdfbededdffdfcbebhchgahafdegbbhhgaecadcdhaecbbceaefbadgedfhgfdaeheeeabbehbeddhdgdhbegefdffdbeebdegdbefbadbehacecdaedbeeedehfhddeggdafaagehefcefbghadhbehgbdehaeaeeecbbagbdefafhcgffgcfeefehgddgggbegcaabcfehcdbfcbbccheeafebdfageefeafafhffdaadcddgbfaegafbhafdbhfgebaaebegcddgcadddfgfcddggbdffffhghcbghbhdcebeacagbdfadhdbghaeacadbccbbebhfeeaghgebghbabbfhcdfagccaadhhgdeechghceefaaeacheedhbdaedcffhcgfeagdgfdchghbbfbf\r\n', 'output': ['261']}, {'input': '500\r\ncaadabddbaacdabdbadcadcadbdcdaadaaabcdbabcadcbaaadcadacbabcddacaabcadcabaabdddbcbcadbbbdabdabacbccddcbcdacbacbadabdcbccacbcbcabdcdbcdacadaacaabbbabbddbcccdcbabbbbcbcaacbdadacbdbabbabcaacdacbadcccbadaaabdbcbdbdadbddcdbdbcbccbbadbaaddcaaddadaaaabababdbbaddbadddbcaabcadbcacccadbdaaabcdcdbddcbbbdadaadbddddbdbacbccdaaabbdccaabcbbbaadaccdcbccdcabdccccabbbbadddccadddcbdddaddbdcaccbaadadbbdcaabdcdaacadddadbbbdadcdcdcbbabdcdbdbdddababaaabcdcbdccabbcaabbccadcdbdbbcdbbaabadacdaccaabbdabdcdbabcdbcbdacdbdcbc\r\n', 'output': ['204']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
230
100
100
100
["0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1", "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1", "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7"]
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between $$$-100$$$ and $$$100$$$.
f6a3dd8b3bab58ff66055c61ddfdf06a
import java.awt.Polygon; import java.awt.geom.Line2D; import java.util.Scanner; public class Squares { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in=new Scanner(System.in); int x1[]=new int[4]; int x2[]=new int[4]; int y1[]=new int[4]; int y2[]=new int[4];boolean t=false; for(int i=0;i<4;i++) { x1[i]=in.nextInt(); y1[i]=in.nextInt(); } for(int i=0;i<4;i++) { x2[i]=in.nextInt(); y2[i]=in.nextInt(); } Polygon P=new Polygon(x1,y1,4); Polygon Q=new Polygon(x2,y2,4); Line2D a[]=new Line2D[4]; Line2D b[]=new Line2D[4]; for(int i=0;i<4;i++) { a[i]=new Line2D.Double(x1[i],y1[i],x1[(i+1)%4],y1[(i+1)%4]); b[i]=new Line2D.Double(x2[i],y2[i],x2[(i+1)%4],y2[(i+1)%4]); } for(int i=0;i<4;i++) { for(int j=0;j<4;j++) { if(a[i].intersectsLine(b[j])) {t=true;break;} } if(t) break; } if(t==false) for(int i=0;i<4;i++) { if(P.contains(x2[i],y2[i])) {t=true;break;} if(Q.contains(x1[i],y1[i])) {t=true;break;} } if(t) System.out.println("YES"); else System.out.println("NO"); in.close(); } }
["YES", "NO", "YES"]
Java
NoteIn the first example the second square lies entirely within the first square, so they do intersect.In the second sample squares do not have any points in common.Here are images corresponding to the samples:
Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower).
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
[{"input": "0 0 6 0 6 6 0 6\r\n1 3 3 5 5 3 3 1\r\n", "output": ["yes", "YES"]}, {"input": "0 0 6 0 6 6 0 6\r\n7 3 9 5 11 3 9 1\r\n", "output": ["NO", "no"]}, {"input": "6 0 6 6 0 6 0 0\r\n7 4 4 7 7 10 10 7\r\n", "output": ["yes", "YES"]}, {"input": "0 0 6 0 6 6 0 6\r\n8 4 4 8 8 12 12 8\r\n", "output": ["yes", "YES"]}, {"input": "2 2 4 2 4 4 2 4\r\n0 3 3 6 6 3 3 0\r\n", "output": ["yes", "YES"]}, {"input": "-5 -5 5 -5 5 5 -5 5\r\n-5 7 0 2 5 7 0 12\r\n", "output": ["yes", "YES"]}, {"input": "-5 -5 5 -5 5 5 -5 5\r\n-5 12 0 7 5 12 0 17\r\n", "output": ["NO", "no"]}, {"input": "-5 -5 5 -5 5 5 -5 5\r\n6 0 0 6 -6 0 0 -6\r\n", "output": ["yes", "YES"]}, {"input": "-100 -100 100 -100 100 100 -100 100\r\n-100 0 0 -100 100 0 0 100\r\n", "output": ["yes", "YES"]}, {"input": "92 1 92 98 -5 98 -5 1\r\n44 60 56 48 44 36 32 48\r\n", "output": ["yes", "YES"]}, {"input": "-12 -54 -12 33 -99 33 -99 -54\r\n-77 -40 -86 -31 -77 -22 -68 -31\r\n", "output": ["yes", "YES"]}, {"input": "3 45 19 45 19 61 3 61\r\n-29 45 -13 29 3 45 -13 61\r\n", "output": ["yes", "YES"]}, {"input": "79 -19 79 15 45 15 45 -19\r\n-1 24 -29 52 -1 80 27 52\r\n", "output": ["NO", "no"]}, {"input": "75 -57 75 -21 39 -21 39 -57\r\n10 -42 -32 0 10 42 52 0\r\n", "output": ["NO", "no"]}, {"input": "-11 53 9 53 9 73 -11 73\r\n-10 9 -43 42 -10 75 23 42\r\n", "output": ["yes", "YES"]}, {"input": "-10 -36 -10 27 -73 27 -73 -36\r\n44 -28 71 -55 44 -82 17 -55\r\n", "output": ["NO", "no"]}, {"input": "-63 -15 6 -15 6 54 -63 54\r\n15 -13 -8 10 15 33 38 10\r\n", "output": ["yes", "YES"]}, {"input": "47 15 51 15 51 19 47 19\r\n19 0 -27 46 19 92 65 46\r\n", "output": ["NO", "no"]}, {"input": "87 -5 87 79 3 79 3 -5\r\n36 36 78 -6 36 -48 -6 -6\r\n", "output": ["yes", "YES"]}, {"input": "-4 56 10 56 10 70 -4 70\r\n-11 47 -35 71 -11 95 13 71\r\n", "output": ["yes", "YES"]}, {"input": "-41 6 -41 8 -43 8 -43 6\r\n-7 27 43 -23 -7 -73 -57 -23\r\n", "output": ["NO", "no"]}, {"input": "44 -58 44 7 -21 7 -21 -58\r\n22 19 47 -6 22 -31 -3 -6\r\n", "output": ["yes", "YES"]}, {"input": "-37 -63 49 -63 49 23 -37 23\r\n-52 68 -21 37 -52 6 -83 37\r\n", "output": ["yes", "YES"]}, {"input": "93 20 93 55 58 55 58 20\r\n61 -17 39 5 61 27 83 5\r\n", "output": ["yes", "YES"]}, {"input": "-7 4 -7 58 -61 58 -61 4\r\n-28 45 -17 34 -28 23 -39 34\r\n", "output": ["yes", "YES"]}, {"input": "24 -79 87 -79 87 -16 24 -16\r\n-59 21 -85 47 -59 73 -33 47\r\n", "output": ["NO", "no"]}, {"input": "-68 -15 6 -15 6 59 -68 59\r\n48 -18 57 -27 48 -36 39 -27\r\n", "output": ["NO", "no"]}, {"input": "25 1 25 91 -65 91 -65 1\r\n24 3 15 12 24 21 33 12\r\n", "output": ["yes", "YES"]}, {"input": "55 24 73 24 73 42 55 42\r\n49 17 10 56 49 95 88 56\r\n", "output": ["yes", "YES"]}, {"input": "69 -65 69 -28 32 -28 32 -65\r\n-1 50 43 6 -1 -38 -45 6\r\n", "output": ["NO", "no"]}, {"input": "86 -26 86 18 42 18 42 -26\r\n3 -22 -40 21 3 64 46 21\r\n", "output": ["yes", "YES"]}, {"input": "52 -47 52 -30 35 -30 35 -47\r\n49 -22 64 -37 49 -52 34 -37\r\n", "output": ["yes", "YES"]}, {"input": "27 -59 27 9 -41 9 -41 -59\r\n-10 -17 2 -29 -10 -41 -22 -29\r\n", "output": ["yes", "YES"]}, {"input": "-90 2 0 2 0 92 -90 92\r\n-66 31 -86 51 -66 71 -46 51\r\n", "output": ["yes", "YES"]}, {"input": "-93 -86 -85 -86 -85 -78 -93 -78\r\n-13 61 0 48 -13 35 -26 48\r\n", "output": ["NO", "no"]}, {"input": "-3 -45 85 -45 85 43 -3 43\r\n-22 0 -66 44 -22 88 22 44\r\n", "output": ["yes", "YES"]}, {"input": "-27 -73 72 -73 72 26 -27 26\r\n58 11 100 -31 58 -73 16 -31\r\n", "output": ["yes", "YES"]}, {"input": "-40 -31 8 -31 8 17 -40 17\r\n0 18 -35 53 0 88 35 53\r\n", "output": ["NO", "no"]}, {"input": "-15 -63 -15 7 -85 7 -85 -63\r\n-35 -40 -33 -42 -35 -44 -37 -42\r\n", "output": ["yes", "YES"]}, {"input": "-100 -100 -100 100 100 100 100 -100\r\n-100 0 0 100 100 0 0 -100\r\n", "output": ["yes", "YES"]}, {"input": "67 33 67 67 33 67 33 33\r\n43 11 9 45 43 79 77 45\r\n", "output": ["yes", "YES"]}, {"input": "14 8 9 8 9 3 14 3\r\n-2 -13 14 3 30 -13 14 -29\r\n", "output": ["yes", "YES"]}, {"input": "4 3 7 3 7 6 4 6\r\n7 29 20 16 7 3 -6 16\r\n", "output": ["yes", "YES"]}, {"input": "14 30 3 30 3 19 14 19\r\n19 -13 11 -5 19 3 27 -5\r\n", "output": ["NO", "no"]}, {"input": "-54 3 -50 3 -50 -1 -54 -1\r\n3 -50 -6 -41 -15 -50 -6 -59\r\n", "output": ["NO", "no"]}, {"input": "3 8 3 -10 21 -10 21 8\r\n-9 2 -21 -10 -9 -22 3 -10\r\n", "output": ["yes", "YES"]}, {"input": "-35 3 -21 3 -21 -11 -35 -11\r\n-8 -10 3 -21 -8 -32 -19 -21\r\n", "output": ["NO", "no"]}, {"input": "-5 -23 -5 -31 3 -31 3 -23\r\n-7 -23 -2 -28 3 -23 -2 -18\r\n", "output": ["yes", "YES"]}, {"input": "3 20 10 20 10 13 3 13\r\n3 20 21 38 39 20 21 2\r\n", "output": ["yes", "YES"]}, {"input": "25 3 16 3 16 12 25 12\r\n21 -2 16 -7 11 -2 16 3\r\n", "output": ["yes", "YES"]}, {"input": "-1 18 -1 3 14 3 14 18\r\n14 3 19 8 14 13 9 8\r\n", "output": ["yes", "YES"]}, {"input": "-44 -17 -64 -17 -64 3 -44 3\r\n-56 15 -44 27 -32 15 -44 3\r\n", "output": ["yes", "YES"]}, {"input": "17 3 2 3 2 18 17 18\r\n22 23 2 3 -18 23 2 43\r\n", "output": ["yes", "YES"]}, {"input": "3 -22 3 -36 -11 -36 -11 -22\r\n11 -44 19 -36 11 -28 3 -36\r\n", "output": ["yes", "YES"]}, {"input": "3 45 3 48 0 48 0 45\r\n13 38 4 47 13 56 22 47\r\n", "output": ["NO", "no"]}, {"input": "3 -10 2 -10 2 -9 3 -9\r\n38 -10 20 -28 2 -10 20 8\r\n", "output": ["yes", "YES"]}, {"input": "-66 3 -47 3 -47 22 -66 22\r\n-52 -2 -45 5 -52 12 -59 5\r\n", "output": ["yes", "YES"]}, {"input": "3 37 -1 37 -1 41 3 41\r\n6 31 9 34 6 37 3 34\r\n", "output": ["NO", "no"]}, {"input": "13 1 15 1 15 3 13 3\r\n13 19 21 11 13 3 5 11\r\n", "output": ["yes", "YES"]}, {"input": "20 8 3 8 3 -9 20 -9\r\n2 -11 3 -10 2 -9 1 -10\r\n", "output": ["NO", "no"]}, {"input": "3 41 3 21 -17 21 -17 41\r\n26 12 10 28 26 44 42 28\r\n", "output": ["NO", "no"]}, {"input": "11 11 11 3 3 3 3 11\r\n-12 26 -27 11 -12 -4 3 11\r\n", "output": ["yes", "YES"]}, {"input": "-29 3 -29 12 -38 12 -38 3\r\n-35 9 -29 15 -23 9 -29 3\r\n", "output": ["yes", "YES"]}, {"input": "3 -32 1 -32 1 -30 3 -30\r\n4 -32 -16 -52 -36 -32 -16 -12\r\n", "output": ["yes", "YES"]}, {"input": "-16 -10 -16 9 3 9 3 -10\r\n-8 -1 2 9 12 -1 2 -11\r\n", "output": ["yes", "YES"]}, {"input": "3 -42 -5 -42 -5 -34 3 -34\r\n-8 -54 -19 -43 -8 -32 3 -43\r\n", "output": ["yes", "YES"]}, {"input": "-47 3 -37 3 -37 -7 -47 -7\r\n-37 3 -33 -1 -37 -5 -41 -1\r\n", "output": ["yes", "YES"]}, {"input": "10 3 12 3 12 5 10 5\r\n12 4 20 12 12 20 4 12\r\n", "output": ["yes", "YES"]}, {"input": "3 -41 -9 -41 -9 -53 3 -53\r\n18 -16 38 -36 18 -56 -2 -36\r\n", "output": ["yes", "YES"]}, {"input": "3 40 2 40 2 41 3 41\r\n22 39 13 48 4 39 13 30\r\n", "output": ["NO", "no"]}, {"input": "21 26 21 44 3 44 3 26\r\n-20 38 -32 26 -20 14 -8 26\r\n", "output": ["NO", "no"]}, {"input": "0 7 3 7 3 10 0 10\r\n3 9 -17 29 -37 9 -17 -11\r\n", "output": ["yes", "YES"]}, {"input": "3 21 3 18 6 18 6 21\r\n-27 18 -11 2 5 18 -11 34\r\n", "output": ["yes", "YES"]}, {"input": "-29 13 -39 13 -39 3 -29 3\r\n-36 -4 -50 -18 -36 -32 -22 -18\r\n", "output": ["NO", "no"]}, {"input": "3 -26 -2 -26 -2 -21 3 -21\r\n-5 -37 -16 -26 -5 -15 6 -26\r\n", "output": ["yes", "YES"]}, {"input": "3 9 -1 9 -1 13 3 13\r\n-9 17 -1 9 -9 1 -17 9\r\n", "output": ["yes", "YES"]}, {"input": "48 8 43 8 43 3 48 3\r\n31 -4 43 8 55 -4 43 -16\r\n", "output": ["yes", "YES"]}, {"input": "-3 1 3 1 3 -5 -3 -5\r\n20 -22 3 -5 20 12 37 -5\r\n", "output": ["yes", "YES"]}, {"input": "14 3 14 -16 -5 -16 -5 3\r\n14 2 15 1 14 0 13 1\r\n", "output": ["yes", "YES"]}, {"input": "-10 12 -10 -1 3 -1 3 12\r\n1 10 -2 7 -5 10 -2 13\r\n", "output": ["yes", "YES"]}, {"input": "39 21 21 21 21 3 39 3\r\n27 3 47 -17 27 -37 7 -17\r\n", "output": ["yes", "YES"]}, {"input": "3 1 3 17 -13 17 -13 1\r\n17 20 10 27 3 20 10 13\r\n", "output": ["NO", "no"]}, {"input": "15 -18 3 -18 3 -6 15 -6\r\n29 -1 16 -14 3 -1 16 12\r\n", "output": ["yes", "YES"]}, {"input": "41 -6 41 3 32 3 32 -6\r\n33 3 35 5 33 7 31 5\r\n", "output": ["yes", "YES"]}, {"input": "7 35 3 35 3 39 7 39\r\n23 15 3 35 23 55 43 35\r\n", "output": ["yes", "YES"]}, {"input": "19 19 35 19 35 3 19 3\r\n25 -9 16 -18 7 -9 16 0\r\n", "output": ["NO", "no"]}, {"input": "-20 3 -20 9 -26 9 -26 3\r\n-19 4 -21 2 -19 0 -17 2\r\n", "output": ["yes", "YES"]}, {"input": "13 3 22 3 22 -6 13 -6\r\n26 3 22 -1 18 3 22 7\r\n", "output": ["yes", "YES"]}, {"input": "-4 -8 -4 -15 3 -15 3 -8\r\n-10 5 -27 -12 -10 -29 7 -12\r\n", "output": ["yes", "YES"]}, {"input": "3 15 7 15 7 19 3 19\r\n-12 30 -23 19 -12 8 -1 19\r\n", "output": ["NO", "no"]}, {"input": "-12 3 5 3 5 -14 -12 -14\r\n-14 22 5 3 24 22 5 41\r\n", "output": ["yes", "YES"]}, {"input": "-37 3 -17 3 -17 -17 -37 -17\r\n-9 -41 9 -23 -9 -5 -27 -23\r\n", "output": ["yes", "YES"]}, {"input": "3 57 3 45 -9 45 -9 57\r\n8 50 21 37 8 24 -5 37\r\n", "output": ["yes", "YES"]}, {"input": "42 3 42 -6 33 -6 33 3\r\n42 4 41 3 40 4 41 5\r\n", "output": ["yes", "YES"]}, {"input": "3 59 3 45 -11 45 -11 59\r\n-2 50 -8 44 -2 38 4 44\r\n", "output": ["yes", "YES"]}, {"input": "-51 3 -39 3 -39 15 -51 15\r\n-39 14 -53 0 -39 -14 -25 0\r\n", "output": ["yes", "YES"]}, {"input": "-7 -15 -7 3 11 3 11 -15\r\n15 -1 22 -8 15 -15 8 -8\r\n", "output": ["yes", "YES"]}, {"input": "3 -39 14 -39 14 -50 3 -50\r\n17 -39 5 -27 -7 -39 5 -51\r\n", "output": ["yes", "YES"]}, {"input": "91 -27 91 29 35 29 35 -27\r\n59 39 95 3 59 -33 23 3\r\n", "output": ["yes", "YES"]}, {"input": "-81 -60 -31 -60 -31 -10 -81 -10\r\n-58 -68 -95 -31 -58 6 -21 -31\r\n", "output": ["yes", "YES"]}, {"input": "78 -59 78 -2 21 -2 21 -59\r\n48 1 86 -37 48 -75 10 -37\r\n", "output": ["yes", "YES"]}, {"input": "-38 -26 32 -26 32 44 -38 44\r\n2 -27 -44 19 2 65 48 19\r\n", "output": ["yes", "YES"]}, {"input": "73 -54 73 -4 23 -4 23 -54\r\n47 1 77 -29 47 -59 17 -29\r\n", "output": ["yes", "YES"]}, {"input": "-6 -25 46 -25 46 27 -6 27\r\n21 -43 -21 -1 21 41 63 -1\r\n", "output": ["yes", "YES"]}, {"input": "-17 -91 -17 -27 -81 -27 -81 -91\r\n-48 -21 -12 -57 -48 -93 -84 -57\r\n", "output": ["yes", "YES"]}, {"input": "-7 16 43 16 43 66 -7 66\r\n18 -7 -27 38 18 83 63 38\r\n", "output": ["yes", "YES"]}, {"input": "-46 11 16 11 16 73 -46 73\r\n-18 -8 -67 41 -18 90 31 41\r\n", "output": ["yes", "YES"]}, {"input": "-33 -64 25 -64 25 -6 -33 -6\r\n-5 -74 -51 -28 -5 18 41 -28\r\n", "output": ["yes", "YES"]}, {"input": "99 -100 100 -100 100 -99 99 -99\r\n99 -99 100 -98 99 -97 98 -98\r\n", "output": ["yes", "YES"]}, {"input": "-100 -100 -100 -99 -99 -99 -99 -100\r\n-10 -10 -9 -9 -10 -8 -11 -9\r\n", "output": ["NO", "no"]}, {"input": "-4 3 -3 3 -3 4 -4 4\r\n0 -4 4 0 0 4 -4 0\r\n", "output": ["NO", "no"]}, {"input": "0 0 10 0 10 10 0 10\r\n11 9 13 7 15 9 13 11\r\n", "output": ["NO", "no"]}, {"input": "1 1 1 6 6 6 6 1\r\n5 8 8 11 11 8 8 5\r\n", "output": ["NO", "no"]}, {"input": "99 99 99 100 100 100 100 99\r\n-100 0 0 100 100 0 0 -100\r\n", "output": ["NO", "no"]}, {"input": "0 0 0 2 2 2 2 0\r\n5 1 9 5 5 9 1 5\r\n", "output": ["NO", "no"]}, {"input": "3 2 3 3 4 3 4 2\r\n0 4 4 0 0 -4 -4 0\r\n", "output": ["NO", "no"]}, {"input": "0 0 2 0 2 2 0 2\r\n4 1 7 4 4 7 1 4\r\n", "output": ["NO", "no"]}, {"input": "3 6 3 8 5 8 5 6\r\n2 9 4 11 6 9 4 7\r\n", "output": ["yes", "YES"]}, {"input": "0 0 10 0 10 10 0 10\r\n-1 5 5 -1 11 5 5 11\r\n", "output": ["yes", "YES"]}, {"input": "0 0 1 0 1 1 0 1\r\n3 0 6 3 3 6 0 3\r\n", "output": ["NO", "no"]}, {"input": "3 7 4 7 4 6 3 6\r\n0 0 10 10 20 0 10 -10\r\n", "output": ["NO", "no"]}, {"input": "0 0 0 1 1 1 1 0\r\n0 3 3 6 6 3 3 0\r\n", "output": ["NO", "no"]}, {"input": "0 0 0 4 4 4 4 0\r\n3 6 7 10 11 6 7 2\r\n", "output": ["NO", "no"]}, {"input": "0 0 0 1 1 1 1 0\r\n0 10 10 0 20 10 10 20\r\n", "output": ["NO", "no"]}]
100
100
100
[{'input': '79 -19 79 15 45 15 45 -19\r\n-1 24 -29 52 -1 80 27 52\r\n', 'output': ['NO', 'no']}, {'input': '1 1 1 6 6 6 6 1\r\n5 8 8 11 11 8 8 5\r\n', 'output': ['NO', 'no']}, {'input': '-16 -10 -16 9 3 9 3 -10\r\n-8 -1 2 9 12 -1 2 -11\r\n', 'output': ['yes', 'YES']}, {'input': '-47 3 -37 3 -37 -7 -47 -7\r\n-37 3 -33 -1 -37 -5 -41 -1\r\n', 'output': ['yes', 'YES']}, {'input': '-35 3 -21 3 -21 -11 -35 -11\r\n-8 -10 3 -21 -8 -32 -19 -21\r\n', 'output': ['NO', 'no']}]
[{'input': '13 1 15 1 15 3 13 3\r\n13 19 21 11 13 3 5 11\r\n', 'output': ['yes', 'YES']}, {'input': '-38 -26 32 -26 32 44 -38 44\r\n2 -27 -44 19 2 65 48 19\r\n', 'output': ['yes', 'YES']}, {'input': '-44 -17 -64 -17 -64 3 -44 3\r\n-56 15 -44 27 -32 15 -44 3\r\n', 'output': ['yes', 'YES']}, {'input': '-7 16 43 16 43 66 -7 66\r\n18 -7 -27 38 18 83 63 38\r\n', 'output': ['yes', 'YES']}, {'input': '92 1 92 98 -5 98 -5 1\r\n44 60 56 48 44 36 32 48\r\n', 'output': ['yes', 'YES']}]
[{'input': '-93 -86 -85 -86 -85 -78 -93 -78\r\n-13 61 0 48 -13 35 -26 48\r\n', 'output': ['NO', 'no']}, {'input': '-4 -8 -4 -15 3 -15 3 -8\r\n-10 5 -27 -12 -10 -29 7 -12\r\n', 'output': ['yes', 'YES']}, {'input': '52 -47 52 -30 35 -30 35 -47\r\n49 -22 64 -37 49 -52 34 -37\r\n', 'output': ['yes', 'YES']}, {'input': '-5 -5 5 -5 5 5 -5 5\r\n-5 12 0 7 5 12 0 17\r\n', 'output': ['NO', 'no']}, {'input': '-41 6 -41 8 -43 8 -43 6\r\n-7 27 43 -23 -7 -73 -57 -23\r\n', 'output': ['NO', 'no']}]
[{'input': '-27 -73 72 -73 72 26 -27 26\r\n58 11 100 -31 58 -73 16 -31\r\n', 'output': ['yes', 'YES']}, {'input': '15 -18 3 -18 3 -6 15 -6\r\n29 -1 16 -14 3 -1 16 12\r\n', 'output': ['yes', 'YES']}, {'input': '-29 13 -39 13 -39 3 -29 3\r\n-36 -4 -50 -18 -36 -32 -22 -18\r\n', 'output': ['NO', 'no']}, {'input': '17 3 2 3 2 18 17 18\r\n22 23 2 3 -18 23 2 43\r\n', 'output': ['yes', 'YES']}, {'input': '-10 -36 -10 27 -73 27 -73 -36\r\n44 -28 71 -55 44 -82 17 -55\r\n', 'output': ['NO', 'no']}]
[{'input': '2 2 4 2 4 4 2 4\r\n0 3 3 6 6 3 3 0\r\n', 'output': ['yes', 'YES']}, {'input': '99 99 99 100 100 100 100 99\r\n-100 0 0 100 100 0 0 -100\r\n', 'output': ['NO', 'no']}, {'input': '-35 3 -21 3 -21 -11 -35 -11\r\n-8 -10 3 -21 -8 -32 -19 -21\r\n', 'output': ['NO', 'no']}, {'input': '-90 2 0 2 0 92 -90 92\r\n-66 31 -86 51 -66 71 -46 51\r\n', 'output': ['yes', 'YES']}, {'input': '48 8 43 8 43 3 48 3\r\n31 -4 43 8 55 -4 43 -16\r\n', 'output': ['yes', 'YES']}]
100
100
100
100
100
94.29
91.43
94.29
94.29
100
91.67
79.17
91.67
91.67
100
231
100
94.86
90.836
["5 2\n#G#T#", "6 1\nT....G", "7 3\nT..#..G", "6 2\n..GT.."]
The first line of the input contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1)Β β€” the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
189a9b5ce669bdb04b9d371d74a5dd41
import java.io.*; import java.util.*; public class Problem2A { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] in = br.readLine().split(" "); int n = Integer.parseInt(in[0]); int k = Integer.parseInt(in[1]); char[] line = br.readLine().toCharArray(); int start = -1; int end = -1; for(int i=0; i<line.length; i++) { if(line[i] == 'G') { start = i; } if(line[i] == 'T') { end = i; } } if(end < start) { int temp = end; end = start; start = temp; } boolean valid = true; if((end-start) % k != 0) valid = false; for(int i=start + k; i<end && valid; i+= k) { if(line[i] != '.') valid = false; } if(valid) System.out.println("YES"); else System.out.println("NO"); } }
["YES", "YES", "NO", "NO"]
Java
NoteIn the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is freeΒ β€” he can get there by jumping left 5 times.In the third sample, the grasshopper can't make a single jump.In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
[{"input": "5 2\r\n#G#T#\r\n", "output": ["YES", "Yes"]}, {"input": "6 1\r\nT....G\r\n", "output": ["YES", "Yes"]}, {"input": "7 3\r\nT..#..G\r\n", "output": ["No", "NO"]}, {"input": "6 2\r\n..GT..\r\n", "output": ["No", "NO"]}, {"input": "2 1\r\nGT\r\n", "output": ["YES", "Yes"]}, {"input": "100 5\r\nG####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####T####\r\n", "output": ["YES", "Yes"]}, {"input": "100 5\r\nG####.####.####.####.####.####.####.####.####.####.####.####.####.#########.####.####.####.####T####\r\n", "output": ["No", "NO"]}, {"input": "2 1\r\nTG\r\n", "output": ["YES", "Yes"]}, {"input": "99 1\r\n...T.............................................................................................G.\r\n", "output": ["YES", "Yes"]}, {"input": "100 2\r\nG............#.....#...........#....#...........##............#............#......................T.\r\n", "output": ["No", "NO"]}, {"input": "100 20\r\n.....G.#.#..................#.........##....#...................#.#..........#...#.#.T..#.......#...\r\n", "output": ["YES", "Yes"]}, {"input": "100 20\r\n.....G................................................................................T.............\r\n", "output": ["No", "NO"]}, {"input": "100 1\r\n#.#.#.##..#..##.#....##.##.##.#....####..##.#.##..GT..##...###.#.##.#..#..##.###..#.####..#.#.##..##\r\n", "output": ["YES", "Yes"]}, {"input": "100 2\r\n..#####.#.#.......#.#.#...##..####..###..#.#######GT####.#.#...##...##.#..###....##.#.#..#.###....#.\r\n", "output": ["No", "NO"]}, {"input": "100 3\r\nG..................................................................................................T\r\n", "output": ["YES", "Yes"]}, {"input": "100 3\r\nG..................................#......#......#.......#.#..........#........#......#..........#.T\r\n", "output": ["No", "NO"]}, {"input": "100 3\r\nG..............#..........#...#..............#.#.....................#......#........#.........#...T\r\n", "output": ["No", "NO"]}, {"input": "100 3\r\nG##################################################################################################T\r\n", "output": ["No", "NO"]}, {"input": "100 33\r\nG..................................................................................................T\r\n", "output": ["YES", "Yes"]}, {"input": "100 33\r\nG.........#........#..........#..............#.................#............................#.#....T\r\n", "output": ["YES", "Yes"]}, {"input": "100 33\r\nG.......#..................#..............................#............................#..........T.\r\n", "output": ["No", "NO"]}, {"input": "100 33\r\nG#..........##...#.#.....................#.#.#.........##..#...........#....#...........##...#..###T\r\n", "output": ["YES", "Yes"]}, {"input": "100 33\r\nG..#.#..#..####......#......##...##...#.##........#...#...#.##....###..#...###..##.#.....#......#.T.\r\n", "output": ["No", "NO"]}, {"input": "100 33\r\nG#....#..#..##.##..#.##.#......#.#.##..##.#.#.##.##....#.#.....####..##...#....##..##..........#...T\r\n", "output": ["No", "NO"]}, {"input": "100 33\r\nG#######.#..##.##.#...#..#.###.#.##.##.#..#.###..####.##.#.##....####...##..####.#..##.##.##.#....#T\r\n", "output": ["No", "NO"]}, {"input": "100 33\r\nG#####.#.##.###########.##..##..#######..########..###.###..#.####.######.############..####..#####T\r\n", "output": ["No", "NO"]}, {"input": "100 99\r\nT..................................................................................................G\r\n", "output": ["YES", "Yes"]}, {"input": "100 99\r\nT.#...............................#............#..............................##...................G\r\n", "output": ["YES", "Yes"]}, {"input": "100 99\r\nT..#....#.##...##########.#.#.#.#...####..#.....#..##..#######.######..#.....###..###...#.......#.#G\r\n", "output": ["YES", "Yes"]}, {"input": "100 99\r\nG##################################################################################################T\r\n", "output": ["YES", "Yes"]}, {"input": "100 9\r\nT..................................................................................................G\r\n", "output": ["YES", "Yes"]}, {"input": "100 9\r\nT.................................................................................................G.\r\n", "output": ["No", "NO"]}, {"input": "100 9\r\nT................................................................................................G..\r\n", "output": ["No", "NO"]}, {"input": "100 9\r\nT...........................................................................................G.......\r\n", "output": ["No", "NO"]}, {"input": "100 9\r\nG..........................................................................................T........\r\n", "output": ["No", "NO"]}, {"input": "100 1\r\nG..................................................................................................T\r\n", "output": ["YES", "Yes"]}, {"input": "100 1\r\nT..................................................................................................G\r\n", "output": ["YES", "Yes"]}, {"input": "100 1\r\n##########G.........T###############################################################################\r\n", "output": ["YES", "Yes"]}, {"input": "100 1\r\n#################################################################################################G.T\r\n", "output": ["YES", "Yes"]}, {"input": "100 17\r\n##########G################.################.################.################T#####################\r\n", "output": ["YES", "Yes"]}, {"input": "100 17\r\n####.#..#.G######.#########.##..##########.#.################.################T######.####.#########\r\n", "output": ["YES", "Yes"]}, {"input": "100 17\r\n.########.G##.####.#.######.###############..#.###########.##.#####.##.#####.#T.###..###.########.##\r\n", "output": ["YES", "Yes"]}, {"input": "100 1\r\nG.............................................#....................................................T\r\n", "output": ["No", "NO"]}, {"input": "100 1\r\nT.#................................................................................................G\r\n", "output": ["No", "NO"]}, {"input": "100 1\r\n##########G....#....T###############################################################################\r\n", "output": ["No", "NO"]}, {"input": "100 1\r\n#################################################################################################G#T\r\n", "output": ["No", "NO"]}, {"input": "100 17\r\nG################.#################################.################T###############################\r\n", "output": ["No", "NO"]}, {"input": "100 17\r\nG################.###############..###.######.#######.###.#######.##T######################.###.####\r\n", "output": ["No", "NO"]}, {"input": "100 17\r\nG####.##.##.#####.####....##.####.#########.##.#..#.###############.T############.#########.#.####.#\r\n", "output": ["No", "NO"]}, {"input": "48 1\r\nT..............................................G\r\n", "output": ["YES", "Yes"]}, {"input": "23 1\r\nT.....................G\r\n", "output": ["YES", "Yes"]}, {"input": "49 1\r\nG...............................................T\r\n", "output": ["YES", "Yes"]}, {"input": "3 1\r\nTG#\r\n", "output": ["YES", "Yes"]}, {"input": "6 2\r\n..TG..\r\n", "output": ["No", "NO"]}, {"input": "14 3\r\n...G.....#..T.\r\n", "output": ["No", "NO"]}, {"input": "5 4\r\n##GT#\r\n", "output": ["No", "NO"]}, {"input": "6 2\r\nT#..G.\r\n", "output": ["YES", "Yes"]}, {"input": "12 3\r\nT.#.#.G.....\r\n", "output": ["YES", "Yes"]}, {"input": "9 1\r\n...TG#...\r\n", "output": ["YES", "Yes"]}, {"input": "5 2\r\nT.G.#\r\n", "output": ["YES", "Yes"]}, {"input": "6 1\r\nT...G#\r\n", "output": ["YES", "Yes"]}, {"input": "5 1\r\nTG###\r\n", "output": ["YES", "Yes"]}, {"input": "5 4\r\n.G..T\r\n", "output": ["No", "NO"]}, {"input": "7 2\r\nT#...#G\r\n", "output": ["YES", "Yes"]}, {"input": "7 1\r\n##TG###\r\n", "output": ["YES", "Yes"]}, {"input": "7 1\r\n###GT##\r\n", "output": ["YES", "Yes"]}, {"input": "5 2\r\nG..T.\r\n", "output": ["No", "NO"]}, {"input": "5 1\r\nG.T##\r\n", "output": ["YES", "Yes"]}, {"input": "6 2\r\nG.T###\r\n", "output": ["YES", "Yes"]}, {"input": "6 2\r\nG#T###\r\n", "output": ["YES", "Yes"]}, {"input": "10 2\r\n####T..G..\r\n", "output": ["No", "NO"]}, {"input": "3 1\r\nGT#\r\n", "output": ["YES", "Yes"]}, {"input": "4 1\r\nTG##\r\n", "output": ["YES", "Yes"]}, {"input": "6 1\r\n.G..T.\r\n", "output": ["YES", "Yes"]}, {"input": "10 3\r\n......G..T\r\n", "output": ["YES", "Yes"]}, {"input": "3 2\r\nG.T\r\n", "output": ["YES", "Yes"]}, {"input": "4 1\r\n#G.T\r\n", "output": ["YES", "Yes"]}, {"input": "5 2\r\nT#G##\r\n", "output": ["YES", "Yes"]}, {"input": "4 2\r\nG#.T\r\n", "output": ["No", "NO"]}, {"input": "4 1\r\nGT##\r\n", "output": ["YES", "Yes"]}]
100
100
100
[{'input': '6 2\r\nG#T###\r\n', 'output': ['YES', 'Yes']}, {'input': '100 17\r\nG################.#################################.################T###############################\r\n', 'output': ['No', 'NO']}, {'input': '100 99\r\nT.#...............................#............#..............................##...................G\r\n', 'output': ['YES', 'Yes']}, {'input': '12 3\r\nT.#.#.G.....\r\n', 'output': ['YES', 'Yes']}, {'input': '100 20\r\n.....G.#.#..................#.........##....#...................#.#..........#...#.#.T..#.......#...\r\n', 'output': ['YES', 'Yes']}]
[{'input': '100 20\r\n.....G................................................................................T.............\r\n', 'output': ['No', 'NO']}, {'input': '100 9\r\nT................................................................................................G..\r\n', 'output': ['No', 'NO']}, {'input': '100 9\r\nT.................................................................................................G.\r\n', 'output': ['No', 'NO']}, {'input': '6 2\r\nT#..G.\r\n', 'output': ['YES', 'Yes']}, {'input': '14 3\r\n...G.....#..T.\r\n', 'output': ['No', 'NO']}]
[{'input': '100 1\r\nT.#................................................................................................G\r\n', 'output': ['No', 'NO']}, {'input': '100 2\r\n..#####.#.#.......#.#.#...##..####..###..#.#######GT####.#.#...##...##.#..###....##.#.#..#.###....#.\r\n', 'output': ['No', 'NO']}, {'input': '100 5\r\nG####.####.####.####.####.####.####.####.####.####.####.####.####.#########.####.####.####.####T####\r\n', 'output': ['No', 'NO']}, {'input': '4 1\r\nGT##\r\n', 'output': ['YES', 'Yes']}, {'input': '5 4\r\n##GT#\r\n', 'output': ['No', 'NO']}]
[{'input': '100 5\r\nG####.####.####.####.####.####.####.####.####.####.####.####.####.#########.####.####.####.####T####\r\n', 'output': ['No', 'NO']}, {'input': '100 17\r\n.########.G##.####.#.######.###############..#.###########.##.#####.##.#####.#T.###..###.########.##\r\n', 'output': ['YES', 'Yes']}, {'input': '100 5\r\nG####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####T####\r\n', 'output': ['YES', 'Yes']}, {'input': '100 20\r\n.....G................................................................................T.............\r\n', 'output': ['No', 'NO']}, {'input': '5 2\r\nT#G##\r\n', 'output': ['YES', 'Yes']}]
[{'input': '5 1\r\nG.T##\r\n', 'output': ['YES', 'Yes']}, {'input': '14 3\r\n...G.....#..T.\r\n', 'output': ['No', 'NO']}, {'input': '48 1\r\nT..............................................G\r\n', 'output': ['YES', 'Yes']}, {'input': '100 3\r\nG..................................#......#......#.......#.#..........#........#......#..........#.T\r\n', 'output': ['No', 'NO']}, {'input': '100 9\r\nT................................................................................................G..\r\n', 'output': ['No', 'NO']}]
100
100
100
100
100
96.15
100
100
100
100
94.44
100
100
100
100
232
100
99.23
98.888
["5\n10 5 0 -5 -10", "4\n1 1 1 1", "3\n5 1 -5", "2\n900 1000"]
The first line contains a single integer n (2 ≀ n ≀ 100) β€” the number of days for which the average air temperature is known. The second line contains a sequence of integers t1, t2, ..., tn ( - 1000 ≀ ti ≀ 1000)Β β€” where ti is the average temperature in the i-th day.
d04fa4322a1b300bdf4a56f09681b17f
import java.util.*; import java.io.*; public class Main { int solve(Scanner in, PrintWriter out) { int n = in.nextInt(); int[] arr = new int[n]; for(int i = 0; i < n; i++) arr[i] = in.nextInt(); if(n == 2) out.print(arr[1] + (arr[1] - arr[0])); else{ int ans = 0; int step = arr[0] - arr[1]; for(int i = 0; i < n-1; i++){ if((arr[i] - arr[i+1]) == step) ans = arr[n-1] +(arr[1] - arr[0]); else{ ans = arr[n - 1]; break; } } out.print(ans); } return 0; } void run() { try( Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out)) { solve(in, out); } } public static void main(String[] args) { new Main().run(); } }
["-15", "1", "-5", "1100"]
Java
NoteIn the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is  - 10 - 5 =  - 15.In the second example the sequence of the average temperatures is an arithmetic progression where the first term is 1 and each following terms equals to the previous one. So the predicted average temperature in the fifth day is 1.In the third example the average temperatures do not form an arithmetic progression, so the average temperature of the fourth day equals to the temperature of the third day and equals to  - 5.In the fourth example the sequence of the average temperatures is an arithmetic progression where the first term is 900 and each the following terms increase by 100. So predicted average temperature in the third day is 1000 + 100 = 1100.
Print the average air temperature in the (n + 1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000.
Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last n days. Assume that the average air temperature for each day is integral.Vasya believes that if the average temperatures over the last n days form an arithmetic progression, where the first term equals to the average temperature on the first day, the second term equals to the average temperature on the second day and so on, then the average temperature of the next (n + 1)-th day will be equal to the next term of the arithmetic progression. Otherwise, according to Vasya's method, the temperature of the (n + 1)-th day will be equal to the temperature of the n-th day.Your task is to help Vasya predict the average temperature for tomorrow, i. e. for the (n + 1)-th day.
[{"input": "5\r\n10 5 0 -5 -10\r\n", "output": ["-15"]}, {"input": "4\r\n1 1 1 1\r\n", "output": ["1"]}, {"input": "3\r\n5 1 -5\r\n", "output": ["-5"]}, {"input": "2\r\n900 1000\r\n", "output": ["1100"]}, {"input": "2\r\n1 2\r\n", "output": ["3"]}, {"input": "3\r\n2 5 8\r\n", "output": ["11"]}, {"input": "4\r\n4 1 -2 -5\r\n", "output": ["-8"]}, {"input": "10\r\n-1000 -995 -990 -985 -980 -975 -970 -965 -960 -955\r\n", "output": ["-950"]}, {"input": "11\r\n-1000 -800 -600 -400 -200 0 200 400 600 800 1000\r\n", "output": ["1200"]}, {"input": "31\r\n1000 978 956 934 912 890 868 846 824 802 780 758 736 714 692 670 648 626 604 582 560 538 516 494 472 450 428 406 384 362 340\r\n", "output": ["318"]}, {"input": "5\r\n1000 544 88 -368 -824\r\n", "output": ["-1280"]}, {"input": "100\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n", "output": ["0"]}, {"input": "33\r\n456 411 366 321 276 231 186 141 96 51 6 -39 -84 -129 -174 -219 -264 -309 -354 -399 -444 -489 -534 -579 -624 -669 -714 -759 -804 -849 -894 -939 -984\r\n", "output": ["-1029"]}, {"input": "77\r\n-765 -742 -719 -696 -673 -650 -627 -604 -581 -558 -535 -512 -489 -466 -443 -420 -397 -374 -351 -328 -305 -282 -259 -236 -213 -190 -167 -144 -121 -98 -75 -52 -29 -6 17 40 63 86 109 132 155 178 201 224 247 270 293 316 339 362 385 408 431 454 477 500 523 546 569 592 615 638 661 684 707 730 753 776 799 822 845 868 891 914 937 960 983\r\n", "output": ["1006"]}, {"input": "3\r\n2 4 8\r\n", "output": ["8"]}, {"input": "4\r\n4 1 -3 -5\r\n", "output": ["-5"]}, {"input": "10\r\n-1000 -995 -990 -984 -980 -975 -970 -965 -960 -955\r\n", "output": ["-955"]}, {"input": "11\r\n-999 -800 -600 -400 -200 0 200 400 600 800 1000\r\n", "output": ["1000"]}, {"input": "51\r\n-9 10 30 50 70 90 110 130 150 170 190 210 230 250 270 290 310 330 350 370 390 410 430 450 470 490 510 530 550 570 590 610 630 650 670 690 710 730 750 770 790 810 830 850 870 890 910 930 950 970 990\r\n", "output": ["990"]}, {"input": "100\r\n10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 207\r\n", "output": ["207"]}, {"input": "2\r\n1000 1000\r\n", "output": ["1000"]}, {"input": "2\r\n-1000 1000\r\n", "output": ["3000"]}, {"input": "2\r\n1000 -1000\r\n", "output": ["-3000"]}, {"input": "2\r\n-1000 -1000\r\n", "output": ["-1000"]}, {"input": "100\r\n-85 -80 -76 -72 -68 -64 -60 -56 -52 -48 -44 -40 -36 -32 -28 -24 -20 -16 -12 -8 -4 0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120 124 128 132 136 140 144 148 152 156 160 164 168 172 176 180 184 188 192 196 200 204 208 212 216 220 224 228 232 236 240 244 248 252 256 260 264 268 272 276 280 284 288 292 296 300 304 308 312\r\n", "output": ["312"]}, {"input": "4\r\n1 2 4 5\r\n", "output": ["5"]}]
100
100
100
[{'input': '2\r\n-1000 -1000\r\n', 'output': ['-1000']}, {'input': '3\r\n5 1 -5\r\n', 'output': ['-5']}, {'input': '10\r\n-1000 -995 -990 -984 -980 -975 -970 -965 -960 -955\r\n', 'output': ['-955']}, {'input': '3\r\n2 5 8\r\n', 'output': ['11']}, {'input': '11\r\n-999 -800 -600 -400 -200 0 200 400 600 800 1000\r\n', 'output': ['1000']}]
[{'input': '4\r\n1 2 4 5\r\n', 'output': ['5']}, {'input': '3\r\n2 4 8\r\n', 'output': ['8']}, {'input': '5\r\n1000 544 88 -368 -824\r\n', 'output': ['-1280']}, {'input': '33\r\n456 411 366 321 276 231 186 141 96 51 6 -39 -84 -129 -174 -219 -264 -309 -354 -399 -444 -489 -534 -579 -624 -669 -714 -759 -804 -849 -894 -939 -984\r\n', 'output': ['-1029']}, {'input': '11\r\n-1000 -800 -600 -400 -200 0 200 400 600 800 1000\r\n', 'output': ['1200']}]
[{'input': '11\r\n-999 -800 -600 -400 -200 0 200 400 600 800 1000\r\n', 'output': ['1000']}, {'input': '10\r\n-1000 -995 -990 -984 -980 -975 -970 -965 -960 -955\r\n', 'output': ['-955']}, {'input': '4\r\n4 1 -2 -5\r\n', 'output': ['-8']}, {'input': '33\r\n456 411 366 321 276 231 186 141 96 51 6 -39 -84 -129 -174 -219 -264 -309 -354 -399 -444 -489 -534 -579 -624 -669 -714 -759 -804 -849 -894 -939 -984\r\n', 'output': ['-1029']}, {'input': '11\r\n-1000 -800 -600 -400 -200 0 200 400 600 800 1000\r\n', 'output': ['1200']}]
[{'input': '11\r\n-1000 -800 -600 -400 -200 0 200 400 600 800 1000\r\n', 'output': ['1200']}, {'input': '77\r\n-765 -742 -719 -696 -673 -650 -627 -604 -581 -558 -535 -512 -489 -466 -443 -420 -397 -374 -351 -328 -305 -282 -259 -236 -213 -190 -167 -144 -121 -98 -75 -52 -29 -6 17 40 63 86 109 132 155 178 201 224 247 270 293 316 339 362 385 408 431 454 477 500 523 546 569 592 615 638 661 684 707 730 753 776 799 822 845 868 891 914 937 960 983\r\n', 'output': ['1006']}, {'input': '4\r\n1 2 4 5\r\n', 'output': ['5']}, {'input': '3\r\n5 1 -5\r\n', 'output': ['-5']}, {'input': '2\r\n-1000 1000\r\n', 'output': ['3000']}]
[{'input': '100\r\n-85 -80 -76 -72 -68 -64 -60 -56 -52 -48 -44 -40 -36 -32 -28 -24 -20 -16 -12 -8 -4 0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120 124 128 132 136 140 144 148 152 156 160 164 168 172 176 180 184 188 192 196 200 204 208 212 216 220 224 228 232 236 240 244 248 252 256 260 264 268 272 276 280 284 288 292 296 300 304 308 312\r\n', 'output': ['312']}, {'input': '2\r\n1 2\r\n', 'output': ['3']}, {'input': '2\r\n1000 1000\r\n', 'output': ['1000']}, {'input': '4\r\n4 1 -2 -5\r\n', 'output': ['-8']}, {'input': '51\r\n-9 10 30 50 70 90 110 130 150 170 190 210 230 250 270 290 310 330 350 370 390 410 430 450 470 490 510 530 550 570 590 610 630 650 670 690 710 730 750 770 790 810 830 850 870 890 910 930 950 970 990\r\n', 'output': ['990']}]
100
100
100
100
100
100
95.24
95.24
100
100
100
87.5
87.5
100
100
233
100
98.096
95
["5\n3 4 5 6 7", "7\n12 13 14 15 14 13 12", "1\n8"]
The first line of the input contains a single integer n (1 ≀ n ≀ 92)Β β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15)Β β€” Vitya's records. It's guaranteed that the input data is consistent.
8330d9fea8d50a79741507b878da0a75
import java.util.Scanner; public class Vitya { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] t = new int[n]; for (int i=0;i<n;i++) { t[i]=scanner.nextInt(); } if (n==1) {if(t[0]==15) {System.out.println("DOWN");}else if(t[0]==0) {System.out.println("UP");}else{System.out.println(-1);} } else { if((t[n-2]<t[n-1]&& t[n-1]!=15)||t[n-1]==0) {System.out.println("UP");} else{System.out.println("DOWN");} } } }
["UP", "DOWN", "-1"]
Java
NoteIn the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1.
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0.As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has.
[{"input": "5\r\n3 4 5 6 7\r\n", "output": ["UP"]}, {"input": "7\r\n12 13 14 15 14 13 12\r\n", "output": ["DOWN"]}, {"input": "1\r\n8\r\n", "output": ["-1"]}, {"input": "44\r\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10\r\n", "output": ["DOWN"]}, {"input": "92\r\n3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4\r\n", "output": ["UP"]}, {"input": "6\r\n10 11 12 13 14 15\r\n", "output": ["DOWN"]}, {"input": "27\r\n11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\r\n", "output": ["DOWN"]}, {"input": "6\r\n8 7 6 5 4 3\r\n", "output": ["DOWN"]}, {"input": "27\r\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10\r\n", "output": ["UP"]}, {"input": "79\r\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5\r\n", "output": ["DOWN"]}, {"input": "25\r\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7\r\n", "output": ["DOWN"]}, {"input": "21\r\n3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7\r\n", "output": ["DOWN"]}, {"input": "56\r\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6\r\n", "output": ["DOWN"]}, {"input": "19\r\n4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14\r\n", "output": ["UP"]}, {"input": "79\r\n5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13\r\n", "output": ["UP"]}, {"input": "87\r\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10\r\n", "output": ["UP"]}, {"input": "13\r\n10 9 8 7 6 5 4 3 2 1 0 1 2\r\n", "output": ["UP"]}, {"input": "2\r\n8 9\r\n", "output": ["UP"]}, {"input": "3\r\n10 11 12\r\n", "output": ["UP"]}, {"input": "1\r\n1\r\n", "output": ["-1"]}, {"input": "1\r\n2\r\n", "output": ["-1"]}, {"input": "1\r\n3\r\n", "output": ["-1"]}, {"input": "1\r\n4\r\n", "output": ["-1"]}, {"input": "1\r\n5\r\n", "output": ["-1"]}, {"input": "1\r\n6\r\n", "output": ["-1"]}, {"input": "1\r\n7\r\n", "output": ["-1"]}, {"input": "1\r\n9\r\n", "output": ["-1"]}, {"input": "1\r\n10\r\n", "output": ["-1"]}, {"input": "1\r\n11\r\n", "output": ["-1"]}, {"input": "1\r\n12\r\n", "output": ["-1"]}, {"input": "1\r\n13\r\n", "output": ["-1"]}, {"input": "1\r\n14\r\n", "output": ["-1"]}, {"input": "1\r\n15\r\n", "output": ["DOWN"]}, {"input": "1\r\n0\r\n", "output": ["UP"]}, {"input": "3\r\n11 12 13\r\n", "output": ["UP"]}, {"input": "2\r\n10 9\r\n", "output": ["DOWN"]}, {"input": "92\r\n10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11\r\n", "output": ["UP"]}, {"input": "92\r\n7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6\r\n", "output": ["DOWN"]}, {"input": "2\r\n14 15\r\n", "output": ["DOWN"]}, {"input": "2\r\n1 0\r\n", "output": ["UP"]}, {"input": "2\r\n15 14\r\n", "output": ["DOWN"]}, {"input": "92\r\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8\r\n", "output": ["UP"]}, {"input": "92\r\n13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12\r\n", "output": ["DOWN"]}, {"input": "92\r\n4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3\r\n", "output": ["DOWN"]}, {"input": "92\r\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\r\n", "output": ["DOWN"]}, {"input": "92\r\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0\r\n", "output": ["UP"]}, {"input": "2\r\n2 1\r\n", "output": ["DOWN"]}, {"input": "3\r\n2 1 0\r\n", "output": ["UP"]}, {"input": "5\r\n4 3 2 1 0\r\n", "output": ["UP"]}, {"input": "2\r\n5 4\r\n", "output": ["DOWN"]}, {"input": "4\r\n3 2 1 0\r\n", "output": ["UP"]}, {"input": "3\r\n13 12 11\r\n", "output": ["DOWN"]}, {"input": "2\r\n1 2\r\n", "output": ["UP"]}, {"input": "2\r\n0 1\r\n", "output": ["UP"]}, {"input": "2\r\n13 14\r\n", "output": ["UP"]}, {"input": "14\r\n13 12 11 10 9 8 7 6 5 4 3 2 1 0\r\n", "output": ["UP"]}]
100
100
100
[{'input': '92\r\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0\r\n', 'output': ['UP']}, {'input': '1\r\n14\r\n', 'output': ['-1']}, {'input': '1\r\n4\r\n', 'output': ['-1']}, {'input': '1\r\n7\r\n', 'output': ['-1']}, {'input': '1\r\n15\r\n', 'output': ['DOWN']}]
[{'input': '2\r\n8 9\r\n', 'output': ['UP']}, {'input': '27\r\n11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\r\n', 'output': ['DOWN']}, {'input': '3\r\n2 1 0\r\n', 'output': ['UP']}, {'input': '1\r\n13\r\n', 'output': ['-1']}, {'input': '2\r\n1 2\r\n', 'output': ['UP']}]
[{'input': '92\r\n10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11\r\n', 'output': ['UP']}, {'input': '3\r\n10 11 12\r\n', 'output': ['UP']}, {'input': '27\r\n11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\r\n', 'output': ['DOWN']}, {'input': '13\r\n10 9 8 7 6 5 4 3 2 1 0 1 2\r\n', 'output': ['UP']}, {'input': '1\r\n3\r\n', 'output': ['-1']}]
[{'input': '3\r\n2 1 0\r\n', 'output': ['UP']}, {'input': '2\r\n14 15\r\n', 'output': ['DOWN']}, {'input': '2\r\n10 9\r\n', 'output': ['DOWN']}, {'input': '13\r\n10 9 8 7 6 5 4 3 2 1 0 1 2\r\n', 'output': ['UP']}, {'input': '21\r\n3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7\r\n', 'output': ['DOWN']}]
[{'input': '44\r\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10\r\n', 'output': ['DOWN']}, {'input': '1\r\n13\r\n', 'output': ['-1']}, {'input': '6\r\n10 11 12 13 14 15\r\n', 'output': ['DOWN']}, {'input': '6\r\n8 7 6 5 4 3\r\n', 'output': ['DOWN']}, {'input': '79\r\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5\r\n', 'output': ['DOWN']}]
100
100
100
100
100
88.89
100
100
100
100
64.29
85.71
71.43
64.29
71.43
234
100
97.778
71.43
["4\nZCTH", "5\nZDATG", "6\nAFBAKC"]
The first line contains a single integer $$$n$$$ ($$$4 \leq n \leq 50$$$)Β β€” the length of the string $$$s$$$. The second line contains the string $$$s$$$, consisting of exactly $$$n$$$ uppercase letters of the Latin alphabet.
ee4f88abe4c9fa776abd15c5f3a94543
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; import java.util.Scanner; /** * * @author Lalo */ public class ContestSandbox { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); int length = Integer.parseInt(in.nextLine()); String s = in.nextLine(); String genome = "ACTG"; int miniumChanges = 3215643; Map<String, Integer> alphabet = new HashMap<>(); int a = 1; for (char ch = 'A'; ch <= 'Z'; ch++) { alphabet.put(String.valueOf(ch), a); a++; } for (int i = 0; (i + 4) <= length; i++) { int sum = 0; for (int x = 0; x < 4; x++) { if (Math.abs(alphabet.get(genome.substring(x, x + 1)) - alphabet.get(s.substring(i + x, i + x + 1))) <= 13) { sum += Math.abs(alphabet.get(genome.substring(x, x + 1)) - alphabet.get(s.substring(i + x, i + x + 1))); } else if (alphabet.get(s.substring(i + x, i + x + 1)) > alphabet.get(genome.substring(x, x + 1))) { sum += (26 - alphabet.get(s.substring(i + x, i + x + 1)) + alphabet.get(genome.substring(x, x + 1))); } else { sum += (26 - alphabet.get(genome.substring(x, x + 1)) + alphabet.get(s.substring(i + x, i + x + 1))); } } if (sum < miniumChanges) { miniumChanges = sum; } } System.out.println(miniumChanges); } }
["2", "5", "16"]
Java
NoteIn the first example, you should replace the letter "Z" with "A" for one operation, the letter "H"Β β€” with the letter "G" for one operation. You will get the string "ACTG", in which the genome is present as a substring.In the second example, we replace the letter "A" with "C" for two operations, the letter "D"Β β€” with the letter "A" for three operations. You will get the string "ZACTG", in which there is a genome.
Output the minimum number of operations that need to be applied to the string $$$s$$$ so that the genome appears as a substring in it.
Today in the scientific lyceum of the Kingdom of Kremland, there was a biology lesson. The topic of the lesson was the genomes. Let's call the genome the string "ACTG".Maxim was very boring to sit in class, so the teacher came up with a task for him: on a given string $$$s$$$ consisting of uppercase letters and length of at least $$$4$$$, you need to find the minimum number of operations that you need to apply, so that the genome appears in it as a substring. For one operation, you can replace any letter in the string $$$s$$$ with the next or previous in the alphabet. For example, for the letter "D" the previous one will be "C", and the nextΒ β€” "E". In this problem, we assume that for the letter "A", the previous one will be the letter "Z", and the next one will be "B", and for the letter "Z", the previous one is the letter "Y", and the next one is the letter "A".Help Maxim solve the problem that the teacher gave him.A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
[{"input": "4\r\nZCTH\r\n", "output": ["2"]}, {"input": "5\r\nZDATG\r\n", "output": ["5"]}, {"input": "6\r\nAFBAKC\r\n", "output": ["16"]}, {"input": "9\r\nAAABBBCCC\r\n", "output": ["14"]}, {"input": "8\r\nABCDABCD\r\n", "output": ["13"]}, {"input": "4\r\nNPGT\r\n", "output": ["52"]}, {"input": "10\r\nABABABABAB\r\n", "output": ["13"]}, {"input": "8\r\nBBAACCZZ\r\n", "output": ["14"]}, {"input": "50\r\nALWLSFLXYPQYMIWXMYMXFYMIVFYJDTJAIGVOAUDAIIAHKNNVTX\r\n", "output": ["13"]}, {"input": "30\r\nTHCVHIPLYOOFCNWQJMBMEDTXLTCKMF\r\n", "output": ["10"]}, {"input": "39\r\nIHESTJHHSZRSHNUSPGMHDTKOJFEFLAUDXUEQWLO\r\n", "output": ["11"]}, {"input": "33\r\nIQHJDOVAGCIAEBAIXQYQCDVZGVOYIIYPR\r\n", "output": ["12"]}, {"input": "32\r\nIWMQCTKRNXICANQUPLBOMDNRBOWWIXZB\r\n", "output": ["14"]}, {"input": "6\r\nNQNEVX\r\n", "output": ["26"]}, {"input": "17\r\nGNPBRASKVPECJKECD\r\n", "output": ["16"]}, {"input": "18\r\nKNGWZFHGQIADTBYWDC\r\n", "output": ["6"]}, {"input": "14\r\nZXPFXCBVESQGAE\r\n", "output": ["7"]}, {"input": "37\r\nINUZOUSGLBHKDEFTQANRPIYMIBFLRTYFNWIFQ\r\n", "output": ["17"]}, {"input": "50\r\nVKRGXLUWYURTRNGAODFLYCKAPHGPHGDLWIGXEYVOAVYYXVDRAB\r\n", "output": ["12"]}, {"input": "50\r\nGOHDHOWWPMZBSEKHDBDKLIYRFEPOUHIHOHPUMVDAQRZDJMUBWV\r\n", "output": ["5"]}, {"input": "50\r\nQFWWIROYKRLAYBPSEXATCWILUBAZPWSGSKLTBLZOLZPHJKQQGF\r\n", "output": ["9"]}, {"input": "50\r\nROWGGKNUITVHOBMKZXOZNBZMQGSFERNCZDFKLRBCFVVDXJEFLP\r\n", "output": ["13"]}, {"input": "50\r\nYUPJIRNPTCFJIPODTHJXTWJUTLKCUYFNZKMJRBZZYBPEDYLKCY\r\n", "output": ["9"]}, {"input": "50\r\nZOMSHKIFVAMFATEIIEUJVITTYZGDWCGSOJMFQNYACRPOLGUZCM\r\n", "output": ["9"]}, {"input": "50\r\nLQFSFNEFCPBEARPMOGSSQVHAGNKOQXXCZKHSAEPTEHWOWSZMKH\r\n", "output": ["13"]}, {"input": "50\r\nHKKUWHLYYKBLLEHKVNIRYAPVFTAPRIFUZELKGRDXZNCNWHSAFG\r\n", "output": ["14"]}, {"input": "50\r\nMGDXLMPDPKUQOIMTLDUDTGTOMJCSYNRTSQSJANYDDPWQYTDTAW\r\n", "output": ["7"]}, {"input": "8\r\nACTGACTG\r\n", "output": ["0"]}, {"input": "10\r\nZZZZZZZZZZ\r\n", "output": ["17"]}, {"input": "8\r\nNPGTNPGT\r\n", "output": ["22"]}, {"input": "5\r\nACTGA\r\n", "output": ["0"]}, {"input": "4\r\nAZTG\r\n", "output": ["3"]}, {"input": "4\r\nYCTG\r\n", "output": ["2"]}, {"input": "4\r\nANTG\r\n", "output": ["11"]}, {"input": "4\r\nOCTG\r\n", "output": ["12"]}, {"input": "4\r\nACHG\r\n", "output": ["12"]}]
100
100
100
[{'input': '4\r\nNPGT\r\n', 'output': ['52']}, {'input': '50\r\nMGDXLMPDPKUQOIMTLDUDTGTOMJCSYNRTSQSJANYDDPWQYTDTAW\r\n', 'output': ['7']}, {'input': '33\r\nIQHJDOVAGCIAEBAIXQYQCDVZGVOYIIYPR\r\n', 'output': ['12']}, {'input': '50\r\nQFWWIROYKRLAYBPSEXATCWILUBAZPWSGSKLTBLZOLZPHJKQQGF\r\n', 'output': ['9']}, {'input': '5\r\nZDATG\r\n', 'output': ['5']}]
[{'input': '50\r\nQFWWIROYKRLAYBPSEXATCWILUBAZPWSGSKLTBLZOLZPHJKQQGF\r\n', 'output': ['9']}, {'input': '8\r\nBBAACCZZ\r\n', 'output': ['14']}, {'input': '50\r\nZOMSHKIFVAMFATEIIEUJVITTYZGDWCGSOJMFQNYACRPOLGUZCM\r\n', 'output': ['9']}, {'input': '39\r\nIHESTJHHSZRSHNUSPGMHDTKOJFEFLAUDXUEQWLO\r\n', 'output': ['11']}, {'input': '9\r\nAAABBBCCC\r\n', 'output': ['14']}]
[{'input': '8\r\nABCDABCD\r\n', 'output': ['13']}, {'input': '50\r\nGOHDHOWWPMZBSEKHDBDKLIYRFEPOUHIHOHPUMVDAQRZDJMUBWV\r\n', 'output': ['5']}, {'input': '32\r\nIWMQCTKRNXICANQUPLBOMDNRBOWWIXZB\r\n', 'output': ['14']}, {'input': '17\r\nGNPBRASKVPECJKECD\r\n', 'output': ['16']}, {'input': '10\r\nZZZZZZZZZZ\r\n', 'output': ['17']}]
[{'input': '4\r\nAZTG\r\n', 'output': ['3']}, {'input': '17\r\nGNPBRASKVPECJKECD\r\n', 'output': ['16']}, {'input': '50\r\nALWLSFLXYPQYMIWXMYMXFYMIVFYJDTJAIGVOAUDAIIAHKNNVTX\r\n', 'output': ['13']}, {'input': '4\r\nACHG\r\n', 'output': ['12']}, {'input': '50\r\nZOMSHKIFVAMFATEIIEUJVITTYZGDWCGSOJMFQNYACRPOLGUZCM\r\n', 'output': ['9']}]
[{'input': '33\r\nIQHJDOVAGCIAEBAIXQYQCDVZGVOYIIYPR\r\n', 'output': ['12']}, {'input': '50\r\nALWLSFLXYPQYMIWXMYMXFYMIVFYJDTJAIGVOAUDAIIAHKNNVTX\r\n', 'output': ['13']}, {'input': '4\r\nNPGT\r\n', 'output': ['52']}, {'input': '6\r\nAFBAKC\r\n', 'output': ['16']}, {'input': '4\r\nACHG\r\n', 'output': ['12']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
235
100
100
100
["1 4 2", "5 5 5", "0 2 0"]
The only line contains three integers l, r and a (0 ≀ l, r, a ≀ 100) β€” the number of left-handers, the number of right-handers and the number of ambidexters at the training.
e8148140e61baffd0878376ac5f3857c
// Why do we fall ? So we can learn to pick ourselves up. import java.util.*; public class solve { static int mod = 1000000007; static int mod1 = 998244353; public static void main(String[] args){ Scanner sc = new Scanner(System.in); int lll = sc.nextInt(),rrr = sc.nextInt(),a = sc.nextInt(); int l = Math.min(lll,rrr),r = Math.max(lll,rrr); if(lll==rrr) System.out.println(2*(l+a/2)); else { int ll = Math.min(r-l,a); l += ll; int aa = a-ll; System.out.println(2*(l+aa/2)); } } }
["6", "14", "0"]
Java
NoteIn the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
Print a single even integerΒ β€” the maximum number of players in the team. It is possible that the team can only have zero number of players.
You are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and a ambidexters, who can play with left or right hand.The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
[{"input": "1 4 2\r\n", "output": ["6"]}, {"input": "5 5 5\r\n", "output": ["14"]}, {"input": "0 2 0\r\n", "output": ["0"]}, {"input": "30 70 34\r\n", "output": ["128"]}, {"input": "89 32 24\r\n", "output": ["112"]}, {"input": "89 44 77\r\n", "output": ["210"]}, {"input": "0 0 0\r\n", "output": ["0"]}, {"input": "100 100 100\r\n", "output": ["300"]}, {"input": "1 1 1\r\n", "output": ["2"]}, {"input": "30 70 35\r\n", "output": ["130"]}, {"input": "89 44 76\r\n", "output": ["208"]}, {"input": "0 100 100\r\n", "output": ["200"]}, {"input": "100 0 100\r\n", "output": ["200"]}, {"input": "100 1 100\r\n", "output": ["200"]}, {"input": "1 100 100\r\n", "output": ["200"]}, {"input": "100 100 0\r\n", "output": ["200"]}, {"input": "100 100 1\r\n", "output": ["200"]}, {"input": "1 2 1\r\n", "output": ["4"]}, {"input": "0 0 100\r\n", "output": ["100"]}, {"input": "0 100 0\r\n", "output": ["0"]}, {"input": "100 0 0\r\n", "output": ["0"]}, {"input": "10 8 7\r\n", "output": ["24"]}, {"input": "45 47 16\r\n", "output": ["108"]}, {"input": "59 43 100\r\n", "output": ["202"]}, {"input": "34 1 30\r\n", "output": ["62"]}, {"input": "14 81 1\r\n", "output": ["30"]}, {"input": "53 96 94\r\n", "output": ["242"]}, {"input": "62 81 75\r\n", "output": ["218"]}, {"input": "21 71 97\r\n", "output": ["188"]}, {"input": "49 82 73\r\n", "output": ["204"]}, {"input": "88 19 29\r\n", "output": ["96"]}, {"input": "89 4 62\r\n", "output": ["132"]}, {"input": "58 3 65\r\n", "output": ["126"]}, {"input": "27 86 11\r\n", "output": ["76"]}, {"input": "35 19 80\r\n", "output": ["134"]}, {"input": "4 86 74\r\n", "output": ["156"]}, {"input": "32 61 89\r\n", "output": ["182"]}, {"input": "68 60 98\r\n", "output": ["226"]}, {"input": "37 89 34\r\n", "output": ["142"]}, {"input": "92 9 28\r\n", "output": ["74"]}, {"input": "79 58 98\r\n", "output": ["234"]}, {"input": "35 44 88\r\n", "output": ["166"]}, {"input": "16 24 19\r\n", "output": ["58"]}, {"input": "74 71 75\r\n", "output": ["220"]}, {"input": "83 86 99\r\n", "output": ["268"]}, {"input": "97 73 15\r\n", "output": ["176"]}, {"input": "77 76 73\r\n", "output": ["226"]}, {"input": "48 85 55\r\n", "output": ["188"]}, {"input": "1 2 2\r\n", "output": ["4"]}, {"input": "2 2 2\r\n", "output": ["6"]}, {"input": "2 1 2\r\n", "output": ["4"]}, {"input": "2 2 1\r\n", "output": ["4"]}, {"input": "3 2 1\r\n", "output": ["6"]}, {"input": "1 2 3\r\n", "output": ["6"]}, {"input": "1 3 2\r\n", "output": ["6"]}, {"input": "2 1 3\r\n", "output": ["6"]}, {"input": "2 3 1\r\n", "output": ["6"]}, {"input": "3 1 2\r\n", "output": ["6"]}, {"input": "99 99 99\r\n", "output": ["296"]}, {"input": "99 99 100\r\n", "output": ["298"]}, {"input": "99 100 99\r\n", "output": ["298"]}, {"input": "99 100 100\r\n", "output": ["298"]}, {"input": "100 99 99\r\n", "output": ["298"]}, {"input": "100 99 100\r\n", "output": ["298"]}, {"input": "100 100 99\r\n", "output": ["298"]}, {"input": "89 32 23\r\n", "output": ["110"]}, {"input": "4 5 0\r\n", "output": ["8"]}, {"input": "3 0 3\r\n", "output": ["6"]}, {"input": "0 0 2\r\n", "output": ["2"]}, {"input": "97 97 0\r\n", "output": ["194"]}, {"input": "1 4 0\r\n", "output": ["2"]}, {"input": "5 2 0\r\n", "output": ["4"]}, {"input": "0 5 10\r\n", "output": ["14"]}, {"input": "0 1 2\r\n", "output": ["2"]}, {"input": "5 2 3\r\n", "output": ["10"]}, {"input": "5 5 0\r\n", "output": ["10"]}, {"input": "0 0 10\r\n", "output": ["10"]}, {"input": "0 1 1\r\n", "output": ["2"]}, {"input": "0 0 1\r\n", "output": ["0"]}]
100
100
100
[{'input': '97 97 0\r\n', 'output': ['194']}, {'input': '89 44 76\r\n', 'output': ['208']}, {'input': '1 2 3\r\n', 'output': ['6']}, {'input': '5 2 3\r\n', 'output': ['10']}, {'input': '0 2 0\r\n', 'output': ['0']}]
[{'input': '99 99 100\r\n', 'output': ['298']}, {'input': '30 70 35\r\n', 'output': ['130']}, {'input': '100 99 99\r\n', 'output': ['298']}, {'input': '14 81 1\r\n', 'output': ['30']}, {'input': '4 5 0\r\n', 'output': ['8']}]
[{'input': '100 100 99\r\n', 'output': ['298']}, {'input': '0 1 2\r\n', 'output': ['2']}, {'input': '49 82 73\r\n', 'output': ['204']}, {'input': '5 5 0\r\n', 'output': ['10']}, {'input': '62 81 75\r\n', 'output': ['218']}]
[{'input': '100 99 99\r\n', 'output': ['298']}, {'input': '0 100 0\r\n', 'output': ['0']}, {'input': '1 100 100\r\n', 'output': ['200']}, {'input': '83 86 99\r\n', 'output': ['268']}, {'input': '1 1 1\r\n', 'output': ['2']}]
[{'input': '74 71 75\r\n', 'output': ['220']}, {'input': '5 2 3\r\n', 'output': ['10']}, {'input': '32 61 89\r\n', 'output': ['182']}, {'input': '1 2 3\r\n', 'output': ['6']}, {'input': '14 81 1\r\n', 'output': ['30']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
50
236
100
100
90
["7 3\n3 5 7 1 6 2 8\n1 2 7", "4 4\n3 4 1 0\n0 1 7 9"]
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10$$$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $$$n$$$ distinct space-separated integers $$$x_1, x_2, \ldots, x_n$$$ ($$$0 \le x_i \le 9$$$) representing the sequence. The next line contains $$$m$$$ distinct space-separated integers $$$y_1, y_2, \ldots, y_m$$$ ($$$0 \le y_i \le 9$$$) β€” the keys with fingerprints.
f9044a4b4c3a0c2751217d9b31cd0c72
import java.util.*; public class A { public static void main(String[] args) { int n,m; Scanner s = new Scanner(System.in); n = s.nextInt(); m = s.nextInt(); int a[] = new int[n]; int b[] = new int[m]; for(int i = 0 ; i < n ; i++) { a[i] = s.nextInt(); } for(int j = 0 ; j < m ; j++) { b[j] = s.nextInt(); } for(int i1 = 0 ; i1 < n ; i1++) { for(int j1 = 0 ; j1 < m ; j1++) { if(a[i1] == b[j1]) { System.out.print(a[i1] + " "); } } } } }
["7 1 2", "1 0"]
Java
NoteIn the first example, the only digits with fingerprints are $$$1$$$, $$$2$$$ and $$$7$$$. All three of them appear in the sequence you know, $$$7$$$ first, then $$$1$$$ and then $$$2$$$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.In the second example digits $$$0$$$, $$$1$$$, $$$7$$$ and $$$9$$$ have fingerprints, however only $$$0$$$ and $$$1$$$ appear in the original sequence. $$$1$$$ appears earlier, so the output is 1 0. Again, the order is important.
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.
[{"input": "7 3\r\n3 5 7 1 6 2 8\r\n1 2 7\r\n", "output": ["7 1 2"]}, {"input": "4 4\r\n3 4 1 0\r\n0 1 7 9\r\n", "output": ["1 0"]}, {"input": "9 4\r\n9 8 7 6 5 4 3 2 1\r\n2 4 6 8\r\n", "output": ["8 6 4 2"]}, {"input": "10 5\r\n3 7 1 2 4 6 9 0 5 8\r\n4 3 0 7 9\r\n", "output": ["3 7 4 9 0"]}, {"input": "5 5\r\n1 2 3 4 5\r\n6 7 8 9 0\r\n", "output": [""]}, {"input": "10 10\r\n1 2 3 4 5 6 7 8 9 0\r\n4 5 6 7 1 2 3 0 9 8\r\n", "output": ["1 2 3 4 5 6 7 8 9 0"]}, {"input": "1 1\r\n4\r\n4\r\n", "output": ["4"]}, {"input": "3 7\r\n6 3 4\r\n4 9 0 1 7 8 6\r\n", "output": ["6 4"]}, {"input": "10 1\r\n9 0 8 1 7 4 6 5 2 3\r\n0\r\n", "output": ["0"]}, {"input": "6 1\r\n4 2 7 3 1 8\r\n9\r\n", "output": [""]}, {"input": "5 10\r\n6 0 3 8 1\r\n3 1 0 5 4 7 2 8 9 6\r\n", "output": ["6 0 3 8 1"]}, {"input": "8 2\r\n7 2 9 6 1 0 3 4\r\n6 3\r\n", "output": ["6 3"]}, {"input": "5 4\r\n7 0 1 4 9\r\n0 9 5 3\r\n", "output": ["0 9"]}, {"input": "10 1\r\n9 6 2 0 1 8 3 4 7 5\r\n6\r\n", "output": ["6"]}, {"input": "10 2\r\n7 1 0 2 4 6 5 9 3 8\r\n3 2\r\n", "output": ["2 3"]}, {"input": "5 9\r\n3 7 9 2 4\r\n3 8 4 5 9 6 1 0 2\r\n", "output": ["3 9 2 4"]}, {"input": "10 6\r\n7 1 2 3 8 0 6 4 5 9\r\n1 5 8 2 3 6\r\n", "output": ["1 2 3 8 6 5"]}, {"input": "8 2\r\n7 4 8 9 2 5 6 1\r\n6 4\r\n", "output": ["4 6"]}, {"input": "10 2\r\n1 0 3 5 8 9 4 7 6 2\r\n0 3\r\n", "output": ["0 3"]}, {"input": "7 6\r\n9 2 8 6 1 3 7\r\n4 2 0 3 1 8\r\n", "output": ["2 8 1 3"]}, {"input": "1 6\r\n3\r\n6 8 2 4 5 3\r\n", "output": ["3"]}, {"input": "1 8\r\n0\r\n9 2 4 8 1 5 0 7\r\n", "output": ["0"]}, {"input": "6 9\r\n7 3 9 4 1 0\r\n9 1 5 8 0 6 2 7 4\r\n", "output": ["7 9 4 1 0"]}, {"input": "10 2\r\n4 9 6 8 3 0 1 5 7 2\r\n0 1\r\n", "output": ["0 1"]}, {"input": "10 5\r\n5 2 8 0 9 7 6 1 4 3\r\n9 6 4 1 2\r\n", "output": ["2 9 6 1 4"]}, {"input": "6 3\r\n8 3 9 2 7 6\r\n5 4 3\r\n", "output": ["3"]}, {"input": "4 10\r\n8 3 9 6\r\n4 9 6 2 7 0 8 1 3 5\r\n", "output": ["8 3 9 6"]}, {"input": "1 2\r\n1\r\n1 0\r\n", "output": ["1"]}, {"input": "3 6\r\n1 2 3\r\n4 5 6 1 2 3\r\n", "output": ["1 2 3"]}, {"input": "1 2\r\n2\r\n1 2\r\n", "output": ["2"]}, {"input": "1 10\r\n9\r\n0 1 2 3 4 5 6 7 8 9\r\n", "output": ["9"]}]
100
100
100
[{'input': '10 6\r\n7 1 2 3 8 0 6 4 5 9\r\n1 5 8 2 3 6\r\n', 'output': ['1 2 3 8 6 5']}, {'input': '1 10\r\n9\r\n0 1 2 3 4 5 6 7 8 9\r\n', 'output': ['9']}, {'input': '10 5\r\n5 2 8 0 9 7 6 1 4 3\r\n9 6 4 1 2\r\n', 'output': ['2 9 6 1 4']}, {'input': '5 4\r\n7 0 1 4 9\r\n0 9 5 3\r\n', 'output': ['0 9']}, {'input': '6 3\r\n8 3 9 2 7 6\r\n5 4 3\r\n', 'output': ['3']}]
[{'input': '10 6\r\n7 1 2 3 8 0 6 4 5 9\r\n1 5 8 2 3 6\r\n', 'output': ['1 2 3 8 6 5']}, {'input': '3 6\r\n1 2 3\r\n4 5 6 1 2 3\r\n', 'output': ['1 2 3']}, {'input': '4 10\r\n8 3 9 6\r\n4 9 6 2 7 0 8 1 3 5\r\n', 'output': ['8 3 9 6']}, {'input': '6 1\r\n4 2 7 3 1 8\r\n9\r\n', 'output': ['']}, {'input': '5 10\r\n6 0 3 8 1\r\n3 1 0 5 4 7 2 8 9 6\r\n', 'output': ['6 0 3 8 1']}]
[{'input': '3 7\r\n6 3 4\r\n4 9 0 1 7 8 6\r\n', 'output': ['6 4']}, {'input': '8 2\r\n7 2 9 6 1 0 3 4\r\n6 3\r\n', 'output': ['6 3']}, {'input': '3 6\r\n1 2 3\r\n4 5 6 1 2 3\r\n', 'output': ['1 2 3']}, {'input': '10 2\r\n1 0 3 5 8 9 4 7 6 2\r\n0 3\r\n', 'output': ['0 3']}, {'input': '10 1\r\n9 0 8 1 7 4 6 5 2 3\r\n0\r\n', 'output': ['0']}]
[{'input': '1 2\r\n1\r\n1 0\r\n', 'output': ['1']}, {'input': '10 2\r\n1 0 3 5 8 9 4 7 6 2\r\n0 3\r\n', 'output': ['0 3']}, {'input': '6 3\r\n8 3 9 2 7 6\r\n5 4 3\r\n', 'output': ['3']}, {'input': '10 1\r\n9 6 2 0 1 8 3 4 7 5\r\n6\r\n', 'output': ['6']}, {'input': '10 5\r\n3 7 1 2 4 6 9 0 5 8\r\n4 3 0 7 9\r\n', 'output': ['3 7 4 9 0']}]
[{'input': '5 9\r\n3 7 9 2 4\r\n3 8 4 5 9 6 1 0 2\r\n', 'output': ['3 9 2 4']}, {'input': '8 2\r\n7 4 8 9 2 5 6 1\r\n6 4\r\n', 'output': ['4 6']}, {'input': '10 2\r\n4 9 6 8 3 0 1 5 7 2\r\n0 1\r\n', 'output': ['0 1']}, {'input': '6 3\r\n8 3 9 2 7 6\r\n5 4 3\r\n', 'output': ['3']}, {'input': '10 2\r\n7 1 0 2 4 6 5 9 3 8\r\n3 2\r\n', 'output': ['2 3']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
237
100
100
100
["1", "2", "3"]
A single line contains a single integer n (1 ≀ n ≀ 4000).
aa2c3e94a44053a0d86f61da06681023
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 { long[] equivalence_relations; int[][] bc; public void solve(int testNumber, InputReader in, PrintWriter out) { int N = in.nextInt(); int MOD = 1000000007; long ans = 0; compute_equivalence_relations(N, MOD); compute_binomial_coefficients(N, MOD); for (int m = 0; m < N; m++) { ans = (ans + equivalence_relations[m] * bc[N][N - m]) % MOD; } out.println(ans); } private void compute_binomial_coefficients(int N, int MOD) { bc = new int[N + 1][N + 1]; for (int n = 1; n <= N; n++) { for (int k = 0; k <= n; k++) { if (k == 0) bc[n][k] = 1; else if (n == k) bc[n][k] = 1; else bc[n][k] = (bc[n - 1][k - 1] + bc[n - 1][k]) % MOD; } } } private void compute_equivalence_relations(int N, int MOD) { long dp[][] = new long[N + 1][N + 1]; dp[0][0] = 1; for (int elems = 1; elems <= N; elems++) { for (int classes = 1; classes <= elems; classes++) { dp[elems][classes] = (long) (classes) * dp[elems - 1][classes] + dp[elems - 1][classes - 1]; dp[elems][classes] = dp[elems][classes] % MOD; } } equivalence_relations = new long[N + 1]; for (int i = 0; i <= N; i++) { long tmp = 0; for (int j = 0; j <= i; j++) { tmp = (tmp + dp[i][j]) % MOD; } equivalence_relations[i] = tmp; } } } 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()); } } }
["1", "3", "10"]
Java
NoteIf n = 1 there is only one such relationΒ β€” an empty one, i.e. . In other words, for a single element x of set A the following is hold: .If n = 2 there are three such relations. Let's assume that set A consists of two elements, x and y. Then the valid relations are , ρ = {(x, x)}, ρ = {(y, y)}. It is easy to see that the three listed binary relations are symmetric and transitive relations, but they are not equivalence relations.
In a single line print the answer to the problem modulo 109 + 7.
Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation.A set ρ of pairs (a, b) of elements of some set A is called a binary relation on set A. For two elements a and b of the set A we say that they are in relation ρ, if pair , in this case we use a notation .Binary relation is equivalence relation, if: It is reflexive (for any a it is true that ); It is symmetric (for any a, b it is true that if , then ); It is transitive (if and , than ).Little Johnny is not completely a fool and he noticed that the first condition is not necessary! Here is his "proof":Take any two elements, a and b. If , then (according to property (2)), which means (according to property (3)).It's very simple, isn't it? However, you noticed that Johnny's "proof" is wrong, and decided to show him a lot of examples that prove him wrong.Here's your task: count the number of binary relations over a set of size n such that they are symmetric, transitive, but not an equivalence relations (i.e. they are not reflexive).Since their number may be very large (not 0, according to Little Johnny), print the remainder of integer division of this number by 109 + 7.
[{"input": "1\r\n", "output": ["1"]}, {"input": "2\r\n", "output": ["3"]}, {"input": "3\r\n", "output": ["10"]}, {"input": "4\r\n", "output": ["37"]}, {"input": "5\r\n", "output": ["151"]}, {"input": "6\r\n", "output": ["674"]}, {"input": "7\r\n", "output": ["3263"]}, {"input": "8\r\n", "output": ["17007"]}, {"input": "9\r\n", "output": ["94828"]}, {"input": "10\r\n", "output": ["562595"]}, {"input": "42\r\n", "output": ["738186543"]}, {"input": "2000\r\n", "output": ["323848720"]}, {"input": "4000\r\n", "output": ["341934157"]}, {"input": "2345\r\n", "output": ["832335061"]}, {"input": "2500\r\n", "output": ["544067513"]}, {"input": "2780\r\n", "output": ["951043097"]}, {"input": "2999\r\n", "output": ["634360769"]}, {"input": "3000\r\n", "output": ["949793998"]}, {"input": "20\r\n", "output": ["654959364"]}, {"input": "76\r\n", "output": ["130527569"]}, {"input": "133\r\n", "output": ["334338018"]}, {"input": "345\r\n", "output": ["838683603"]}, {"input": "555\r\n", "output": ["31983119"]}, {"input": "666\r\n", "output": ["86247911"]}, {"input": "777\r\n", "output": ["765401747"]}, {"input": "999\r\n", "output": ["867937200"]}, {"input": "1234\r\n", "output": ["845807965"]}, {"input": "1730\r\n", "output": ["730878735"]}, {"input": "3333\r\n", "output": ["938772236"]}, {"input": "3555\r\n", "output": ["810675957"]}, {"input": "3789\r\n", "output": ["397160465"]}, {"input": "3999\r\n", "output": ["124834909"]}]
100
100
100
[{'input': '2780\r\n', 'output': ['951043097']}, {'input': '1\r\n', 'output': ['1']}, {'input': '76\r\n', 'output': ['130527569']}, {'input': '3555\r\n', 'output': ['810675957']}, {'input': '6\r\n', 'output': ['674']}]
[{'input': '4000\r\n', 'output': ['341934157']}, {'input': '1234\r\n', 'output': ['845807965']}, {'input': '3000\r\n', 'output': ['949793998']}, {'input': '3555\r\n', 'output': ['810675957']}, {'input': '2780\r\n', 'output': ['951043097']}]
[{'input': '1234\r\n', 'output': ['845807965']}, {'input': '1730\r\n', 'output': ['730878735']}, {'input': '133\r\n', 'output': ['334338018']}, {'input': '777\r\n', 'output': ['765401747']}, {'input': '2999\r\n', 'output': ['634360769']}]
[{'input': '3000\r\n', 'output': ['949793998']}, {'input': '555\r\n', 'output': ['31983119']}, {'input': '2780\r\n', 'output': ['951043097']}, {'input': '2\r\n', 'output': ['3']}, {'input': '6\r\n', 'output': ['674']}]
[{'input': '555\r\n', 'output': ['31983119']}, {'input': '10\r\n', 'output': ['562595']}, {'input': '8\r\n', 'output': ['17007']}, {'input': '345\r\n', 'output': ['838683603']}, {'input': '20\r\n', 'output': ['654959364']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
238
100
100
100
["3", "4"]
The first line contains single integer $$$n$$$ ($$$3 \le n \le 500$$$) β€” the number of vertices in the regular polygon.
1bd29d7a8793c22e81a1f6fd3991307a
import java.util.*; import java.io.*; public class Solution { public static void main(String []ks) throws Exception { BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); long n=Long.parseLong(bf.readLine()); long a=2,b=3; long res=0; for(int i=3;i<=n;i++) { res+=(a*b); a++; b++; } System.out.println(res); } }
["6", "18"]
Java
NoteAccording to Wiki: polygon triangulation is the decomposition of a polygonal area (simple polygon) $$$P$$$ into a set of triangles, i. e., finding a set of triangles with pairwise non-intersecting interiors whose union is $$$P$$$.In the first example the polygon is a triangle, so we don't need to cut it further, so the answer is $$$1 \cdot 2 \cdot 3 = 6$$$.In the second example the polygon is a rectangle, so it should be divided into two triangles. It's optimal to cut it using diagonal $$$1-3$$$ so answer is $$$1 \cdot 2 \cdot 3 + 1 \cdot 3 \cdot 4 = 6 + 12 = 18$$$.
Print one integer β€” the minimum weight among all triangulations of the given polygon.
You are given a regular polygon with $$$n$$$ vertices labeled from $$$1$$$ to $$$n$$$ in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle is a vertex of the initial polygon, there is no pair of triangles such that their intersection has non-zero area, and the total area of all triangles is equal to the area of the given polygon. The weight of a triangulation is the sum of weigths of triangles it consists of, where the weight of a triagle is denoted as the product of labels of its vertices.Calculate the minimum weight among all triangulations of the polygon.
[{"input": "3\r\n", "output": ["6"]}, {"input": "4\r\n", "output": ["18"]}, {"input": "5\r\n", "output": ["38"]}, {"input": "6\r\n", "output": ["68"]}, {"input": "7\r\n", "output": ["110"]}, {"input": "8\r\n", "output": ["166"]}, {"input": "9\r\n", "output": ["238"]}, {"input": "10\r\n", "output": ["328"]}, {"input": "100\r\n", "output": ["333298"]}, {"input": "101\r\n", "output": ["343398"]}, {"input": "102\r\n", "output": ["353700"]}, {"input": "103\r\n", "output": ["364206"]}, {"input": "104\r\n", "output": ["374918"]}, {"input": "105\r\n", "output": ["385838"]}, {"input": "106\r\n", "output": ["396968"]}, {"input": "107\r\n", "output": ["408310"]}, {"input": "108\r\n", "output": ["419866"]}, {"input": "109\r\n", "output": ["431638"]}, {"input": "110\r\n", "output": ["443628"]}, {"input": "500\r\n", "output": ["41666498"]}, {"input": "497\r\n", "output": ["40920990"]}, {"input": "494\r\n", "output": ["40184428"]}, {"input": "491\r\n", "output": ["39456758"]}, {"input": "488\r\n", "output": ["38737926"]}, {"input": "485\r\n", "output": ["38027878"]}, {"input": "482\r\n", "output": ["37326560"]}, {"input": "479\r\n", "output": ["36633918"]}, {"input": "476\r\n", "output": ["35949898"]}, {"input": "473\r\n", "output": ["35274446"]}, {"input": "470\r\n", "output": ["34607508"]}, {"input": "467\r\n", "output": ["33949030"]}, {"input": "464\r\n", "output": ["33298958"]}, {"input": "461\r\n", "output": ["32657238"]}, {"input": "458\r\n", "output": ["32023816"]}, {"input": "455\r\n", "output": ["31398638"]}, {"input": "452\r\n", "output": ["30781650"]}, {"input": "449\r\n", "output": ["30172798"]}, {"input": "446\r\n", "output": ["29572028"]}, {"input": "42\r\n", "output": ["24680"]}, {"input": "69\r\n", "output": ["109478"]}, {"input": "228\r\n", "output": ["3950706"]}, {"input": "233\r\n", "output": ["4216366"]}, {"input": "420\r\n", "output": ["24695858"]}, {"input": "368\r\n", "output": ["16611886"]}, {"input": "225\r\n", "output": ["3796798"]}, {"input": "11\r\n", "output": ["438"]}, {"input": "12\r\n", "output": ["570"]}, {"input": "13\r\n", "output": ["726"]}, {"input": "14\r\n", "output": ["908"]}, {"input": "135\r\n", "output": ["820078"]}, {"input": "199\r\n", "output": ["2626798"]}, {"input": "137\r\n", "output": ["857070"]}, {"input": "131\r\n", "output": ["749318"]}, {"input": "130\r\n", "output": ["732288"]}, {"input": "139\r\n", "output": ["895158"]}]
100
100
100
[{'input': '14\r\n', 'output': ['908']}, {'input': '233\r\n', 'output': ['4216366']}, {'input': '225\r\n', 'output': ['3796798']}, {'input': '108\r\n', 'output': ['419866']}, {'input': '4\r\n', 'output': ['18']}]
[{'input': '473\r\n', 'output': ['35274446']}, {'input': '470\r\n', 'output': ['34607508']}, {'input': '228\r\n', 'output': ['3950706']}, {'input': '225\r\n', 'output': ['3796798']}, {'input': '464\r\n', 'output': ['33298958']}]
[{'input': '461\r\n', 'output': ['32657238']}, {'input': '135\r\n', 'output': ['820078']}, {'input': '130\r\n', 'output': ['732288']}, {'input': '473\r\n', 'output': ['35274446']}, {'input': '479\r\n', 'output': ['36633918']}]
[{'input': '4\r\n', 'output': ['18']}, {'input': '10\r\n', 'output': ['328']}, {'input': '446\r\n', 'output': ['29572028']}, {'input': '106\r\n', 'output': ['396968']}, {'input': '105\r\n', 'output': ['385838']}]
[{'input': '461\r\n', 'output': ['32657238']}, {'input': '101\r\n', 'output': ['343398']}, {'input': '103\r\n', 'output': ['364206']}, {'input': '497\r\n', 'output': ['40920990']}, {'input': '4\r\n', 'output': ['18']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
239
100
100
100
["2 162", "4 42", "100 40021"]
The first line contains two positive integers a and b (1 ≀ a &lt; b ≀ 109)Β β€” the number which Vasily has and the number he wants to have.
fc3adb1a9a7f1122b567b4d8afd7b3f3
import java.util.*; public class transformation { public static void main(String[] args){ Scanner scan = new Scanner(System.in); int num1 = scan.nextInt(); int num2 = scan.nextInt(),k=num2; ArrayList<Integer> arr = new ArrayList<>(); while(num2>num1){ if(num2%2==0){ num2=num2/2; arr.add(num2); } else if(num2%10==1){ num2=num2/10; arr.add(num2); } else break; } if(num1==num2){ System.out.println("YES"); System.out.println(arr.size()+1); for(int i=arr.size()-1;i>=0;i--){ System.out.print(arr.get(i)+" "); } System.out.print(k); } else System.out.println("NO"); } }
["YES\n5\n2 4 8 81 162", "NO", "YES\n5\n100 200 2001 4002 40021"]
Java
null
If there is no way to get b from a, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer kΒ β€” the length of the transformation sequence. On the third line print the sequence of transformations x1, x2, ..., xk, where: x1 should be equal to a, xk should be equal to b, xi should be obtained from xi - 1 using any of two described operations (1 &lt; i ≀ k). If there are multiple answers, print any of them.
Vasily has a number a, which he wants to turn into a number b. For this purpose, he can do two types of operations: multiply the current number by 2 (that is, replace the number x by 2Β·x); append the digit 1 to the right of current number (that is, replace the number x by 10Β·x + 1). You need to help Vasily to transform the number a into the number b using only the operations described above, or find that it is impossible.Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform a into b.
[{"input": "2 162\r\n", "output": ["YES\r\n5\r\n2 4 8 81 162"]}, {"input": "4 42\r\n", "output": ["NO"]}, {"input": "100 40021\r\n", "output": ["YES\r\n5\r\n100 200 2001 4002 40021"]}, {"input": "1 111111111\r\n", "output": ["YES\r\n9\r\n1 11 111 1111 11111 111111 1111111 11111111 111111111"]}, {"input": "1 1000000000\r\n", "output": ["NO"]}, {"input": "999999999 1000000000\r\n", "output": ["NO"]}, {"input": "1 2\r\n", "output": ["YES\r\n2\r\n1 2"]}, {"input": "1 536870912\r\n", "output": ["YES\r\n30\r\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912"]}, {"input": "11111 11111111\r\n", "output": ["YES\r\n4\r\n11111 111111 1111111 11111111"]}, {"input": "59139 946224\r\n", "output": ["YES\r\n5\r\n59139 118278 236556 473112 946224"]}, {"input": "9859 19718\r\n", "output": ["YES\r\n2\r\n9859 19718"]}, {"input": "25987 51974222\r\n", "output": ["YES\r\n5\r\n25987 259871 2598711 25987111 51974222"]}, {"input": "9411 188222222\r\n", "output": ["YES\r\n6\r\n9411 94111 941111 9411111 94111111 188222222"]}, {"input": "25539 510782222\r\n", "output": ["YES\r\n6\r\n25539 255391 2553911 25539111 255391111 510782222"]}, {"input": "76259 610072\r\n", "output": ["YES\r\n4\r\n76259 152518 305036 610072"]}, {"input": "92387 184774\r\n", "output": ["YES\r\n2\r\n92387 184774"]}, {"input": "8515 85151111\r\n", "output": ["YES\r\n5\r\n8515 85151 851511 8515111 85151111"]}, {"input": "91939 9193911\r\n", "output": ["YES\r\n3\r\n91939 919391 9193911"]}, {"input": "30518 610361\r\n", "output": ["YES\r\n3\r\n30518 61036 610361"]}, {"input": "46646 373168844\r\n", "output": ["YES\r\n7\r\n46646 466461 932922 9329221 93292211 186584422 373168844"]}, {"input": "30070 300701\r\n", "output": ["YES\r\n2\r\n30070 300701"]}, {"input": "13494 1079528\r\n", "output": ["YES\r\n5\r\n13494 134941 269882 539764 1079528"]}, {"input": "96918 775344422\r\n", "output": ["YES\r\n7\r\n96918 193836 1938361 3876722 38767221 387672211 775344422"]}, {"input": "13046 260921\r\n", "output": ["YES\r\n3\r\n13046 26092 260921"]}, {"input": "29174 5834811\r\n", "output": ["YES\r\n4\r\n29174 58348 583481 5834811"]}, {"input": "79894 319576421\r\n", "output": ["YES\r\n6\r\n79894 798941 1597882 15978821 31957642 319576421"]}, {"input": "96022 1920442\r\n", "output": ["YES\r\n3\r\n96022 960221 1920442"]}, {"input": "79446 6355681\r\n", "output": ["YES\r\n5\r\n79446 158892 317784 635568 6355681"]}, {"input": "5440 27853056\r\n", "output": ["YES\r\n11\r\n5440 10880 108801 217602 435204 870408 1740816 3481632 6963264 13926528 27853056"]}, {"input": "250000000 705032705\r\n", "output": ["NO"]}, {"input": "17 35\r\n", "output": ["NO"]}, {"input": "1 3\r\n", "output": ["NO"]}, {"input": "2 11\r\n", "output": ["NO"]}]
100
100
100
[{'input': '1 111111111\r\n', 'output': ['YES\r\n9\r\n1 11 111 1111 11111 111111 1111111 11111111 111111111']}, {'input': '79446 6355681\r\n', 'output': ['YES\r\n5\r\n79446 158892 317784 635568 6355681']}, {'input': '1 3\r\n', 'output': ['NO']}, {'input': '46646 373168844\r\n', 'output': ['YES\r\n7\r\n46646 466461 932922 9329221 93292211 186584422 373168844']}, {'input': '13494 1079528\r\n', 'output': ['YES\r\n5\r\n13494 134941 269882 539764 1079528']}]
[{'input': '25987 51974222\r\n', 'output': ['YES\r\n5\r\n25987 259871 2598711 25987111 51974222']}, {'input': '29174 5834811\r\n', 'output': ['YES\r\n4\r\n29174 58348 583481 5834811']}, {'input': '1 3\r\n', 'output': ['NO']}, {'input': '1 1000000000\r\n', 'output': ['NO']}, {'input': '59139 946224\r\n', 'output': ['YES\r\n5\r\n59139 118278 236556 473112 946224']}]
[{'input': '30070 300701\r\n', 'output': ['YES\r\n2\r\n30070 300701']}, {'input': '100 40021\r\n', 'output': ['YES\r\n5\r\n100 200 2001 4002 40021']}, {'input': '250000000 705032705\r\n', 'output': ['NO']}, {'input': '5440 27853056\r\n', 'output': ['YES\r\n11\r\n5440 10880 108801 217602 435204 870408 1740816 3481632 6963264 13926528 27853056']}, {'input': '79894 319576421\r\n', 'output': ['YES\r\n6\r\n79894 798941 1597882 15978821 31957642 319576421']}]
[{'input': '5440 27853056\r\n', 'output': ['YES\r\n11\r\n5440 10880 108801 217602 435204 870408 1740816 3481632 6963264 13926528 27853056']}, {'input': '2 11\r\n', 'output': ['NO']}, {'input': '13494 1079528\r\n', 'output': ['YES\r\n5\r\n13494 134941 269882 539764 1079528']}, {'input': '25539 510782222\r\n', 'output': ['YES\r\n6\r\n25539 255391 2553911 25539111 255391111 510782222']}, {'input': '9411 188222222\r\n', 'output': ['YES\r\n6\r\n9411 94111 941111 9411111 94111111 188222222']}]
[{'input': '13046 260921\r\n', 'output': ['YES\r\n3\r\n13046 26092 260921']}, {'input': '92387 184774\r\n', 'output': ['YES\r\n2\r\n92387 184774']}, {'input': '76259 610072\r\n', 'output': ['YES\r\n4\r\n76259 152518 305036 610072']}, {'input': '91939 9193911\r\n', 'output': ['YES\r\n3\r\n91939 919391 9193911']}, {'input': '1 3\r\n', 'output': ['NO']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
90
100
240
100
100
98
["4\n5\n6\n3\n1\n2", "12\n11\n13\n20\n4\n6", "17\n14\n5\n21\n15\n17"]
The first line contains one integer $$$a$$$ $$$(1 \le a \le 100\,000)$$$ β€” the number of ties. The second line contains one integer $$$b$$$ $$$(1 \le b \le 100\,000)$$$ β€” the number of scarves. The third line contains one integer $$$c$$$ $$$(1 \le c \le 100\,000)$$$ β€” the number of vests. The fourth line contains one integer $$$d$$$ $$$(1 \le d \le 100\,000)$$$ β€” the number of jackets. The fifth line contains one integer $$$e$$$ $$$(1 \le e \le 1\,000)$$$ β€” the cost of one suit of the first type. The sixth line contains one integer $$$f$$$ $$$(1 \le f \le 1\,000)$$$ β€” the cost of one suit of the second type.
84d9e7e9c9541d997e6573edb421ae0a
/*package whatever //do not write package name here */ import java.io.*; import java.util.*; public class GFG { public static void main (String[] args) { Scanner s = new Scanner(System.in); int a = s.nextInt(); int b = s.nextInt(); int c = s.nextInt(); int d = s.nextInt(); int e = s.nextInt(); int f = s.nextInt(); int cost=0; if(e<f) { int min = (int)Math.min(b,c); min = (int)Math.min(min,d); cost=min*f; d=d-min; if(d>0) { cost=cost+(int)Math.min(a,d)*e; } System.out.println(cost); } else { int min = (int)Math.min(a,d); cost=min*e; d=d-min; if(d>0) { min = (int)Math.min(b,c); cost=cost+(int)Math.min(min,d)*f; } System.out.println(cost); } } }
["6", "102", "325"]
Java
NoteIt is possible to compose three suits of the second type in the first example, and their total cost will be $$$6$$$. Since all jackets will be used, it's impossible to add anything to this set.The best course of action in the second example is to compose nine suits of the first type and eleven suits of the second type. The total cost is $$$9 \cdot 4 + 11 \cdot 6 = 102$$$.
Print one integer β€” the maximum total cost of some set of suits that can be composed from the delivered items.
A new delivery of clothing has arrived today to the clothing store. This delivery consists of $$$a$$$ ties, $$$b$$$ scarves, $$$c$$$ vests and $$$d$$$ jackets.The store does not sell single clothing items β€” instead, it sells suits of two types: a suit of the first type consists of one tie and one jacket; a suit of the second type consists of one scarf, one vest and one jacket. Each suit of the first type costs $$$e$$$ coins, and each suit of the second type costs $$$f$$$ coins.Calculate the maximum possible cost of a set of suits that can be composed from the delivered clothing items. Note that one item cannot be used in more than one suit (though some items may be left unused).
[{"input": "4\r\n5\r\n6\r\n3\r\n1\r\n2\r\n", "output": ["6"]}, {"input": "12\r\n11\r\n13\r\n20\r\n4\r\n6\r\n", "output": ["102"]}, {"input": "17\r\n14\r\n5\r\n21\r\n15\r\n17\r\n", "output": ["325"]}, {"input": "43475\r\n48103\r\n50473\r\n97918\r\n991\r\n974\r\n", "output": ["89936047"]}, {"input": "35361\r\n35182\r\n68078\r\n30077\r\n870\r\n907\r\n", "output": ["27279839"]}, {"input": "84205\r\n15736\r\n30259\r\n79331\r\n647\r\n378\r\n", "output": ["51327157"]}, {"input": "220\r\n623\r\n94\r\n463\r\n28\r\n656\r\n", "output": ["67824"]}, {"input": "100000\r\n100000\r\n100000\r\n100000\r\n1000\r\n1\r\n", "output": ["100000000"]}, {"input": "22606\r\n4759\r\n37264\r\n19105\r\n787\r\n237\r\n", "output": ["15035635"]}, {"input": "630\r\n312\r\n279\r\n823\r\n316\r\n915\r\n", "output": ["427189"]}, {"input": "86516\r\n30436\r\n14408\r\n80824\r\n605\r\n220\r\n", "output": ["48898520"]}, {"input": "1\r\n1\r\n1\r\n2\r\n100\r\n200\r\n", "output": ["300"]}, {"input": "406\r\n847\r\n512\r\n65\r\n86\r\n990\r\n", "output": ["64350"]}, {"input": "250\r\n400\r\n766\r\n246\r\n863\r\n166\r\n", "output": ["212298"]}, {"input": "724\r\n20\r\n391\r\n850\r\n639\r\n149\r\n", "output": ["465616"]}, {"input": "30233\r\n27784\r\n36393\r\n81065\r\n782\r\n953\r\n", "output": ["50120358"]}, {"input": "61455\r\n43924\r\n94322\r\n83903\r\n855\r\n232\r\n", "output": ["57751961"]}, {"input": "68576\r\n46084\r\n31772\r\n10708\r\n632\r\n408\r\n", "output": ["6767456"]}, {"input": "19969\r\n99297\r\n44283\r\n67490\r\n71\r\n20\r\n", "output": ["2303459"]}, {"input": "68814\r\n96071\r\n14437\r\n59848\r\n848\r\n195\r\n", "output": ["50751104"]}, {"input": "58253\r\n17658\r\n9101\r\n94990\r\n625\r\n178\r\n", "output": ["38028103"]}, {"input": "179\r\n762\r\n909\r\n155\r\n768\r\n278\r\n", "output": ["119040"]}, {"input": "240\r\n655\r\n943\r\n1000\r\n545\r\n262\r\n", "output": ["302410"]}, {"input": "844\r\n909\r\n790\r\n209\r\n809\r\n949\r\n", "output": ["198341"]}, {"input": "15122\r\n4341\r\n98868\r\n60319\r\n760\r\n49\r\n", "output": ["11705429"]}, {"input": "23929\r\n40873\r\n44600\r\n53185\r\n833\r\n328\r\n", "output": ["29528825"]}, {"input": "6781\r\n2030\r\n73183\r\n45619\r\n802\r\n208\r\n", "output": ["5860602"]}, {"input": "260\r\n538\r\n587\r\n231\r\n49\r\n308\r\n", "output": ["71148"]}, {"input": "91\r\n75\r\n768\r\n322\r\n530\r\n291\r\n", "output": ["70055"]}, {"input": "438\r\n541\r\n215\r\n575\r\n795\r\n274\r\n", "output": ["385748"]}, {"input": "756\r\n608\r\n949\r\n947\r\n746\r\n375\r\n", "output": ["635601"]}, {"input": "129\r\n203\r\n206\r\n749\r\n11\r\n358\r\n", "output": ["74093"]}, {"input": "6870\r\n43115\r\n61342\r\n70498\r\n34\r\n145\r\n", "output": ["6485255"]}, {"input": "72593\r\n77891\r\n86639\r\n87424\r\n3\r\n617\r\n", "output": ["48087346"]}, {"input": "58967\r\n2953\r\n35483\r\n681\r\n780\r\n304\r\n", "output": ["531180"]}, {"input": "88\r\n476\r\n735\r\n980\r\n731\r\n404\r\n", "output": ["256632"]}, {"input": "988\r\n657\r\n824\r\n346\r\n996\r\n387\r\n", "output": ["344616"]}, {"input": "92\r\n346\r\n431\r\n669\r\n773\r\n563\r\n", "output": ["265914"]}, {"input": "685\r\n236\r\n234\r\n965\r\n101\r\n832\r\n", "output": ["263873"]}, {"input": "234\r\n519\r\n610\r\n886\r\n877\r\n815\r\n", "output": ["628203"]}, {"input": "184\r\n301\r\n373\r\n420\r\n93\r\n602\r\n", "output": ["192269"]}, {"input": "627\r\n737\r\n778\r\n968\r\n870\r\n74\r\n", "output": ["570724"]}, {"input": "81001\r\n64465\r\n98287\r\n68848\r\n309\r\n982\r\n", "output": ["64658977"]}, {"input": "60469\r\n13310\r\n49402\r\n62958\r\n790\r\n861\r\n", "output": ["50681830"]}, {"input": "88020\r\n62154\r\n14139\r\n86851\r\n863\r\n844\r\n", "output": ["74952413"]}, {"input": "66\r\n393\r\n648\r\n651\r\n6\r\n648\r\n", "output": ["255060"]}, {"input": "647\r\n495\r\n516\r\n125\r\n79\r\n928\r\n", "output": ["116000"]}, {"input": "708\r\n774\r\n307\r\n44\r\n47\r\n103\r\n", "output": ["4532"]}, {"input": "27989\r\n77786\r\n5733\r\n14112\r\n294\r\n715\r\n", "output": ["6562521"]}, {"input": "76294\r\n65438\r\n30385\r\n94336\r\n71\r\n891\r\n", "output": ["31613556"]}, {"input": "5771\r\n19397\r\n45992\r\n46525\r\n336\r\n170\r\n", "output": ["5236546"]}, {"input": "25432\r\n28656\r\n46763\r\n79950\r\n64\r\n957\r\n", "output": ["29051440"]}, {"input": "132\r\n402\r\n711\r\n790\r\n33\r\n837\r\n", "output": ["340830"]}, {"input": "100000\r\n100000\r\n100000\r\n100000\r\n1\r\n1000\r\n", "output": ["100000000"]}, {"input": "100000\r\n100000\r\n100000\r\n100000\r\n1000\r\n1000\r\n", "output": ["100000000"]}, {"input": "1\r\n2\r\n3\r\n4\r\n1\r\n1\r\n", "output": ["3"]}, {"input": "6\r\n1\r\n2\r\n5\r\n1\r\n1\r\n", "output": ["5"]}, {"input": "1\r\n2\r\n2\r\n2\r\n2\r\n1\r\n", "output": ["3"]}, {"input": "1\r\n4\r\n5\r\n6\r\n8\r\n8\r\n", "output": ["40"]}, {"input": "10\r\n1\r\n1\r\n10\r\n2\r\n2\r\n", "output": ["20"]}, {"input": "1\r\n1\r\n1\r\n2\r\n1\r\n1\r\n", "output": ["2"]}]
100
100
100
[{'input': '630\r\n312\r\n279\r\n823\r\n316\r\n915\r\n', 'output': ['427189']}, {'input': '68576\r\n46084\r\n31772\r\n10708\r\n632\r\n408\r\n', 'output': ['6767456']}, {'input': '1\r\n4\r\n5\r\n6\r\n8\r\n8\r\n', 'output': ['40']}, {'input': '72593\r\n77891\r\n86639\r\n87424\r\n3\r\n617\r\n', 'output': ['48087346']}, {'input': '88020\r\n62154\r\n14139\r\n86851\r\n863\r\n844\r\n', 'output': ['74952413']}]
[{'input': '1\r\n4\r\n5\r\n6\r\n8\r\n8\r\n', 'output': ['40']}, {'input': '406\r\n847\r\n512\r\n65\r\n86\r\n990\r\n', 'output': ['64350']}, {'input': '27989\r\n77786\r\n5733\r\n14112\r\n294\r\n715\r\n', 'output': ['6562521']}, {'input': '844\r\n909\r\n790\r\n209\r\n809\r\n949\r\n', 'output': ['198341']}, {'input': '35361\r\n35182\r\n68078\r\n30077\r\n870\r\n907\r\n', 'output': ['27279839']}]
[{'input': '132\r\n402\r\n711\r\n790\r\n33\r\n837\r\n', 'output': ['340830']}, {'input': '27989\r\n77786\r\n5733\r\n14112\r\n294\r\n715\r\n', 'output': ['6562521']}, {'input': '100000\r\n100000\r\n100000\r\n100000\r\n1000\r\n1\r\n', 'output': ['100000000']}, {'input': '86516\r\n30436\r\n14408\r\n80824\r\n605\r\n220\r\n', 'output': ['48898520']}, {'input': '58253\r\n17658\r\n9101\r\n94990\r\n625\r\n178\r\n', 'output': ['38028103']}]
[{'input': '6\r\n1\r\n2\r\n5\r\n1\r\n1\r\n', 'output': ['5']}, {'input': '179\r\n762\r\n909\r\n155\r\n768\r\n278\r\n', 'output': ['119040']}, {'input': '25432\r\n28656\r\n46763\r\n79950\r\n64\r\n957\r\n', 'output': ['29051440']}, {'input': '17\r\n14\r\n5\r\n21\r\n15\r\n17\r\n', 'output': ['325']}, {'input': '129\r\n203\r\n206\r\n749\r\n11\r\n358\r\n', 'output': ['74093']}]
[{'input': '1\r\n1\r\n1\r\n2\r\n100\r\n200\r\n', 'output': ['300']}, {'input': '68576\r\n46084\r\n31772\r\n10708\r\n632\r\n408\r\n', 'output': ['6767456']}, {'input': '72593\r\n77891\r\n86639\r\n87424\r\n3\r\n617\r\n', 'output': ['48087346']}, {'input': '627\r\n737\r\n778\r\n968\r\n870\r\n74\r\n', 'output': ['570724']}, {'input': '5771\r\n19397\r\n45992\r\n46525\r\n336\r\n170\r\n', 'output': ['5236546']}]
100
100
100
100
100
100
100
100
92
100
83.33
83.33
83.33
66.67
83.33
241
100
98.4
79.998
["8\nbacabcab", "4\nbcda", "6\nabbbbb"]
The only line of the input contains one integer $$$|s|$$$ ($$$1 \le |s| \le 100$$$) β€” the length of $$$s$$$. The second line of the input contains one string $$$s$$$ consisting of $$$|s|$$$ lowercase Latin letters.
9ce37bc2d361f5bb8a0568fb479b8a38
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); String str = in.next(); System.out.println(getAns(str, N)); in.close(); } public static int getAns(String str, int N) { int ans = 0; StringBuilder sb = new StringBuilder(str); for (int i = 25; i >= 0; i--) { char ch = (char) (97 + i); for (int j = 0; j < sb.length(); j++) { if (sb.length() == 1) { break; } char ch1 = sb.charAt(j); if (ch != ch1) { continue; } // System.out.println(j); if (j == 0 && ((int) ch - 1 == (int) sb.charAt(j + 1))) { //System.out.println("leftMost " + j); sb.deleteCharAt(j); ans++; j -= 1; continue; } else if (j == sb.length() - 1 && ((int) ch - 1 == (int) sb.charAt(j - 1))) { //System.out.println("rightMost " + j); sb.deleteCharAt(j); ans++; j -= 1; continue; } else if ((j < sb.length() - 1 && (int) ch - 1 == (int) sb.charAt(j + 1)) || (j > 0 && (int) ch - 1 == (int) sb.charAt(j - 1))) { //System.out.println("middle " + j); sb.deleteCharAt(j); ans++; j -= 2; //System.out.println("middle " + j + " " + sb.toString() + " " + sb.length()); continue; } //System.out.println(sb.toString()); } } return ans; } }
["4", "3", "5"]
Java
NoteThe first example is described in the problem statement. Note that the sequence of moves provided in the statement is not the only, but it can be shown that the maximum possible answer to this test is $$$4$$$.In the second example, you can remove all but one character of $$$s$$$. The only possible answer follows. During the first move, remove the third character $$$s_3=$$$ d, $$$s$$$ becomes bca. During the second move, remove the second character $$$s_2=$$$ c, $$$s$$$ becomes ba. And during the third move, remove the first character $$$s_1=$$$ b, $$$s$$$ becomes a.
Print one integer β€” the maximum possible number of characters you can remove if you choose the sequence of moves optimally.
You are given a string $$$s$$$ consisting of lowercase Latin letters. Let the length of $$$s$$$ be $$$|s|$$$. You may perform several operations on this string.In one operation, you can choose some index $$$i$$$ and remove the $$$i$$$-th character of $$$s$$$ ($$$s_i$$$) if at least one of its adjacent characters is the previous letter in the Latin alphabet for $$$s_i$$$. For example, the previous letter for b is a, the previous letter for s is r, the letter a has no previous letters. Note that after each removal the length of the string decreases by one. So, the index $$$i$$$ should satisfy the condition $$$1 \le i \le |s|$$$ during each operation.For the character $$$s_i$$$ adjacent characters are $$$s_{i-1}$$$ and $$$s_{i+1}$$$. The first and the last characters of $$$s$$$ both have only one adjacent character (unless $$$|s| = 1$$$).Consider the following example. Let $$$s=$$$ bacabcab. During the first move, you can remove the first character $$$s_1=$$$ b because $$$s_2=$$$ a. Then the string becomes $$$s=$$$ acabcab. During the second move, you can remove the fifth character $$$s_5=$$$ c because $$$s_4=$$$ b. Then the string becomes $$$s=$$$ acabab. During the third move, you can remove the sixth character $$$s_6=$$$'b' because $$$s_5=$$$ a. Then the string becomes $$$s=$$$ acaba. During the fourth move, the only character you can remove is $$$s_4=$$$ b, because $$$s_3=$$$ a (or $$$s_5=$$$ a). The string becomes $$$s=$$$ acaa and you cannot do anything with it. Your task is to find the maximum possible number of characters you can remove if you choose the sequence of operations optimally.
[{"input": "8\r\nbacabcab\r\n", "output": ["4"]}, {"input": "4\r\nbcda\r\n", "output": ["3"]}, {"input": "6\r\nabbbbb\r\n", "output": ["5"]}, {"input": "1\r\na\r\n", "output": ["0"]}, {"input": "1\r\nt\r\n", "output": ["0"]}, {"input": "100\r\nciftajmzqbfkvbhnyugneialytrkwjlhzwltylptheadmypbjxdzkxnqovimgmzkwpuelzbbhciinfiyspfatgoexeezolulnliu\r\n", "output": ["0"]}, {"input": "100\r\nyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": ["99"]}, {"input": "100\r\naaaaaabbcccccccddffffhhhhhhhhiiiiiikkkkkkkkmmmmmmooooooopppprrrrrrrrrttttttvvvvvvvvvvvvxxxxxxxzzzzzz\r\n", "output": ["21"]}, {"input": "100\r\nbabaababbaabbabababbabbbababababbaabababaaababaababbbaaababbaabbababababbababbabaabbaabaaaaabbababba\r\n", "output": ["50"]}, {"input": "100\r\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\r\n", "output": ["99"]}, {"input": "100\r\nacdfijmnorszzyyzzzzzzyzzyzzzzxwzzzzzyzzzzzzyzzzzzzzyzzzzzyzzzzzzyxzzzyzzzzzyzzzzzyzzyzzzzvutqplkhgeb\r\n", "output": ["99"]}, {"input": "100\r\nabcdeghfgefedeefcabaaabcedfefedacbbcaaabehhjlkjikjloqrtuyzxwvspnmnlkjgfdcbacdcghfedfebaacbcbcdbccaaa\r\n", "output": ["85"]}, {"input": "100\r\nababaaaabaabaaaaaaabaaaaaaaaaaaaacbaaaabaaaaaabaabaaaababaaaabaehijkmnpqvxzywutsrolgfdcbaaaabaabaaaa\r\n", "output": ["40"]}, {"input": "100\r\naaaaaaabaaaaaabcaaaaaaaaaaaaaaaaaaaabbbaaaaaaabefhklmnopsuxzywvtrqjigdcaaaaaaaaaaaaaaaaaaaaaaaabaaaa\r\n", "output": ["32"]}, {"input": "100\r\naaaaabcjkprsvxyzwutqonmlihgfedaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": ["26"]}, {"input": "100\r\nyltrygcqmgjzsxoahbvovspancmoaltdrxgjnxwxbrehubvradguoqgiodzanljxtszdutuzgcnihmwevoloceyidyvoopnqbtlb\r\n", "output": ["9"]}, {"input": "100\r\naaaabbbcccccccdddddeeeeeffgggghhhiijjjjkkkllmmnnnoooppqqqrrrrssssssttttuuuuuuuuvvvvvwwwwxxxxyyyyzzzz\r\n", "output": ["96"]}, {"input": "100\r\nrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n", "output": ["0"]}, {"input": "100\r\nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn\r\n", "output": ["0"]}, {"input": "100\r\njupemetthxolktvhbmzdwlrekwmcugngajdgifwseksjlibsdgmegmqtmeeeqszqjxjhjenjxofvkesfjugbzephryjqqkxatrvl\r\n", "output": ["1"]}, {"input": "100\r\nmxjrojjwtrauhhccftvjsyfyfsnbdnwjfltyjetsylbddrkoqjxbmientcowknrecfqcvxfgsbymwyvakmbulhvrxzvzbygajtgc\r\n", "output": ["2"]}, {"input": "100\r\nbldubjepvkwhjbxrueydtpparjszjgwpxjlqlpsmdrjoaagfnrohfcabchmdwaoctmilfbpztwjrfdgdioqggokdftcniqywmvjd\r\n", "output": ["3"]}, {"input": "100\r\nzbzevxgewibujtbyvhzohoobudkghaivlbpaywiesizahkdxmcpdoqzsxqglezenmsgvsmxcrzcntauvarpakddglhrjmzylfuyq\r\n", "output": ["4"]}, {"input": "100\r\nwhkbjjjrpcgsfaxgcmktmwypyfhbzvvowkvxltbmnyndqkswixxqxriopddrygymbcvadjjheugxgikrlirnhhsmnjmzpizyltau\r\n", "output": ["5"]}, {"input": "1\r\nz\r\n", "output": ["0"]}, {"input": "5\r\nbabaa\r\n", "output": ["2"]}, {"input": "5\r\nabbdd\r\n", "output": ["2"]}, {"input": "6\r\naaaaaa\r\n", "output": ["0"]}, {"input": "6\r\nbbbbab\r\n", "output": ["5"]}, {"input": "6\r\nbaabbb\r\n", "output": ["4"]}, {"input": "6\r\ndacbab\r\n", "output": ["3"]}, {"input": "7\r\naaaaaaa\r\n", "output": ["0"]}, {"input": "7\r\nbaaabab\r\n", "output": ["3"]}, {"input": "7\r\nccababa\r\n", "output": ["2"]}, {"input": "7\r\ncddcbcb\r\n", "output": ["5"]}, {"input": "8\r\naaaaaaaa\r\n", "output": ["0"]}, {"input": "8\r\naaabbaab\r\n", "output": ["3"]}, {"input": "8\r\nabababbc\r\n", "output": ["5"]}, {"input": "8\r\nbdaacddc\r\n", "output": ["2"]}, {"input": "9\r\naaaaaaaaa\r\n", "output": ["0"]}, {"input": "9\r\naabaaabab\r\n", "output": ["3"]}, {"input": "9\r\nbaccbbaca\r\n", "output": ["5"]}, {"input": "9\r\nacacaabaa\r\n", "output": ["1"]}, {"input": "10\r\naaaaaaaaaa\r\n", "output": ["0"]}, {"input": "10\r\nbbaabaabbb\r\n", "output": ["6"]}, {"input": "10\r\ncbbbbcaaca\r\n", "output": ["6"]}, {"input": "10\r\ncadbcdddda\r\n", "output": ["6"]}]
100
100
100
[{'input': '6\r\nbbbbab\r\n', 'output': ['5']}, {'input': '1\r\na\r\n', 'output': ['0']}, {'input': '100\r\naaaaaaabaaaaaabcaaaaaaaaaaaaaaaaaaaabbbaaaaaaabefhklmnopsuxzywvtrqjigdcaaaaaaaaaaaaaaaaaaaaaaaabaaaa\r\n', 'output': ['32']}, {'input': '5\r\nbabaa\r\n', 'output': ['2']}, {'input': '100\r\nababaaaabaabaaaaaaabaaaaaaaaaaaaacbaaaabaaaaaabaabaaaababaaaabaehijkmnpqvxzywutsrolgfdcbaaaabaabaaaa\r\n', 'output': ['40']}]
[{'input': '100\r\nababaaaabaabaaaaaaabaaaaaaaaaaaaacbaaaabaaaaaabaabaaaababaaaabaehijkmnpqvxzywutsrolgfdcbaaaabaabaaaa\r\n', 'output': ['40']}, {'input': '100\r\nacdfijmnorszzyyzzzzzzyzzyzzzzxwzzzzzyzzzzzzyzzzzzzzyzzzzzyzzzzzzyxzzzyzzzzzyzzzzzyzzyzzzzvutqplkhgeb\r\n', 'output': ['99']}, {'input': '100\r\naaaaabcjkprsvxyzwutqonmlihgfedaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n', 'output': ['26']}, {'input': '6\r\nbbbbab\r\n', 'output': ['5']}, {'input': '100\r\nwhkbjjjrpcgsfaxgcmktmwypyfhbzvvowkvxltbmnyndqkswixxqxriopddrygymbcvadjjheugxgikrlirnhhsmnjmzpizyltau\r\n', 'output': ['5']}]
[{'input': '6\r\nbbbbab\r\n', 'output': ['5']}, {'input': '100\r\nciftajmzqbfkvbhnyugneialytrkwjlhzwltylptheadmypbjxdzkxnqovimgmzkwpuelzbbhciinfiyspfatgoexeezolulnliu\r\n', 'output': ['0']}, {'input': '100\r\nacdfijmnorszzyyzzzzzzyzzyzzzzxwzzzzzyzzzzzzyzzzzzzzyzzzzzyzzzzzzyxzzzyzzzzzyzzzzzyzzyzzzzvutqplkhgeb\r\n', 'output': ['99']}, {'input': '100\r\nmxjrojjwtrauhhccftvjsyfyfsnbdnwjfltyjetsylbddrkoqjxbmientcowknrecfqcvxfgsbymwyvakmbulhvrxzvzbygajtgc\r\n', 'output': ['2']}, {'input': '8\r\nbdaacddc\r\n', 'output': ['2']}]
[{'input': '100\r\naaaabbbcccccccdddddeeeeeffgggghhhiijjjjkkkllmmnnnoooppqqqrrrrssssssttttuuuuuuuuvvvvvwwwwxxxxyyyyzzzz\r\n', 'output': ['96']}, {'input': '100\r\nabcdeghfgefedeefcabaaabcedfefedacbbcaaabehhjlkjikjloqrtuyzxwvspnmnlkjgfdcbacdcghfedfebaacbcbcdbccaaa\r\n', 'output': ['85']}, {'input': '6\r\nbbbbab\r\n', 'output': ['5']}, {'input': '4\r\nbcda\r\n', 'output': ['3']}, {'input': '8\r\nbdaacddc\r\n', 'output': ['2']}]
[{'input': '9\r\nbaccbbaca\r\n', 'output': ['5']}, {'input': '4\r\nbcda\r\n', 'output': ['3']}, {'input': '6\r\nbbbbab\r\n', 'output': ['5']}, {'input': '100\r\nbldubjepvkwhjbxrueydtpparjszjgwpxjlqlpsmdrjoaagfnrohfcabchmdwaoctmilfbpztwjrfdgdioqggokdftcniqywmvjd\r\n', 'output': ['3']}, {'input': '7\r\ncddcbcb\r\n', 'output': ['5']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
242
100
100
100
["21", "20"]
The first line contains integer n (1 ≀ n ≀ 109).
ae20ae2a16273a0d379932d6e973f878
import java.io.*; import java.util.ArrayList; import java.util.StringTokenizer; /** * * @author arif_ * @date * @algo * @difficulty */ public class CF_876C { /* START OF I/O ROUTINE */ // PrintWriter for faster output public static PrintWriter out; // MyInputReader class for faster input public static class MyInputReader { BufferedReader br; StringTokenizer st; public MyInputReader(InputStream stream) { br = new BufferedReader(new InputStreamReader(stream), 32768); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // end of class MyInputReader /* END OF I/O ROUTINE */ public static void main(String[] args) { MyInputReader in = new MyInputReader(System.in); out = new PrintWriter(new BufferedOutputStream(System.out)); int n = in.nextInt(); ArrayList<Integer> ans = new ArrayList<Integer>(); for (int i=81; i>=1; i--) { if (i >= n) continue; int x = n - i; int sum = 0, y = x; while (y > 0) { sum += (y % 10); y /= 10; } if (sum+x == n) ans.add(x); } out.println(ans.size()); for (Integer a : ans) { out.println(a); } out.close(); } // end of method main() } // end of class Main
["1\n15", "0"]
Java
NoteIn the first test case x = 15 there is only one variant: 15 + 1 + 5 = 21.In the second test case there are no such x.
In the first line print one integer kΒ β€” number of different values of x satisfying the condition. In next k lines print these values in ascending order.
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer x was given. The task was to add x to the sum of the digits of the number x written in decimal numeral system.Since the number n on the board was small, Vova quickly guessed which x could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number n for all suitable values of x or determine that such x does not exist. Write such a program for Vova.
[{"input": "21\r\n", "output": ["1\r\n15"]}, {"input": "20\r\n", "output": ["0"]}, {"input": "1\r\n", "output": ["0"]}, {"input": "2\r\n", "output": ["1\r\n1"]}, {"input": "3\r\n", "output": ["0"]}, {"input": "100000001\r\n", "output": ["2\r\n99999937\r\n 100000000", "2\r\n99999937 100000000", "2\r\n99999937\r\n100000000"]}, {"input": "1000000000\r\n", "output": ["1\r\n999999932"]}, {"input": "999999979\r\n", "output": ["2\r\n999999899\r\n 999999908", "2\r\n999999899 999999908", "2\r\n999999899\r\n999999908"]}, {"input": "9\r\n", "output": ["0"]}, {"input": "10\r\n", "output": ["1\r\n5"]}, {"input": "11\r\n", "output": ["1\r\n10"]}, {"input": "39\r\n", "output": ["1\r\n33"]}, {"input": "66\r\n", "output": ["1\r\n60"]}, {"input": "75\r\n", "output": ["0"]}, {"input": "100\r\n", "output": ["1\r\n86"]}, {"input": "101\r\n", "output": ["2\r\n91\r\n100", "2\r\n91\r\n 100", "2\r\n91 100"]}, {"input": "2014\r\n", "output": ["2\r\n1988\r\n2006", "2\r\n1988 2006", "2\r\n1988\r\n 2006"]}, {"input": "999999994\r\n", "output": ["0"]}]
100
100
100
[{'input': '66\r\n', 'output': ['1\r\n60']}, {'input': '2\r\n', 'output': ['1\r\n1']}, {'input': '39\r\n', 'output': ['1\r\n33']}, {'input': '20\r\n', 'output': ['0']}, {'input': '100000001\r\n', 'output': ['2\r\n99999937\r\n 100000000', '2\r\n99999937 100000000', '2\r\n99999937\r\n100000000']}]
[{'input': '1000000000\r\n', 'output': ['1\r\n999999932']}, {'input': '101\r\n', 'output': ['2\r\n91\r\n100', '2\r\n91\r\n 100', '2\r\n91 100']}, {'input': '2\r\n', 'output': ['1\r\n1']}, {'input': '1\r\n', 'output': ['0']}, {'input': '21\r\n', 'output': ['1\r\n15']}]
[{'input': '66\r\n', 'output': ['1\r\n60']}, {'input': '3\r\n', 'output': ['0']}, {'input': '100000001\r\n', 'output': ['2\r\n99999937\r\n 100000000', '2\r\n99999937 100000000', '2\r\n99999937\r\n100000000']}, {'input': '39\r\n', 'output': ['1\r\n33']}, {'input': '20\r\n', 'output': ['0']}]
[{'input': '100\r\n', 'output': ['1\r\n86']}, {'input': '100000001\r\n', 'output': ['2\r\n99999937\r\n 100000000', '2\r\n99999937 100000000', '2\r\n99999937\r\n100000000']}, {'input': '39\r\n', 'output': ['1\r\n33']}, {'input': '3\r\n', 'output': ['0']}, {'input': '999999994\r\n', 'output': ['0']}]
[{'input': '11\r\n', 'output': ['1\r\n10']}, {'input': '3\r\n', 'output': ['0']}, {'input': '100\r\n', 'output': ['1\r\n86']}, {'input': '1000000000\r\n', 'output': ['1\r\n999999932']}, {'input': '1\r\n', 'output': ['0']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
243
100
100
100
["2\n5\n7", "4\n7\n13", "2\n3\n2"]
The first line contains the positive integer a (1 ≀ a ≀ 1000)Β β€” the number of lemons Nikolay has. The second line contains the positive integer b (1 ≀ b ≀ 1000)Β β€” the number of apples Nikolay has. The third line contains the positive integer c (1 ≀ c ≀ 1000)Β β€” the number of pears Nikolay has.
82a4a60eac90765fb62f2a77d2305c01
import java.util.Scanner; public class JavaApplication1 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner scanner=new Scanner(System.in); int lemon = scanner.nextInt(); int apple = scanner.nextInt(); int pear = scanner.nextInt(); int result=0; for(int i=lemon;i>0;i--){ if(2*i<=apple&&4*i<=pear){ result=i+(2*i)+(4*i); System.out.println(result+""); return; }else if(i==1){ System.out.println(result+""); } } } }
["7", "21", "0"]
Java
NoteIn the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0.
Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.
Nikolay has a lemons, b apples and c pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1: 2: 4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruitsΒ β€” lemons, apples and pearsΒ β€” should be put in the compote as whole fruits.Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0.
[{"input": "2\r\n5\r\n7\r\n", "output": ["7"]}, {"input": "4\r\n7\r\n13\r\n", "output": ["21"]}, {"input": "2\r\n3\r\n2\r\n", "output": ["0"]}, {"input": "1\r\n1\r\n1\r\n", "output": ["0"]}, {"input": "1\r\n2\r\n4\r\n", "output": ["7"]}, {"input": "1000\r\n1000\r\n1000\r\n", "output": ["1750"]}, {"input": "1\r\n1\r\n4\r\n", "output": ["0"]}, {"input": "1\r\n2\r\n3\r\n", "output": ["0"]}, {"input": "1\r\n1000\r\n1000\r\n", "output": ["7"]}, {"input": "1000\r\n1\r\n1000\r\n", "output": ["0"]}, {"input": "1000\r\n2\r\n1000\r\n", "output": ["7"]}, {"input": "1000\r\n500\r\n1000\r\n", "output": ["1750"]}, {"input": "1000\r\n1000\r\n4\r\n", "output": ["7"]}, {"input": "1000\r\n1000\r\n3\r\n", "output": ["0"]}, {"input": "4\r\n8\r\n12\r\n", "output": ["21"]}, {"input": "10\r\n20\r\n40\r\n", "output": ["70"]}, {"input": "100\r\n200\r\n399\r\n", "output": ["693"]}, {"input": "200\r\n400\r\n800\r\n", "output": ["1400"]}, {"input": "199\r\n400\r\n800\r\n", "output": ["1393"]}, {"input": "201\r\n400\r\n800\r\n", "output": ["1400"]}, {"input": "200\r\n399\r\n800\r\n", "output": ["1393"]}, {"input": "200\r\n401\r\n800\r\n", "output": ["1400"]}, {"input": "200\r\n400\r\n799\r\n", "output": ["1393"]}, {"input": "200\r\n400\r\n801\r\n", "output": ["1400"]}, {"input": "139\r\n252\r\n871\r\n", "output": ["882"]}, {"input": "109\r\n346\r\n811\r\n", "output": ["763"]}, {"input": "237\r\n487\r\n517\r\n", "output": ["903"]}, {"input": "161\r\n331\r\n725\r\n", "output": ["1127"]}, {"input": "39\r\n471\r\n665\r\n", "output": ["273"]}, {"input": "9\r\n270\r\n879\r\n", "output": ["63"]}, {"input": "137\r\n422\r\n812\r\n", "output": ["959"]}, {"input": "15\r\n313\r\n525\r\n", "output": ["105"]}, {"input": "189\r\n407\r\n966\r\n", "output": ["1323"]}, {"input": "18\r\n268\r\n538\r\n", "output": ["126"]}, {"input": "146\r\n421\r\n978\r\n", "output": ["1022"]}, {"input": "70\r\n311\r\n685\r\n", "output": ["490"]}, {"input": "244\r\n405\r\n625\r\n", "output": ["1092"]}, {"input": "168\r\n454\r\n832\r\n", "output": ["1176"]}, {"input": "46\r\n344\r\n772\r\n", "output": ["322"]}, {"input": "174\r\n438\r\n987\r\n", "output": ["1218"]}, {"input": "144\r\n387\r\n693\r\n", "output": ["1008"]}, {"input": "22\r\n481\r\n633\r\n", "output": ["154"]}, {"input": "196\r\n280\r\n848\r\n", "output": ["980"]}, {"input": "190\r\n454\r\n699\r\n", "output": ["1218"]}, {"input": "231\r\n464\r\n928\r\n", "output": ["1617"]}, {"input": "151\r\n308\r\n616\r\n", "output": ["1057"]}, {"input": "88\r\n182\r\n364\r\n", "output": ["616"]}, {"input": "12\r\n26\r\n52\r\n", "output": ["84"]}, {"input": "204\r\n412\r\n824\r\n", "output": ["1428"]}, {"input": "127\r\n256\r\n512\r\n", "output": ["889"]}, {"input": "224\r\n446\r\n896\r\n", "output": ["1561"]}, {"input": "146\r\n291\r\n584\r\n", "output": ["1015"]}, {"input": "83\r\n164\r\n332\r\n", "output": ["574"]}, {"input": "20\r\n38\r\n80\r\n", "output": ["133"]}, {"input": "198\r\n393\r\n792\r\n", "output": ["1372"]}, {"input": "120\r\n239\r\n480\r\n", "output": ["833"]}, {"input": "208\r\n416\r\n831\r\n", "output": ["1449"]}, {"input": "130\r\n260\r\n517\r\n", "output": ["903"]}, {"input": "67\r\n134\r\n267\r\n", "output": ["462"]}, {"input": "245\r\n490\r\n979\r\n", "output": ["1708"]}, {"input": "182\r\n364\r\n727\r\n", "output": ["1267"]}, {"input": "104\r\n208\r\n413\r\n", "output": ["721"]}, {"input": "10\r\n2\r\n100\r\n", "output": ["7"]}, {"input": "2\r\n100\r\n100\r\n", "output": ["14"]}, {"input": "2\r\n3\r\n8\r\n", "output": ["7"]}, {"input": "1\r\n2\r\n8\r\n", "output": ["7"]}, {"input": "1\r\n2\r\n200\r\n", "output": ["7"]}, {"input": "5\r\n4\r\n16\r\n", "output": ["14"]}, {"input": "1\r\n10\r\n10\r\n", "output": ["7"]}, {"input": "1\r\n4\r\n8\r\n", "output": ["7"]}, {"input": "100\r\n4\r\n1000\r\n", "output": ["14"]}, {"input": "2\r\n6\r\n12\r\n", "output": ["14"]}, {"input": "10\r\n7\r\n4\r\n", "output": ["7"]}, {"input": "2\r\n10\r\n100\r\n", "output": ["14"]}, {"input": "2\r\n3\r\n4\r\n", "output": ["7"]}, {"input": "1\r\n2\r\n999\r\n", "output": ["7"]}, {"input": "1\r\n10\r\n20\r\n", "output": ["7"]}, {"input": "100\r\n18\r\n20\r\n", "output": ["35"]}, {"input": "100\r\n1\r\n100\r\n", "output": ["0"]}, {"input": "3\r\n7\r\n80\r\n", "output": ["21"]}, {"input": "2\r\n8\r\n24\r\n", "output": ["14"]}, {"input": "1\r\n100\r\n100\r\n", "output": ["7"]}, {"input": "2\r\n1\r\n8\r\n", "output": ["0"]}, {"input": "10\r\n5\r\n23\r\n", "output": ["14"]}]
100
100
100
[{'input': '1000\r\n2\r\n1000\r\n', 'output': ['7']}, {'input': '109\r\n346\r\n811\r\n', 'output': ['763']}, {'input': '15\r\n313\r\n525\r\n', 'output': ['105']}, {'input': '104\r\n208\r\n413\r\n', 'output': ['721']}, {'input': '146\r\n291\r\n584\r\n', 'output': ['1015']}]
[{'input': '5\r\n4\r\n16\r\n', 'output': ['14']}, {'input': '1\r\n4\r\n8\r\n', 'output': ['7']}, {'input': '100\r\n4\r\n1000\r\n', 'output': ['14']}, {'input': '168\r\n454\r\n832\r\n', 'output': ['1176']}, {'input': '109\r\n346\r\n811\r\n', 'output': ['763']}]
[{'input': '104\r\n208\r\n413\r\n', 'output': ['721']}, {'input': '151\r\n308\r\n616\r\n', 'output': ['1057']}, {'input': '146\r\n421\r\n978\r\n', 'output': ['1022']}, {'input': '100\r\n200\r\n399\r\n', 'output': ['693']}, {'input': '67\r\n134\r\n267\r\n', 'output': ['462']}]
[{'input': '109\r\n346\r\n811\r\n', 'output': ['763']}, {'input': '1\r\n2\r\n3\r\n', 'output': ['0']}, {'input': '137\r\n422\r\n812\r\n', 'output': ['959']}, {'input': '22\r\n481\r\n633\r\n', 'output': ['154']}, {'input': '168\r\n454\r\n832\r\n', 'output': ['1176']}]
[{'input': '10\r\n2\r\n100\r\n', 'output': ['7']}, {'input': '189\r\n407\r\n966\r\n', 'output': ['1323']}, {'input': '70\r\n311\r\n685\r\n', 'output': ['490']}, {'input': '1\r\n1000\r\n1000\r\n', 'output': ['7']}, {'input': '1\r\n10\r\n10\r\n', 'output': ['7']}]
100
100
100
100
100
84.62
84.62
84.62
100
84.62
75
62.5
62.5
75
62.5
244
100
87.696
67.5
["5 2 6 3", "3 1 5 6", "8 3 3 2", "2 3 10 4"]
The only line of the input contains four integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$1 \le a, b, c, d \le 10^9$$$). It is possible that any two (or all three) ropewalkers are in the same position at the beginning of the performance.
47c07e46517dbc937e2e779ec0d74eb3
import static java.lang.StrictMath.abs; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Ropewalkers { static int a; static int b; static int c; static int d; static List <Integer> list = new ArrayList(); static int counter=0; public static void main(String args[]){ Scanner in = new Scanner(System.in); a = in.nextInt(); b = in.nextInt(); c = in.nextInt(); d = in.nextInt(); list.add(a); list.add(b); list.add(c); int max = Collections.max(list); int min = Collections.min(list); int mid = (a+b+c) - (min+max); if (abs(mid - min) < d ){ counter += d - (mid-min); } if(abs(max - mid) < d ){ counter += d - max + mid; } System.out.println(counter); } }
["2", "8", "2", "3"]
Java
NoteIn the first example: in the first two seconds Konrad moves for 2 positions to the right (to the position $$$8$$$), while Agafon and Boniface stay at their positions. Thus, the distance between Agafon and Boniface will be $$$|5 - 2| = 3$$$, the distance between Boniface and Konrad will be $$$|2 - 8| = 6$$$ and the distance between Agafon and Konrad will be $$$|5 - 8| = 3$$$. Therefore, all three pairwise distances will be at least $$$d=3$$$, so the performance could be finished within 2 seconds.
Output one integer β€” the minimum duration (in seconds) of the performance.
Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad.The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions $$$a$$$, $$$b$$$ and $$$c$$$ respectively. At the end of the performance, the distance between each pair of ropewalkers was at least $$$d$$$.Ropewalkers can walk on the rope. In one second, only one ropewalker can change his position. Every ropewalker can change his position exactly by $$$1$$$ (i. e. shift by $$$1$$$ to the left or right direction on the rope). Agafon, Boniface and Konrad can not move at the same time (Only one of them can move at each moment). Ropewalkers can be at the same positions at the same time and can "walk past each other".You should find the minimum duration (in seconds) of the performance. In other words, find the minimum number of seconds needed so that the distance between each pair of ropewalkers can be greater or equal to $$$d$$$.Ropewalkers can walk to negative coordinates, due to the rope is infinite to both sides.
[{"input": "5 2 6 3\r\n", "output": ["2"]}, {"input": "3 1 5 6\r\n", "output": ["8"]}, {"input": "8 3 3 2\r\n", "output": ["2"]}, {"input": "2 3 10 4\r\n", "output": ["3"]}, {"input": "1000000000 1000000000 1000000000 1000000000\r\n", "output": ["2000000000"]}, {"input": "500000000 250000000 750000000 1000000000\r\n", "output": ["1500000000"]}, {"input": "1 3 2 5\r\n", "output": ["8"]}, {"input": "2 3 1 6\r\n", "output": ["10"]}, {"input": "9 6 2 5\r\n", "output": ["3"]}, {"input": "1 1 1 1\r\n", "output": ["2"]}, {"input": "1 1 500 10\r\n", "output": ["10"]}, {"input": "500 1 500 1000\r\n", "output": ["1501"]}, {"input": "1 2 1 1\r\n", "output": ["1"]}, {"input": "89 983 751 1000\r\n", "output": ["1106"]}, {"input": "716270982 22102638 553198855 1000000000\r\n", "output": ["1305831656"]}, {"input": "1000000000 1 1000000000 999999999\r\n", "output": ["999999999"]}, {"input": "999999999 1 1 1000000000\r\n", "output": ["1000000002"]}, {"input": "1 2 3 4\r\n", "output": ["6"]}, {"input": "1 3 4 5\r\n", "output": ["7"]}, {"input": "1 3 2 6\r\n", "output": ["10"]}, {"input": "2 2 3 4\r\n", "output": ["7"]}, {"input": "1 1 4 5\r\n", "output": ["7"]}, {"input": "5 5 2 6\r\n", "output": ["9"]}, {"input": "1 3 3 6\r\n", "output": ["10"]}, {"input": "1 4 4 6\r\n", "output": ["9"]}, {"input": "1 3 3 5\r\n", "output": ["8"]}, {"input": "1 4 4 5\r\n", "output": ["7"]}, {"input": "1000000000 1000000000 1000000000 1\r\n", "output": ["2"]}, {"input": "2 1 1 3\r\n", "output": ["5"]}, {"input": "3 2 2 3\r\n", "output": ["5"]}, {"input": "5 5 4 1\r\n", "output": ["1"]}, {"input": "3 1 4 2\r\n", "output": ["1"]}, {"input": "5 4 2 3\r\n", "output": ["3"]}, {"input": "3 2 1 4\r\n", "output": ["6"]}, {"input": "3 2 3 5\r\n", "output": ["9"]}, {"input": "1 3 4 6\r\n", "output": ["9"]}, {"input": "3 1 2 7\r\n", "output": ["12"]}, {"input": "1 5 4 8\r\n", "output": ["12"]}, {"input": "1 4 3 9\r\n", "output": ["15"]}, {"input": "5 3 4 10\r\n", "output": ["18"]}, {"input": "3 5 8 1\r\n", "output": ["0"]}, {"input": "1 1 2 100\r\n", "output": ["199"]}, {"input": "5 5 7 5\r\n", "output": ["8"]}, {"input": "1 5 10 3\r\n", "output": ["0"]}, {"input": "1 2 9 5\r\n", "output": ["4"]}, {"input": "2 4 7 6\r\n", "output": ["7"]}, {"input": "1 1 1 1000000000\r\n", "output": ["2000000000"]}, {"input": "1 500000000 1000000000 1000000000\r\n", "output": ["1000000001"]}, {"input": "15 15 15 15\r\n", "output": ["30"]}]
100
100
100
[{'input': '1 4 3 9\r\n', 'output': ['15']}, {'input': '8 3 3 2\r\n', 'output': ['2']}, {'input': '15 15 15 15\r\n', 'output': ['30']}, {'input': '1 2 9 5\r\n', 'output': ['4']}, {'input': '9 6 2 5\r\n', 'output': ['3']}]
[{'input': '15 15 15 15\r\n', 'output': ['30']}, {'input': '1 4 4 5\r\n', 'output': ['7']}, {'input': '5 5 2 6\r\n', 'output': ['9']}, {'input': '3 1 2 7\r\n', 'output': ['12']}, {'input': '8 3 3 2\r\n', 'output': ['2']}]
[{'input': '1 500000000 1000000000 1000000000\r\n', 'output': ['1000000001']}, {'input': '2 3 1 6\r\n', 'output': ['10']}, {'input': '2 2 3 4\r\n', 'output': ['7']}, {'input': '500000000 250000000 750000000 1000000000\r\n', 'output': ['1500000000']}, {'input': '9 6 2 5\r\n', 'output': ['3']}]
[{'input': '3 1 4 2\r\n', 'output': ['1']}, {'input': '5 5 4 1\r\n', 'output': ['1']}, {'input': '3 1 2 7\r\n', 'output': ['12']}, {'input': '15 15 15 15\r\n', 'output': ['30']}, {'input': '1000000000 1000000000 1000000000 1000000000\r\n', 'output': ['2000000000']}]
[{'input': '89 983 751 1000\r\n', 'output': ['1106']}, {'input': '1 3 3 6\r\n', 'output': ['10']}, {'input': '1 4 4 6\r\n', 'output': ['9']}, {'input': '500 1 500 1000\r\n', 'output': ['1501']}, {'input': '1 5 4 8\r\n', 'output': ['12']}]
100
100
100
100
100
100
100
100
100
100
75
75
50
75
50
245
100
100
65
["3 1\n-1 0 1", "2 1\n1 0", "1 1\n-1"]
The first line contains two integers $$$n$$$ and $$$p$$$ ($$$1 \leq n \leq 50$$$, $$$0 \leq p \leq 1$$$) β€” the number of pieces and Kuro's wanted parity. The second line contains $$$n$$$ integers $$$c_{1}, c_{2}, ..., c_{n}$$$ ($$$-1 \leq c_{i} \leq 1$$$) β€” the colors of the pieces.
aaf5f8afa71d9d25ebab405dddec78cd
import java.io.*; import java.util.*; public class Codeforces979E { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); int[] c = new int[n]; st = new StringTokenizer(br.readLine()); for (int i = 0; i < n; i++) { c[i] = Integer.parseInt(st.nextToken()); } //list of powers of 2 until 2^{n^2}, mod 1000000007 int[] twopower = new int[n*n+1]; twopower[0] = 1; for (int i = 1; i <= n*n; i++) { twopower[i] = (2*twopower[i-1])%1000000007; } //Pascal's triangle until n choose k, mod 1000000007 int[][] pascal = new int[n+1][n+1]; for (int i = 0; i <= n; i++) { pascal[i][0] = 1; pascal[0][i] = 1; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { pascal[i][j] = (pascal[i][j-1]+pascal[i-1][j])%1000000007; } } //dp[x][y][z] means the last x have all arrows intact //and there are y 0's and z 1's at the start with no //arrows going between them. //we only care when 0 <= x+y+z <= n. //answer is dp[n][0][0]. int[][][] dp = new int[n+1][n+1][n+1]; //base case of x = 0 for (int y = 0; y <= n; y++) { for (int z = 0; z <= (n-y); z++) { if (p == (y+z)%2) { dp[0][y][z] = 1; } } } for (int x = 1; x <= n; x++) { for (int y = 0; y <= (n-x); y++) { for (int z = 0; z <= (n-x-y); z++) { if (c[n-x] != 1) { int evenmultiple; int oddmultiple; if (z == 0) { evenmultiple = 1; oddmultiple = 0; } else { evenmultiple = twopower[z-1]; oddmultiple = twopower[z-1]; } long evenk = (long) evenmultiple * (long) dp[x-1][y+1][z]; evenk %= 1000000007; long oddk = (long) oddmultiple * (long) dp[x-1][y][z]; oddk %= 1000000007; oddk *= (long) twopower[x-1]; oddk %= 1000000007; long totalk = evenk+oddk; totalk *= twopower[y]; totalk %= 1000000007; dp[x][y][z] += (int) totalk; } if (c[n-x] != 0) { int evenmultiple; int oddmultiple; if (y == 0) { evenmultiple = 1; oddmultiple = 0; } else { evenmultiple = twopower[y-1]; oddmultiple = twopower[y-1]; } long evenk = (long) evenmultiple * (long) dp[x-1][y][z+1]; evenk %= 1000000007; long oddk = (long) oddmultiple * (long) dp[x-1][y][z]; oddk %= 1000000007; oddk *= (long) twopower[x-1]; oddk %= 1000000007; long totalk = evenk+oddk; totalk *= twopower[z]; totalk %= 1000000007; dp[x][y][z] += (int) totalk; } dp[x][y][z] %= 1000000007; } } } pw.println(dp[n][0][0]); pw.close(); } }
["6", "1", "2"]
Java
NoteIn the first example, there are $$$6$$$ ways to color the pieces and add the arrows, as are shown in the figure below. The scores are $$$3, 3, 5$$$ for the first row and $$$5, 3, 3$$$ for the second row, both from left to right.
Print a single integer β€” the number of ways to put the arrows and choose colors so the number of valid paths of alternating colors has the parity of $$$p$$$.
Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games.Kuro challenged Katie to create a game with only a white paper, a pencil, a pair of scissors and a lot of arrows (you can assume that the number of arrows is infinite). Immediately, Katie came up with the game called Topological Parity.The paper is divided into $$$n$$$ pieces enumerated from $$$1$$$ to $$$n$$$. Shiro has painted some pieces with some color. Specifically, the $$$i$$$-th piece has color $$$c_{i}$$$ where $$$c_{i} = 0$$$ defines black color, $$$c_{i} = 1$$$ defines white color and $$$c_{i} = -1$$$ means that the piece hasn't been colored yet.The rules of the game is simple. Players must put some arrows between some pairs of different pieces in such a way that for each arrow, the number in the piece it starts from is less than the number of the piece it ends at. Also, two different pieces can only be connected by at most one arrow. After that the players must choose the color ($$$0$$$ or $$$1$$$) for each of the unpainted pieces. The score of a valid way of putting the arrows and coloring pieces is defined as the number of paths of pieces of alternating colors. For example, $$$[1 \to 0 \to 1 \to 0]$$$, $$$[0 \to 1 \to 0 \to 1]$$$, $$$[1]$$$, $$$[0]$$$ are valid paths and will be counted. You can only travel from piece $$$x$$$ to piece $$$y$$$ if and only if there is an arrow from $$$x$$$ to $$$y$$$.But Kuro is not fun yet. He loves parity. Let's call his favorite parity $$$p$$$ where $$$p = 0$$$ stands for "even" and $$$p = 1$$$ stands for "odd". He wants to put the arrows and choose colors in such a way that the score has the parity of $$$p$$$.It seems like there will be so many ways which satisfy Kuro. He wants to count the number of them but this could be a very large number. Let's help him with his problem, but print it modulo $$$10^{9} + 7$$$.
[{"input": "3 1\r\n-1 0 1\r\n", "output": ["6"]}, {"input": "2 1\r\n1 0\r\n", "output": ["1"]}, {"input": "1 1\r\n-1\r\n", "output": ["2"]}, {"input": "1 0\r\n-1\r\n", "output": ["0"]}, {"input": "1 1\r\n0\r\n", "output": ["1"]}, {"input": "5 1\r\n-1 -1 -1 -1 -1\r\n", "output": ["16512"]}, {"input": "5 0\r\n-1 -1 -1 -1 -1\r\n", "output": ["16256"]}, {"input": "10 1\r\n1 1 1 1 0 0 0 1 0 0\r\n", "output": ["185921272"]}, {"input": "50 1\r\n-1 -1 1 0 1 1 0 -1 1 0 -1 -1 0 0 -1 -1 0 1 1 -1 1 0 -1 1 1 -1 -1 -1 1 -1 -1 0 -1 0 -1 0 0 -1 -1 0 1 -1 0 1 -1 1 0 -1 -1 1\r\n", "output": ["803313751"]}, {"input": "20 1\r\n0 0 -1 0 1 1 1 1 -1 -1 1 1 1 -1 0 0 1 1 1 0\r\n", "output": ["483548109"]}, {"input": "30 0\r\n1 0 1 1 0 -1 0 1 -1 0 1 -1 0 -1 1 1 -1 1 0 1 0 -1 1 1 0 1 -1 0 1 1\r\n", "output": ["40673917"]}, {"input": "40 1\r\n-1 1 1 1 0 -1 -1 1 1 -1 1 1 1 0 0 -1 1 0 1 -1 -1 1 0 1 1 0 1 0 0 -1 -1 1 -1 1 1 1 1 0 -1 0\r\n", "output": ["73320910"]}, {"input": "50 1\r\n-1 -1 0 -1 1 0 1 0 1 -1 -1 0 0 0 -1 0 0 -1 0 1 -1 0 1 -1 1 -1 1 -1 -1 1 -1 -1 0 1 1 0 0 0 1 -1 -1 1 0 0 -1 0 1 1 0 0\r\n", "output": ["772364444"]}, {"input": "50 1\r\n-1 -1 -1 -1 -1 0 -1 -1 -1 0 1 0 -1 0 1 -1 -1 -1 1 0 1 -1 0 1 0 1 0 0 1 1 -1 1 -1 -1 1 1 -1 -1 0 -1 -1 1 -1 1 -1 1 1 0 0 -1\r\n", "output": ["279519499"]}, {"input": "3 1\r\n0 -1 -1\r\n", "output": ["18"]}, {"input": "4 0\r\n1 -1 1 0\r\n", "output": ["64"]}, {"input": "21 0\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n", "output": ["0"]}, {"input": "29 1\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n", "output": ["733922348"]}, {"input": "41 0\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n", "output": ["0"]}, {"input": "3 0\r\n0 0 0\r\n", "output": ["0"]}, {"input": "38 1\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["0"]}, {"input": "25 1\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["322050759"]}, {"input": "30 0\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["549790477"]}, {"input": "46 0\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["480432768"]}, {"input": "10 0\r\n1 0 -1 1 -1 0 0 1 1 0\r\n", "output": ["743685088"]}, {"input": "6 0\r\n-1 0 -1 1 1 1\r\n", "output": ["61440"]}, {"input": "7 0\r\n1 0 1 1 -1 1 1\r\n", "output": ["2359296"]}, {"input": "9 0\r\n0 -1 -1 -1 -1 -1 1 0 -1\r\n", "output": ["560111071"]}, {"input": "6 1\r\n1 -1 -1 -1 0 0\r\n", "output": ["131072"]}, {"input": "6 0\r\n0 -1 -1 0 0 -1\r\n", "output": ["135168"]}, {"input": "8 0\r\n-1 0 1 -1 1 -1 1 1\r\n", "output": ["56964601"]}, {"input": "6 1\r\n1 1 0 -1 -1 -1\r\n", "output": ["133120"]}, {"input": "22 1\r\n0 -1 1 0 0 1 1 1 -1 -1 1 1 1 -1 1 1 0 0 -1 0 1 1\r\n", "output": ["981309322"]}, {"input": "47 1\r\n0 -1 0 1 0 -1 1 -1 1 -1 1 -1 0 0 -1 0 -1 1 -1 -1 0 1 -1 1 0 0 1 -1 0 1 0 1 0 1 0 1 -1 -1 1 -1 -1 -1 0 1 1 0 1\r\n", "output": ["716651774"]}, {"input": "2 1\r\n0 1\r\n", "output": ["1"]}, {"input": "36 1\r\n-1 0 0 1 1 0 -1 -1 -1 -1 1 1 0 -1 0 1 0 -1 0 -1 0 1 0 -1 -1 0 1 -1 0 -1 0 -1 1 0 1 1\r\n", "output": ["693536347"]}, {"input": "37 0\r\n0 -1 0 0 0 -1 0 1 0 0 -1 0 -1 -1 0 1 1 0 -1 -1 -1 -1 1 -1 0 0 0 1 -1 -1 1 -1 1 1 -1 -1 -1\r\n", "output": ["915368288"]}, {"input": "4 1\r\n1 -1 -1 1\r\n", "output": ["120"]}, {"input": "35 0\r\n0 0 -1 -1 1 -1 1 -1 1 0 1 0 -1 0 1 1 -1 1 -1 0 0 -1 0 0 1 -1 -1 0 1 1 -1 1 1 1 -1\r\n", "output": ["45647242"]}, {"input": "25 1\r\n1 0 0 -1 -1 0 1 0 -1 1 0 0 0 -1 0 0 1 -1 -1 1 -1 -1 -1 1 1\r\n", "output": ["66699122"]}, {"input": "36 1\r\n-1 0 -1 -1 1 0 0 -1 1 0 0 -1 1 -1 1 0 1 0 0 0 1 1 1 0 1 1 0 -1 1 -1 0 0 0 1 1 -1\r\n", "output": ["77953873"]}, {"input": "9 1\r\n-1 -1 1 1 1 -1 -1 0 1\r\n", "output": ["608326411"]}, {"input": "36 0\r\n-1 0 0 -1 -1 -1 0 -1 0 1 -1 -1 1 1 -1 1 0 0 1 -1 1 1 -1 0 0 1 1 1 -1 1 1 -1 1 1 1 -1\r\n", "output": ["152782818"]}, {"input": "10 1\r\n1 1 1 -1 0 -1 -1 1 1 0\r\n", "output": ["487370169"]}, {"input": "7 0\r\n1 0 -1 1 -1 1 0\r\n", "output": ["4194304"]}, {"input": "2 0\r\n-1 0\r\n", "output": ["3"]}, {"input": "5 1\r\n-1 1 0 0 -1\r\n", "output": ["1920"]}, {"input": "2 0\r\n-1 -1\r\n", "output": ["6"]}, {"input": "4 1\r\n0 1 -1 -1\r\n", "output": ["136"]}, {"input": "5 0\r\n-1 0 0 0 1\r\n", "output": ["1088"]}, {"input": "17 0\r\n0 -1 -1 0 1 -1 0 0 -1 -1 0 -1 -1 -1 0 0 0\r\n", "output": ["310296666"]}, {"input": "10 0\r\n1 -1 0 1 1 -1 -1 0 1 0\r\n", "output": ["487370169"]}, {"input": "31 0\r\n1 -1 -1 0 -1 0 -1 -1 0 -1 -1 -1 1 1 0 1 -1 1 1 0 0 -1 0 1 -1 1 0 -1 1 -1 -1\r\n", "output": ["304540143"]}, {"input": "41 1\r\n0 0 -1 1 -1 -1 1 -1 -1 1 -1 1 -1 1 -1 0 1 1 1 0 0 1 1 -1 0 0 1 0 0 1 1 1 -1 0 -1 1 0 1 1 1 1\r\n", "output": ["589337580"]}, {"input": "37 1\r\n1 -1 1 -1 -1 -1 0 1 -1 -1 1 0 0 0 1 1 -1 0 -1 1 -1 0 1 -1 -1 -1 -1 -1 0 -1 0 0 -1 0 -1 -1 -1\r\n", "output": ["916646835"]}, {"input": "31 0\r\n1 0 1 1 0 0 0 -1 -1 -1 -1 -1 0 1 1 1 0 -1 1 -1 -1 1 -1 1 1 0 0 1 1 -1 0\r\n", "output": ["253181331"]}, {"input": "4 1\r\n1 0 1 0\r\n", "output": ["32"]}, {"input": "26 1\r\n1 -1 1 1 1 1 -1 1 -1 1 -1 -1 0 -1 -1 -1 1 0 -1 -1 0 1 -1 0 1 0\r\n", "output": ["996763118"]}, {"input": "28 1\r\n0 0 1 1 -1 1 -1 1 0 -1 -1 -1 0 -1 0 -1 1 0 -1 1 0 -1 -1 0 -1 1 1 -1\r\n", "output": ["618844160"]}, {"input": "24 1\r\n0 0 0 1 1 0 -1 0 -1 1 -1 -1 0 0 1 1 0 -1 0 0 0 0 1 1\r\n", "output": ["189147304"]}, {"input": "17 0\r\n-1 0 -1 1 0 0 1 1 -1 -1 -1 -1 -1 1 1 -1 -1\r\n", "output": ["555719737"]}, {"input": "42 1\r\n0 1 -1 0 -1 0 -1 1 -1 1 0 1 1 -1 0 -1 -1 1 -1 -1 0 -1 1 -1 0 1 0 1 -1 1 -1 1 0 0 -1 0 1 0 1 1 0 0\r\n", "output": ["386658717"]}, {"input": "3 0\r\n0 -1 -1\r\n", "output": ["14"]}, {"input": "9 1\r\n0 1 -1 -1 -1 -1 1 1 1\r\n", "output": ["755810045"]}, {"input": "9 0\r\n1 1 0 0 1 -1 -1 0 0\r\n", "output": ["438952513"]}, {"input": "14 1\r\n-1 0 0 1 -1 0 0 0 -1 -1 0 -1 0 0\r\n", "output": ["829277977"]}, {"input": "20 0\r\n1 -1 1 -1 -1 -1 0 1 1 0 1 0 -1 1 1 -1 1 0 1 1\r\n", "output": ["841268608"]}, {"input": "18 0\r\n1 1 1 -1 0 -1 -1 0 -1 -1 0 0 -1 0 -1 0 -1 1\r\n", "output": ["557382306"]}, {"input": "16 0\r\n1 -1 0 0 0 -1 -1 -1 0 -1 -1 1 0 0 -1 1\r\n", "output": ["807669877"]}, {"input": "27 1\r\n-1 0 -1 -1 -1 0 1 -1 1 0 0 -1 0 1 0 0 0 -1 -1 1 -1 -1 -1 0 1 0 0\r\n", "output": ["61073361"]}, {"input": "2 0\r\n-1 1\r\n", "output": ["3"]}, {"input": "34 1\r\n1 0 -1 0 0 0 -1 1 0 1 1 1 1 1 1 -1 0 0 1 0 -1 -1 -1 1 -1 -1 -1 1 1 1 -1 1 1 -1\r\n", "output": ["132603129"]}, {"input": "17 0\r\n1 0 1 1 0 1 1 0 1 1 1 0 1 0 0 -1 0\r\n", "output": ["585862415"]}, {"input": "16 0\r\n-1 0 0 1 0 0 0 0 -1 -1 -1 -1 1 1 0 1\r\n", "output": ["878929813"]}, {"input": "17 0\r\n0 0 0 0 0 1 -1 -1 -1 1 -1 1 0 0 1 -1 -1\r\n", "output": ["427689083"]}, {"input": "38 0\r\n-1 -1 1 1 -1 -1 1 -1 0 1 -1 1 1 1 -1 1 0 1 0 -1 1 -1 -1 0 0 1 -1 -1 0 -1 0 -1 -1 0 1 0 -1 0\r\n", "output": ["502273788"]}, {"input": "33 0\r\n0 1 -1 -1 -1 1 -1 1 1 -1 -1 -1 -1 0 1 0 -1 0 0 -1 1 -1 -1 0 0 -1 0 0 1 0 1 1 1\r\n", "output": ["52976952"]}, {"input": "32 1\r\n0 0 1 0 -1 0 1 -1 -1 -1 0 1 0 0 1 0 -1 -1 1 1 1 0 0 1 -1 -1 1 0 0 -1 0 1\r\n", "output": ["247728070"]}, {"input": "6 0\r\n-1 1 1 -1 -1 -1\r\n", "output": ["267264"]}, {"input": "27 1\r\n0 -1 1 0 -1 1 1 -1 0 -1 0 0 0 -1 -1 0 0 -1 -1 0 -1 0 -1 0 0 1 1\r\n", "output": ["28918236"]}, {"input": "27 1\r\n0 -1 -1 1 1 1 -1 1 0 0 1 -1 -1 1 -1 1 1 1 1 1 0 0 0 0 -1 -1 0\r\n", "output": ["69931865"]}, {"input": "17 1\r\n0 -1 -1 0 0 1 -1 -1 0 0 -1 1 0 -1 1 0 0\r\n", "output": ["427689083"]}, {"input": "34 0\r\n1 1 1 0 0 0 0 1 0 0 1 -1 1 1 -1 0 -1 1 1 1 0 1 1 -1 0 0 1 -1 -1 0 0 0 -1 -1\r\n", "output": ["115086916"]}, {"input": "31 1\r\n1 0 0 0 0 0 0 0 -1 0 0 0 1 -1 -1 -1 0 0 -1 0 1 -1 1 0 1 1 1 1 -1 -1 1\r\n", "output": ["186475897"]}, {"input": "48 1\r\n1 0 0 0 1 -1 1 1 0 -1 0 -1 1 1 0 -1 -1 -1 0 0 0 1 0 1 0 -1 -1 -1 -1 1 0 1 -1 -1 -1 1 -1 0 1 0 0 1 -1 0 -1 0 0 0\r\n", "output": ["763606955"]}, {"input": "5 0\r\n0 -1 0 0 0\r\n", "output": ["768"]}, {"input": "43 0\r\n1 0 0 -1 0 -1 0 -1 1 1 -1 1 -1 0 0 1 -1 -1 -1 0 0 -1 1 -1 -1 1 0 0 1 -1 0 -1 -1 -1 -1 -1 1 1 0 -1 -1 -1 0\r\n", "output": ["477560567"]}, {"input": "11 1\r\n1 0 1 0 -1 1 0 -1 -1 0 0\r\n", "output": ["67049563"]}, {"input": "13 1\r\n-1 1 0 0 -1 0 -1 1 -1 -1 1 1 0\r\n", "output": ["621572676"]}]
100
100
100
[{'input': '6 1\r\n1 1 0 -1 -1 -1\r\n', 'output': ['133120']}, {'input': '10 1\r\n1 1 1 1 0 0 0 1 0 0\r\n', 'output': ['185921272']}, {'input': '6 0\r\n-1 0 -1 1 1 1\r\n', 'output': ['61440']}, {'input': '50 1\r\n-1 -1 1 0 1 1 0 -1 1 0 -1 -1 0 0 -1 -1 0 1 1 -1 1 0 -1 1 1 -1 -1 -1 1 -1 -1 0 -1 0 -1 0 0 -1 -1 0 1 -1 0 1 -1 1 0 -1 -1 1\r\n', 'output': ['803313751']}, {'input': '14 1\r\n-1 0 0 1 -1 0 0 0 -1 -1 0 -1 0 0\r\n', 'output': ['829277977']}]
[{'input': '4 1\r\n0 1 -1 -1\r\n', 'output': ['136']}, {'input': '29 1\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n', 'output': ['733922348']}, {'input': '3 0\r\n0 0 0\r\n', 'output': ['0']}, {'input': '2 0\r\n-1 1\r\n', 'output': ['3']}, {'input': '46 0\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n', 'output': ['480432768']}]
[{'input': '17 0\r\n-1 0 -1 1 0 0 1 1 -1 -1 -1 -1 -1 1 1 -1 -1\r\n', 'output': ['555719737']}, {'input': '9 0\r\n1 1 0 0 1 -1 -1 0 0\r\n', 'output': ['438952513']}, {'input': '4 1\r\n0 1 -1 -1\r\n', 'output': ['136']}, {'input': '16 0\r\n-1 0 0 1 0 0 0 0 -1 -1 -1 -1 1 1 0 1\r\n', 'output': ['878929813']}, {'input': '42 1\r\n0 1 -1 0 -1 0 -1 1 -1 1 0 1 1 -1 0 -1 -1 1 -1 -1 0 -1 1 -1 0 1 0 1 -1 1 -1 1 0 0 -1 0 1 0 1 1 0 0\r\n', 'output': ['386658717']}]
[{'input': '4 0\r\n1 -1 1 0\r\n', 'output': ['64']}, {'input': '1 0\r\n-1\r\n', 'output': ['0']}, {'input': '10 1\r\n1 1 1 -1 0 -1 -1 1 1 0\r\n', 'output': ['487370169']}, {'input': '7 0\r\n1 0 1 1 -1 1 1\r\n', 'output': ['2359296']}, {'input': '5 1\r\n-1 -1 -1 -1 -1\r\n', 'output': ['16512']}]
[{'input': '30 0\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n', 'output': ['549790477']}, {'input': '31 0\r\n1 0 1 1 0 0 0 -1 -1 -1 -1 -1 0 1 1 1 0 -1 1 -1 -1 1 -1 1 1 0 0 1 1 -1 0\r\n', 'output': ['253181331']}, {'input': '7 0\r\n1 0 1 1 -1 1 1\r\n', 'output': ['2359296']}, {'input': '6 1\r\n1 1 0 -1 -1 -1\r\n', 'output': ['133120']}, {'input': '14 1\r\n-1 0 0 1 -1 0 0 0 -1 -1 0 -1 0 0\r\n', 'output': ['829277977']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
246
100
100
100
["3\n1 3 5", "5\n1 0 1 5 1", "3\n4 3 1", "4\n3 9 9 3"]
The first line of input contains a non-negative integer n (1 ≀ n ≀ 100) β€” the length of the sequence. The second line contains n space-separated non-negative integers a1, a2, ..., an (0 ≀ ai ≀ 100) β€” the elements of the sequence.
2b8c2deb5d7e49e8e3ededabfd4427db
import java.io.*; import java.util.*; public class A { FScanner in = new FScanner(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out), true); void run() { int n = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { int x = in.nextInt(); a[i] = x; } out.print(a[0] % 2 != 0 && a[n - 1] % 2 != 0 && n % 2 == 1 ? "Yes" : "No"); out.close(); } public static void main(String[] args) { new A().run(); } static class FScanner { BufferedReader br; StringTokenizer st; FScanner() { 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(); } double nextDouble() { return Double.parseDouble(next()); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } char[][] nextCharArray(int n, int m) { char[][] g = new char[n][m]; for (int i = 0; i < n; i++) g[i] = next().toCharArray(); return g; } double[] nextDoubleArray(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextDouble(); return a; } 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; } } }
["Yes", "Yes", "No", "No"]
Java
NoteIn the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise. You can output each letter in any case (upper or lower).
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.
[{"input": "3\r\n1 3 5\r\n", "output": ["YES", "Yes"]}, {"input": "5\r\n1 0 1 5 1\r\n", "output": ["YES", "Yes"]}, {"input": "3\r\n4 3 1\r\n", "output": ["No", "NO"]}, {"input": "4\r\n3 9 9 3\r\n", "output": ["No", "NO"]}, {"input": "1\r\n1\r\n", "output": ["YES", "Yes"]}, {"input": "5\r\n100 99 100 99 99\r\n", "output": ["No", "NO"]}, {"input": "100\r\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\r\n", "output": ["No", "NO"]}, {"input": "1\r\n0\r\n", "output": ["No", "NO"]}, {"input": "2\r\n1 1\r\n", "output": ["No", "NO"]}, {"input": "2\r\n10 10\r\n", "output": ["No", "NO"]}, {"input": "2\r\n54 21\r\n", "output": ["No", "NO"]}, {"input": "5\r\n0 0 0 0 0\r\n", "output": ["No", "NO"]}, {"input": "5\r\n67 92 0 26 43\r\n", "output": ["YES", "Yes"]}, {"input": "15\r\n45 52 35 80 68 80 93 57 47 32 69 23 63 90 43\r\n", "output": ["YES", "Yes"]}, {"input": "15\r\n81 28 0 82 71 64 63 89 87 92 38 30 76 72 36\r\n", "output": ["No", "NO"]}, {"input": "50\r\n49 32 17 59 77 98 65 50 85 10 40 84 65 34 52 25 1 31 61 45 48 24 41 14 76 12 33 76 44 86 53 33 92 58 63 93 50 24 31 79 67 50 72 93 2 38 32 14 87 99\r\n", "output": ["No", "NO"]}, {"input": "55\r\n65 69 53 66 11 100 68 44 43 17 6 66 24 2 6 6 61 72 91 53 93 61 52 96 56 42 6 8 79 49 76 36 83 58 8 43 2 90 71 49 80 21 75 13 76 54 95 61 58 82 40 33 73 61 46\r\n", "output": ["No", "NO"]}, {"input": "99\r\n73 89 51 85 42 67 22 80 75 3 90 0 52 100 90 48 7 15 41 1 54 2 23 62 86 68 2 87 57 12 45 34 68 54 36 49 27 46 22 70 95 90 57 91 90 79 48 89 67 92 28 27 25 37 73 66 13 89 7 99 62 53 48 24 73 82 62 88 26 39 21 86 50 95 26 27 60 6 56 14 27 90 55 80 97 18 37 36 70 2 28 53 36 77 39 79 82 42 69\r\n", "output": ["YES", "Yes"]}, {"input": "99\r\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99\r\n", "output": ["YES", "Yes"]}, {"input": "100\r\n61 63 34 45 20 91 31 28 40 27 94 1 73 5 69 10 56 94 80 23 79 99 59 58 13 56 91 59 77 78 88 72 80 72 70 71 63 60 41 41 41 27 83 10 43 14 35 48 0 78 69 29 63 33 42 67 1 74 51 46 79 41 37 61 16 29 82 28 22 14 64 49 86 92 82 55 54 24 75 58 95 31 3 34 26 23 78 91 49 6 30 57 27 69 29 54 42 0 61 83\r\n", "output": ["No", "NO"]}, {"input": "6\r\n1 2 2 2 2 1\r\n", "output": ["No", "NO"]}, {"input": "3\r\n1 2 1\r\n", "output": ["YES", "Yes"]}, {"input": "4\r\n1 3 2 3\r\n", "output": ["No", "NO"]}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": ["No", "NO"]}, {"input": "6\r\n1 1 0 0 1 1\r\n", "output": ["No", "NO"]}, {"input": "4\r\n1 4 9 3\r\n", "output": ["No", "NO"]}, {"input": "4\r\n1 0 1 1\r\n", "output": ["No", "NO"]}, {"input": "10\r\n1 0 0 1 1 1 1 1 1 1\r\n", "output": ["No", "NO"]}, {"input": "10\r\n9 2 5 7 8 3 1 9 4 9\r\n", "output": ["No", "NO"]}, {"input": "99\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2\r\n", "output": ["No", "NO"]}, {"input": "6\r\n1 2 1 2 2 1\r\n", "output": ["No", "NO"]}, {"input": "6\r\n1 0 1 0 0 1\r\n", "output": ["No", "NO"]}, {"input": "4\r\n1 3 4 7\r\n", "output": ["No", "NO"]}, {"input": "8\r\n1 1 1 2 1 1 1 1\r\n", "output": ["No", "NO"]}, {"input": "3\r\n1 1 2\r\n", "output": ["No", "NO"]}, {"input": "5\r\n1 2 1 2 1\r\n", "output": ["YES", "Yes"]}, {"input": "5\r\n5 4 4 2 1\r\n", "output": ["YES", "Yes"]}, {"input": "6\r\n1 3 3 3 3 1\r\n", "output": ["No", "NO"]}, {"input": "7\r\n1 2 1 2 2 2 1\r\n", "output": ["YES", "Yes"]}, {"input": "4\r\n1 2 2 1\r\n", "output": ["No", "NO"]}, {"input": "6\r\n1 2 3 4 6 5\r\n", "output": ["No", "NO"]}, {"input": "5\r\n1 1 2 2 2\r\n", "output": ["No", "NO"]}, {"input": "5\r\n1 0 0 1 1\r\n", "output": ["YES", "Yes"]}, {"input": "3\r\n1 2 4\r\n", "output": ["No", "NO"]}, {"input": "3\r\n1 0 2\r\n", "output": ["No", "NO"]}, {"input": "5\r\n1 1 1 0 1\r\n", "output": ["YES", "Yes"]}, {"input": "4\r\n3 9 2 3\r\n", "output": ["No", "NO"]}, {"input": "6\r\n1 1 1 4 4 1\r\n", "output": ["No", "NO"]}, {"input": "6\r\n1 2 3 5 6 7\r\n", "output": ["No", "NO"]}, {"input": "6\r\n1 1 1 2 2 1\r\n", "output": ["No", "NO"]}, {"input": "6\r\n1 1 1 0 0 1\r\n", "output": ["No", "NO"]}, {"input": "5\r\n1 2 2 5 5\r\n", "output": ["YES", "Yes"]}, {"input": "5\r\n1 3 2 4 5\r\n", "output": ["YES", "Yes"]}, {"input": "8\r\n1 2 3 5 7 8 8 5\r\n", "output": ["No", "NO"]}, {"input": "10\r\n1 1 1 2 1 1 1 1 1 1\r\n", "output": ["No", "NO"]}, {"input": "4\r\n1 0 0 1\r\n", "output": ["No", "NO"]}, {"input": "7\r\n1 0 1 1 0 0 1\r\n", "output": ["YES", "Yes"]}, {"input": "7\r\n1 4 5 7 6 6 3\r\n", "output": ["YES", "Yes"]}, {"input": "4\r\n2 2 2 2\r\n", "output": ["No", "NO"]}, {"input": "5\r\n2 3 4 5 6\r\n", "output": ["No", "NO"]}, {"input": "4\r\n1 1 2 1\r\n", "output": ["No", "NO"]}, {"input": "3\r\n1 2 3\r\n", "output": ["YES", "Yes"]}, {"input": "6\r\n1 3 3 2 2 3\r\n", "output": ["No", "NO"]}, {"input": "4\r\n1 1 2 3\r\n", "output": ["No", "NO"]}, {"input": "4\r\n1 2 3 5\r\n", "output": ["No", "NO"]}, {"input": "5\r\n3 4 4 3 3\r\n", "output": ["YES", "Yes"]}, {"input": "4\r\n3 2 2 3\r\n", "output": ["No", "NO"]}, {"input": "6\r\n1 1 1 1 2 1\r\n", "output": ["No", "NO"]}, {"input": "6\r\n1 1 2 2 1 1\r\n", "output": ["No", "NO"]}, {"input": "10\r\n3 4 2 4 3 2 2 4 4 3\r\n", "output": ["No", "NO"]}, {"input": "7\r\n1 2 4 3 2 4 5\r\n", "output": ["YES", "Yes"]}, {"input": "28\r\n75 51 25 52 13 7 34 29 5 59 68 56 13 2 9 37 59 83 18 32 36 30 20 43 92 76 78 67\r\n", "output": ["No", "NO"]}, {"input": "79\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 18\r\n", "output": ["No", "NO"]}, {"input": "100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["No", "NO"]}]
100
100
100
[{'input': '4\r\n3 2 2 3\r\n', 'output': ['No', 'NO']}, {'input': '7\r\n1 0 1 1 0 0 1\r\n', 'output': ['YES', 'Yes']}, {'input': '5\r\n1 1 1 0 1\r\n', 'output': ['YES', 'Yes']}, {'input': '6\r\n1 1 0 0 1 1\r\n', 'output': ['No', 'NO']}, {'input': '7\r\n1 2 4 3 2 4 5\r\n', 'output': ['YES', 'Yes']}]
[{'input': '2\r\n1 1\r\n', 'output': ['No', 'NO']}, {'input': '5\r\n3 4 4 3 3\r\n', 'output': ['YES', 'Yes']}, {'input': '10\r\n3 4 2 4 3 2 2 4 4 3\r\n', 'output': ['No', 'NO']}, {'input': '5\r\n100 99 100 99 99\r\n', 'output': ['No', 'NO']}, {'input': '3\r\n1 0 2\r\n', 'output': ['No', 'NO']}]
[{'input': '6\r\n1 2 2 2 2 1\r\n', 'output': ['No', 'NO']}, {'input': '4\r\n3 9 2 3\r\n', 'output': ['No', 'NO']}, {'input': '5\r\n1 1 2 2 2\r\n', 'output': ['No', 'NO']}, {'input': '6\r\n1 1 2 2 1 1\r\n', 'output': ['No', 'NO']}, {'input': '6\r\n1 1 1 2 2 1\r\n', 'output': ['No', 'NO']}]
[{'input': '6\r\n1 1 1 1 1 1\r\n', 'output': ['No', 'NO']}, {'input': '28\r\n75 51 25 52 13 7 34 29 5 59 68 56 13 2 9 37 59 83 18 32 36 30 20 43 92 76 78 67\r\n', 'output': ['No', 'NO']}, {'input': '5\r\n1 2 2 5 5\r\n', 'output': ['YES', 'Yes']}, {'input': '5\r\n100 99 100 99 99\r\n', 'output': ['No', 'NO']}, {'input': '4\r\n1 3 4 7\r\n', 'output': ['No', 'NO']}]
[{'input': '6\r\n1 1 1 4 4 1\r\n', 'output': ['No', 'NO']}, {'input': '4\r\n3 2 2 3\r\n', 'output': ['No', 'NO']}, {'input': '5\r\n5 4 4 2 1\r\n', 'output': ['YES', 'Yes']}, {'input': '2\r\n54 21\r\n', 'output': ['No', 'NO']}, {'input': '7\r\n1 4 5 7 6 6 3\r\n', 'output': ['YES', 'Yes']}]
100
100
100
100
100
100
100
93.33
100
100
75
100
75
87.5
87.5
247
100
98.666
85
["2 2", "123 456789"]
The only line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 250$$$, $$$1 \le k \le 10^{9}$$$).
f67173c973c6f83e88bc0ddb0b9bfa93
//package cf589d2; import java.io.*; import java.util.*; import static java.lang.Math.*; public class E { static long MOD = 1000000007; public static void main(String[] args) { MyScanner sc = new MyScanner(); int n = sc.nextInt(); long k = sc.nextLong(); long[][] choose = new long[n + 1][n + 1]; long[][] pow = new long[n + 1][2]; for(int i = 0; i <= n; i++) { choose[i][0] = 1; choose[i][i] = 1; } for(int i = 2; i <= n; i++) for(int j = 1; j < i; j++) choose[i][j] = (choose[i - 1][j] + choose[i - 1][j - 1]) % MOD; for(int i = 0; i <= n; i++) for(int j = 0; j < 2; j++) pow[i][j] = pMod(k - j, i); long[][] dp = new long[n + 1][n + 1]; dp[0][n] = 1; for(int i = 1; i <= n; i++) for(int j = 0; j <= n; j++) for(int l = 0; l <= j; l++) { long del = dp[i - 1][j] * choose[j][l] % MOD * pow[l][1] % MOD; if(l < j) del = del * pow[n - j][0] % MOD; else del = del * (pow[n - j][0] - pow[n - j][1] + MOD) % MOD; dp[i][l] = (dp[i][l] + del) % MOD; } out.println(dp[n][0]); out.close(); } public static long pMod(long x, long p) { if(p == 0) return 1; long l = pMod(x, p / 2); return l * l % MOD * (p % 2 == 1 ? x : 1) % MOD; } public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static class MyScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; String next() { while (st == null || !st.hasMoreElements()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
["7", "689974806"]
Java
NoteIn the first example, following $$$7$$$ cases are possible. In the second example, make sure you print the answer modulo $$$(10^{9} + 7)$$$.
Print the answer modulo $$$(10^{9} + 7)$$$.
You have $$$n \times n$$$ square grid and an integer $$$k$$$. Put an integer in each cell while satisfying the conditions below. All numbers in the grid should be between $$$1$$$ and $$$k$$$ inclusive. Minimum number of the $$$i$$$-th row is $$$1$$$ ($$$1 \le i \le n$$$). Minimum number of the $$$j$$$-th column is $$$1$$$ ($$$1 \le j \le n$$$). Find the number of ways to put integers in the grid. Since the answer can be very large, find the answer modulo $$$(10^{9} + 7)$$$. These are the examples of valid and invalid grid when $$$n=k=2$$$.
[{"input": "2 2\r\n", "output": ["7"]}, {"input": "123 456789\r\n", "output": ["689974806"]}, {"input": "250 1000000000\r\n", "output": ["770503193"]}, {"input": "250 1\r\n", "output": ["1"]}, {"input": "1 3\r\n", "output": ["1"]}, {"input": "3 497285769\r\n", "output": ["790515254"]}, {"input": "3 212096267\r\n", "output": ["501206544"]}, {"input": "4 221874066\r\n", "output": ["274467242"]}, {"input": "244 315404017\r\n", "output": ["868949606"]}, {"input": "218 325181815\r\n", "output": ["230476135"]}, {"input": "246 629926913\r\n", "output": ["283598434"]}, {"input": "216 639704712\r\n", "output": ["319243107"]}, {"input": "244 22597665\r\n", "output": ["56808536"]}, {"input": "218 737408162\r\n", "output": ["720936813"]}, {"input": "242 747185961\r\n", "output": ["365665959"]}, {"input": "220 51931060\r\n", "output": ["944377763"]}, {"input": "244 61708858\r\n", "output": ["84446310"]}, {"input": "216 104981514\r\n", "output": ["943178465"]}, {"input": "208 1\r\n", "output": ["1"]}, {"input": "236 1\r\n", "output": ["1"]}, {"input": "242 106758452\r\n", "output": ["437620405"]}, {"input": "216 411503551\r\n", "output": ["618370501"]}, {"input": "244 126314049\r\n", "output": ["662993833"]}, {"input": "214 431059147\r\n", "output": ["37643610"]}, {"input": "242 440836946\r\n", "output": ["687163955"]}, {"input": "220 528762598\r\n", "output": ["944995733"]}, {"input": "244 833507696\r\n", "output": ["89218992"]}, {"input": "218 548318195\r\n", "output": ["721573920"]}, {"input": "242 558095993\r\n", "output": ["300047623"]}, {"input": "224 26911790\r\n", "output": ["554883010"]}, {"input": "206 1\r\n", "output": ["1"]}, {"input": "234 1\r\n", "output": ["1"]}, {"input": "10 19549\r\n", "output": ["843886139"]}]
100
100
100
[{'input': '216 639704712\r\n', 'output': ['319243107']}, {'input': '244 126314049\r\n', 'output': ['662993833']}, {'input': '216 411503551\r\n', 'output': ['618370501']}, {'input': '220 51931060\r\n', 'output': ['944377763']}, {'input': '214 431059147\r\n', 'output': ['37643610']}]
[{'input': '10 19549\r\n', 'output': ['843886139']}, {'input': '208 1\r\n', 'output': ['1']}, {'input': '1 3\r\n', 'output': ['1']}, {'input': '3 497285769\r\n', 'output': ['790515254']}, {'input': '216 411503551\r\n', 'output': ['618370501']}]
[{'input': '3 497285769\r\n', 'output': ['790515254']}, {'input': '216 411503551\r\n', 'output': ['618370501']}, {'input': '216 104981514\r\n', 'output': ['943178465']}, {'input': '250 1000000000\r\n', 'output': ['770503193']}, {'input': '242 106758452\r\n', 'output': ['437620405']}]
[{'input': '10 19549\r\n', 'output': ['843886139']}, {'input': '216 411503551\r\n', 'output': ['618370501']}, {'input': '236 1\r\n', 'output': ['1']}, {'input': '224 26911790\r\n', 'output': ['554883010']}, {'input': '216 639704712\r\n', 'output': ['319243107']}]
[{'input': '246 629926913\r\n', 'output': ['283598434']}, {'input': '208 1\r\n', 'output': ['1']}, {'input': '220 528762598\r\n', 'output': ['944995733']}, {'input': '218 548318195\r\n', 'output': ['721573920']}, {'input': '242 106758452\r\n', 'output': ['437620405']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
248
100
100
100
["1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1", "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1", "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0"]
The input consists of four lines with each line describing a road part given in a counter-clockwise order. Each line contains four integers l, s, r, p β€” for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.
44fdf71d56bef949ec83f00d17c29127
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int a[][] = new int[5][5]; for (int i = 1; i < a.length; i++) { for (int j = 1; j < a.length; j++) { a[i][j] = sc.nextInt(); } } if (a[1][4] == 1 && (a[1][1] == 1 || a[1][2] == 1 || a[1][3] == 1 || a[2][1] == 1 || a[3][2] == 1 || a[4][3] == 1)) { System.out.println("YES"); } else if (a[2][4] == 1 && (a[2][1] == 1 || a[2][2] == 1 || a[2][3] == 1 || a[3][1] == 1 || a[4][2] == 1 || a[1][3] == 1)) { System.out.println("YES"); } else if (a[3][4] == 1 && (a[3][1] == 1 || a[3][2] == 1 || a[3][3] == 1 || a[4][1] == 1 || a[2][3] == 1 || a[1][2] == 1)) { System.out.println("YES"); } else if (a[4][4] == 1 && (a[4][1] == 1 || a[4][2] == 1 || a[4][3] == 1 || a[3][3] == 1 || a[1][1] == 1 || a[2][2] == 1)) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
["YES", "NO", "NO"]
Java
NoteIn the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur.
On a single line, print "YES" if an accident is possible, and "NO" otherwise.
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane getting into the intersection (l β€” left, s β€” straight, r β€” right) and a light p for a pedestrian crossing. An accident is possible if a car can hit a pedestrian. This can happen if the light of a pedestrian crossing of some part and the light of a lane that can get to or from that same part are green at the same time.Now, Sagheer is monitoring the configuration of the traffic lights. Your task is to help him detect whether an accident is possible.
[{"input": "1 0 0 1\r\n0 1 0 0\r\n0 0 1 0\r\n0 0 0 1\r\n", "output": ["YES"]}, {"input": "0 1 1 0\r\n1 0 1 0\r\n1 1 0 0\r\n0 0 0 1\r\n", "output": ["NO"]}, {"input": "1 0 0 0\r\n0 0 0 1\r\n0 0 0 0\r\n1 0 1 0\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 0 1\r\n", "output": ["NO"]}, {"input": "1 1 1 0\r\n0 1 0 1\r\n1 1 1 0\r\n1 1 1 1\r\n", "output": ["YES"]}, {"input": "0 1 1 0\r\n0 1 0 0\r\n1 0 0 1\r\n1 0 0 0\r\n", "output": ["YES"]}, {"input": "1 0 0 0\r\n0 1 0 0\r\n1 1 0 0\r\n0 1 1 0\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n0 1 0 1\r\n1 0 1 1\r\n1 1 1 0\r\n", "output": ["YES"]}, {"input": "1 1 0 0\r\n0 1 0 1\r\n1 1 1 0\r\n0 0 1 1\r\n", "output": ["YES"]}, {"input": "0 1 0 0\r\n0 0 0 0\r\n1 0 0 0\r\n0 0 0 1\r\n", "output": ["NO"]}, {"input": "0 0 1 0\r\n0 0 0 0\r\n1 1 0 0\r\n0 0 0 1\r\n", "output": ["NO"]}, {"input": "0 0 1 0\r\n0 1 0 1\r\n1 0 1 0\r\n0 0 1 0\r\n", "output": ["YES"]}, {"input": "1 1 1 0\r\n0 1 0 1\r\n1 1 1 1\r\n0 0 0 1\r\n", "output": ["YES"]}, {"input": "0 0 1 0\r\n0 0 0 0\r\n0 0 0 1\r\n0 0 0 1\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n0 1 0 1\r\n1 0 1 1\r\n0 0 0 1\r\n", "output": ["YES"]}, {"input": "1 1 0 0\r\n0 1 0 0\r\n1 1 1 0\r\n1 0 1 0\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n0 0 0 0\r\n0 0 0 1\r\n0 0 0 1\r\n", "output": ["NO"]}, {"input": "1 0 1 0\r\n1 1 0 0\r\n1 1 0 0\r\n0 0 0 0\r\n", "output": ["NO"]}, {"input": "0 0 1 0\r\n1 1 0 0\r\n1 0 1 0\r\n1 0 0 0\r\n", "output": ["NO"]}, {"input": "0 0 1 0\r\n1 0 0 0\r\n0 0 0 1\r\n0 0 0 1\r\n", "output": ["NO"]}, {"input": "0 1 1 0\r\n1 1 0 1\r\n1 0 0 1\r\n1 1 1 0\r\n", "output": ["YES"]}, {"input": "1 0 0 0\r\n1 1 0 0\r\n1 1 0 1\r\n0 0 1 0\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n1 1 0 0\r\n0 0 0 1\r\n0 0 1 0\r\n", "output": ["NO"]}, {"input": "0 1 0 0\r\n0 0 0 1\r\n0 1 0 0\r\n0 0 0 1\r\n", "output": ["NO"]}, {"input": "0 1 0 0\r\n1 1 0 1\r\n1 0 0 1\r\n1 1 0 1\r\n", "output": ["YES"]}, {"input": "1 0 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 1 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 1 1\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 1\r\n1 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 1\r\n0 1 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["NO"]}, {"input": "0 0 0 1\r\n0 0 1 0\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["NO"]}, {"input": "0 0 0 1\r\n0 0 0 0\r\n1 0 0 0\r\n0 0 0 0\r\n", "output": ["NO"]}, {"input": "0 0 0 1\r\n0 0 0 0\r\n0 1 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 1\r\n0 0 0 0\r\n0 0 1 0\r\n0 0 0 0\r\n", "output": ["NO"]}, {"input": "0 0 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n1 0 0 0\r\n", "output": ["NO"]}, {"input": "0 0 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n0 1 0 0\r\n", "output": ["NO"]}, {"input": "0 0 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 1 0\r\n", "output": ["YES"]}, {"input": "1 0 0 0\r\n0 0 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["NO"]}, {"input": "0 1 0 0\r\n0 0 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["NO"]}, {"input": "0 0 1 0\r\n0 0 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n1 0 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n0 1 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n0 0 1 1\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n0 0 0 1\r\n1 0 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n0 0 0 1\r\n0 1 0 0\r\n0 0 0 0\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n0 0 0 1\r\n0 0 1 0\r\n0 0 0 0\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n0 0 0 1\r\n0 0 0 0\r\n1 0 0 0\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n0 0 0 1\r\n0 0 0 0\r\n0 1 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n0 0 0 1\r\n0 0 0 0\r\n0 0 1 0\r\n", "output": ["NO"]}, {"input": "1 0 0 0\r\n0 0 0 0\r\n0 0 0 1\r\n0 0 0 0\r\n", "output": ["NO"]}, {"input": "0 1 0 0\r\n0 0 0 0\r\n0 0 0 1\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 1 0\r\n0 0 0 0\r\n0 0 0 1\r\n0 0 0 0\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n1 0 0 0\r\n0 0 0 1\r\n0 0 0 0\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n0 1 0 0\r\n0 0 0 1\r\n0 0 0 0\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n0 0 1 0\r\n0 0 0 1\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n0 0 0 0\r\n1 0 0 1\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n0 0 0 0\r\n0 1 0 1\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n0 0 0 0\r\n0 0 1 1\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n0 0 0 0\r\n0 0 0 1\r\n1 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n0 0 0 0\r\n0 0 0 1\r\n0 1 0 0\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n0 0 0 0\r\n0 0 0 1\r\n0 0 1 0\r\n", "output": ["NO"]}, {"input": "1 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 1\r\n", "output": ["YES"]}, {"input": "0 1 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 1\r\n", "output": ["NO"]}, {"input": "0 0 1 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 1\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n1 0 0 0\r\n0 0 0 0\r\n0 0 0 1\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n0 1 0 0\r\n0 0 0 0\r\n0 0 0 1\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n0 0 1 0\r\n0 0 0 0\r\n0 0 0 1\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n0 0 0 0\r\n1 0 0 0\r\n0 0 0 1\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n0 0 0 0\r\n0 1 0 0\r\n0 0 0 1\r\n", "output": ["NO"]}, {"input": "0 0 0 0\r\n0 0 0 0\r\n0 0 1 0\r\n0 0 0 1\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n1 0 0 1\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 1 0 1\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 1 1\r\n", "output": ["YES"]}, {"input": "0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["NO"]}, {"input": "1 1 1 1\r\n1 1 1 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": ["YES"]}, {"input": "1 0 0 0\r\n0 1 0 0\r\n0 0 1 0\r\n0 0 0 1\r\n", "output": ["YES"]}, {"input": "1 1 1 1\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 1 1 0\r\n1 0 1 0\r\n1 1 1 0\r\n0 0 0 1\r\n", "output": ["YES"]}, {"input": "1 1 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "1 1 1 0\r\n1 1 1 0\r\n1 1 1 0\r\n0 0 0 1\r\n", "output": ["YES"]}, {"input": "0 0 0 1\r\n0 0 1 1\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 1\r\n0 1 1 1\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 1\r\n0 1 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 1\r\n0 0 0 1\r\n0 0 0 0\r\n0 1 0 0\r\n", "output": ["YES"]}, {"input": "0 0 0 1\r\n0 0 0 1\r\n1 0 0 0\r\n0 0 0 0\r\n", "output": ["YES"]}]
100
100
100
[{'input': '0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 1 0 1\r\n', 'output': ['YES']}, {'input': '0 0 0 1\r\n1 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n', 'output': ['YES']}, {'input': '0 0 1 0\r\n0 0 0 0\r\n1 1 0 0\r\n0 0 0 1\r\n', 'output': ['NO']}, {'input': '0 0 1 0\r\n0 0 0 0\r\n0 0 0 1\r\n0 0 0 1\r\n', 'output': ['NO']}, {'input': '1 1 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n', 'output': ['YES']}]
[{'input': '0 0 0 1\r\n0 1 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n', 'output': ['YES']}, {'input': '1 0 1 0\r\n1 1 0 0\r\n1 1 0 0\r\n0 0 0 0\r\n', 'output': ['NO']}, {'input': '0 0 0 0\r\n0 0 0 0\r\n0 0 0 1\r\n0 0 1 0\r\n', 'output': ['NO']}, {'input': '1 1 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n', 'output': ['YES']}, {'input': '0 1 0 0\r\n0 0 0 0\r\n0 0 0 1\r\n0 0 0 0\r\n', 'output': ['YES']}]
[{'input': '0 0 1 0\r\n0 0 0 0\r\n1 1 0 0\r\n0 0 0 1\r\n', 'output': ['NO']}, {'input': '0 1 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n', 'output': ['YES']}, {'input': '0 0 0 1\r\n0 1 1 1\r\n0 0 0 0\r\n0 0 0 0\r\n', 'output': ['YES']}, {'input': '0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 1 0 1\r\n', 'output': ['YES']}, {'input': '1 1 1 0\r\n1 1 1 0\r\n1 1 1 0\r\n0 0 0 1\r\n', 'output': ['YES']}]
[{'input': '0 0 0 0\r\n0 0 0 0\r\n0 0 1 1\r\n0 0 0 0\r\n', 'output': ['YES']}, {'input': '0 1 0 0\r\n0 0 0 1\r\n0 0 0 0\r\n0 0 0 0\r\n', 'output': ['NO']}, {'input': '1 1 1 0\r\n0 1 0 1\r\n1 1 1 0\r\n1 1 1 1\r\n', 'output': ['YES']}, {'input': '0 1 0 0\r\n1 1 0 1\r\n1 0 0 1\r\n1 1 0 1\r\n', 'output': ['YES']}, {'input': '1 1 0 0\r\n0 1 0 1\r\n1 1 1 0\r\n0 0 1 1\r\n', 'output': ['YES']}]
[{'input': '1 1 0 0\r\n0 1 0 1\r\n1 1 1 0\r\n0 0 1 1\r\n', 'output': ['YES']}, {'input': '0 0 0 0\r\n0 0 1 0\r\n0 0 0 1\r\n0 0 0 0\r\n', 'output': ['YES']}, {'input': '0 0 0 1\r\n0 1 1 1\r\n0 0 0 0\r\n0 0 0 0\r\n', 'output': ['YES']}, {'input': '0 0 0 0\r\n0 1 0 1\r\n1 0 1 1\r\n0 0 0 1\r\n', 'output': ['YES']}, {'input': '0 1 0 0\r\n0 0 0 1\r\n0 1 0 0\r\n0 0 0 1\r\n', 'output': ['NO']}]
100
100
100
100
100
88.24
94.12
94.12
88.24
88.24
48.39
46.77
46.77
37.1
59.68
249
100
90.592
47.742
["3\n2 1 3", "3\n1 2 3"]
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$) β€” the number of figures. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 3$$$, $$$a_i \ne a_{i + 1}$$$) β€” types of the figures.
6c8f028f655cc77b05ed89a668273702
import java.util.Scanner; public class InscribedFigures { public static void main(String[] args) { Scanner sc=new Scanner (System.in); int n=sc.nextInt(); int A[]=new int[n]; for (int x=0;x<n;x++) A[x]=sc.nextInt(); int s=0; int d=0; for (int x=0;x<n-1;x++) { if (A[x]+A[x+1]==5) { s=-1; break; } else if(A[x]+A[x+1]==3) s=s+3; else s=s+4; } for (int x=0;x<n-2;x++) if (A[x]==3&&A[x+1]==1&&A[x+2]==2) d=d+1; if (s==-1) System.out.println("Infinite"); else { System.out.println("Finite"); System.out.println(s-d); } } }
["Finite\n7", "Infinite"]
Java
NoteHere are the glorious pictures for the examples. Note that the triangle is not equilateral but just isosceles with the length of height equal to the length of base. Thus it fits into a square in a unique way.The distinct points where figures touch are marked red.In the second example the triangle and the square touch each other for the whole segment, it contains infinite number of points.
The first line should contain either the word "Infinite" if the number of distinct points where figures touch is infinite or "Finite" otherwise. If the number is finite than print it in the second line. It's guaranteed that the number fits into 32-bit integer type.
The math faculty of Berland State University has suffered the sudden drop in the math skills of enrolling students. This year the highest grade on the entrance math test was 8. Out of 100! Thus, the decision was made to make the test easier.Future students will be asked just a single question. They are given a sequence of integer numbers $$$a_1, a_2, \dots, a_n$$$, each number is from $$$1$$$ to $$$3$$$ and $$$a_i \ne a_{i + 1}$$$ for each valid $$$i$$$. The $$$i$$$-th number represents a type of the $$$i$$$-th figure: circle; isosceles triangle with the length of height equal to the length of base; square. The figures of the given sequence are placed somewhere on a Cartesian plane in such a way that: $$$(i + 1)$$$-th figure is inscribed into the $$$i$$$-th one; each triangle base is parallel to OX; the triangle is oriented in such a way that the vertex opposite to its base is at the top; each square sides are parallel to the axes; for each $$$i$$$ from $$$2$$$ to $$$n$$$ figure $$$i$$$ has the maximum possible length of side for triangle and square and maximum radius for circle. Note that the construction is unique for some fixed position and size of just the first figure.The task is to calculate the number of distinct points (not necessarily with integer coordinates) where figures touch. The trick is, however, that the number is sometimes infinite. But that won't make the task difficult for you, will it?So can you pass the math test and enroll into Berland State University?
[{"input": "3\r\n2 1 3\r\n", "output": ["Finite\r\n7", "Finite\n7"]}, {"input": "3\r\n1 2 3\r\n", "output": ["Infinite"]}, {"input": "99\r\n3 1 3 1 3 1 2 1 3 1 3 1 2 1 3 1 3 1 3 1 3 1 2 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1 3 1 3 1 3 1 3 1 2 1 2 1 3 1 3 1 2 1 2 1 2 1 3 1 3 1 3 1 2 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1 3 1 3 1 2 1 3 1 3 1 3 1 3 1 2 1 2\r\n", "output": ["Finite\r\n341", "Finite\n341"]}, {"input": "100\r\n3 1 3 1 2 1 2 3 1 2 3 2 3 2 3 2 3 1 2 1 2 3 1 2 3 2 1 2 1 3 2 3 1 2 3 1 2 3 1 3 2 1 2 1 3 2 1 2 1 3 1 3 2 1 2 1 2 1 2 3 2 1 2 1 2 3 2 3 2 1 3 2 1 2 1 2 1 3 1 3 1 2 1 2 3 2 1 2 3 2 3 1 3 2 3 1 2 3 2 3\r\n", "output": ["Infinite"]}, {"input": "100\r\n1 2 1 2 1 2 1 2 1 3 1 3 1 2 1 3 1 2 1 3 1 2 1 3 1 2 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1 2 1 3 1 2 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 2 1 3 1 3 1 3 1 2 1 2 1 2 1 2 1 2 1 2 1 3 1 3 1 2 1 2 1 2 1 3 1 2 1 3 1 2 1 2\r\n", "output": ["Finite\r\n331", "Finite\n331"]}, {"input": "100\r\n1 3 2 3 2 1 3 2 3 1 2 1 3 1 2 1 3 1 2 1 3 2 3 2 1 2 1 3 2 1 3 2 3 1 3 1 3 1 3 1 3 2 3 2 3 2 3 1 2 1 2 3 1 3 2 3 2 3 2 3 2 3 2 1 3 1 2 3 1 2 3 2 1 2 3 1 2 1 3 2 1 2 1 2 1 3 1 2 1 2 1 2 3 1 2 1 3 1 3 1\r\n", "output": ["Infinite"]}, {"input": "99\r\n1 2 1 2 1 2 1 3 1 2 1 3 1 3 1 2 1 3 1 3 1 2 1 2 1 2 1 3 1 3 1 3 1 3 1 3 1 3 1 2 1 3 1 2 1 3 1 3 1 2 1 2 1 3 1 2 1 2 1 2 1 3 1 2 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1 2 1 3 1 2 1 3 1 2 1 3 1 3 1 3 1 2 1 3 1\r\n", "output": ["Finite\r\n331", "Finite\n331"]}, {"input": "100\r\n2 1 3 1 3 1 3 1 2 1 2 1 3 1 2 1 3 1 2 1 3 1 2 1 3 1 3 1 3 1 2 1 2 1 2 1 3 1 3 1 2 1 2 1 2 1 2 1 2 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1 2 1 2 1 3 1 2 1 2 1 3 1 2 1 3 1 3 1 3 1 2 1 2 1 3 1 2 1 2 1 2 1 3 1 3 1\r\n", "output": ["Finite\r\n329", "Finite\n329"]}, {"input": "2\r\n3 2\r\n", "output": ["Infinite"]}, {"input": "3\r\n3 1 2\r\n", "output": ["Finite\n6", "Finite\r\n6"]}, {"input": "11\r\n3 1 2 1 3 1 2 1 3 1 2\r\n", "output": ["Finite\r\n32", "Finite\n32"]}, {"input": "2\r\n3 1\r\n", "output": ["Finite\r\n4", "Finite\n4"]}, {"input": "4\r\n1 3 1 2\r\n", "output": ["Finite\r\n10", "Finite\n10"]}, {"input": "4\r\n3 1 2 3\r\n", "output": ["Infinite"]}, {"input": "8\r\n3 1 2 1 3 1 2 1\r\n", "output": ["Finite\n22", "Finite\r\n22"]}, {"input": "8\r\n3 1 2 1 3 1 3 1\r\n", "output": ["Finite\r\n25", "Finite\n25"]}, {"input": "2\r\n1 2\r\n", "output": ["Finite\r\n3", "Finite\n3"]}, {"input": "4\r\n3 1 2 1\r\n", "output": ["Finite\r\n9", "Finite\n9"]}, {"input": "16\r\n3 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1\r\n", "output": ["Finite\n49", "Finite\r\n49"]}, {"input": "5\r\n3 1 2 1 2\r\n", "output": ["Finite\r\n12", "Finite\n12"]}, {"input": "4\r\n2 3 1 2\r\n", "output": ["Infinite"]}, {"input": "3\r\n1 3 2\r\n", "output": ["Infinite"]}, {"input": "4\r\n3 1 3 2\r\n", "output": ["Infinite"]}, {"input": "2\r\n2 3\r\n", "output": ["Infinite"]}, {"input": "3\r\n2 3 1\r\n", "output": ["Infinite"]}, {"input": "2\r\n2 1\r\n", "output": ["Finite\r\n3", "Finite\n3"]}, {"input": "3\r\n1 2 1\r\n", "output": ["Finite\n6", "Finite\r\n6"]}, {"input": "5\r\n2 1 3 1 2\r\n", "output": ["Finite\r\n13", "Finite\n13"]}, {"input": "15\r\n2 1 2 1 2 1 2 1 2 1 2 1 2 1 2\r\n", "output": ["Finite\n42", "Finite\r\n42"]}, {"input": "15\r\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1\r\n", "output": ["Finite\n42", "Finite\r\n42"]}]
100
100
100
[{'input': '4\r\n3 1 2 1\r\n', 'output': ['Finite\r\n9', 'Finite\n9']}, {'input': '4\r\n2 3 1 2\r\n', 'output': ['Infinite']}, {'input': '3\r\n2 1 3\r\n', 'output': ['Finite\r\n7', 'Finite\n7']}, {'input': '2\r\n2 3\r\n', 'output': ['Infinite']}, {'input': '100\r\n2 1 3 1 3 1 3 1 2 1 2 1 3 1 2 1 3 1 2 1 3 1 2 1 3 1 3 1 3 1 2 1 2 1 2 1 3 1 3 1 2 1 2 1 2 1 2 1 2 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1 2 1 2 1 3 1 2 1 2 1 3 1 2 1 3 1 3 1 3 1 2 1 2 1 3 1 2 1 2 1 2 1 3 1 3 1\r\n', 'output': ['Finite\r\n329', 'Finite\n329']}]
[{'input': '4\r\n3 1 2 1\r\n', 'output': ['Finite\r\n9', 'Finite\n9']}, {'input': '4\r\n1 3 1 2\r\n', 'output': ['Finite\r\n10', 'Finite\n10']}, {'input': '4\r\n3 1 2 3\r\n', 'output': ['Infinite']}, {'input': '5\r\n2 1 3 1 2\r\n', 'output': ['Finite\r\n13', 'Finite\n13']}, {'input': '3\r\n2 1 3\r\n', 'output': ['Finite\r\n7', 'Finite\n7']}]
[{'input': '15\r\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1\r\n', 'output': ['Finite\n42', 'Finite\r\n42']}, {'input': '4\r\n2 3 1 2\r\n', 'output': ['Infinite']}, {'input': '4\r\n3 1 3 2\r\n', 'output': ['Infinite']}, {'input': '2\r\n3 2\r\n', 'output': ['Infinite']}, {'input': '4\r\n3 1 2 3\r\n', 'output': ['Infinite']}]
[{'input': '11\r\n3 1 2 1 3 1 2 1 3 1 2\r\n', 'output': ['Finite\r\n32', 'Finite\n32']}, {'input': '3\r\n1 3 2\r\n', 'output': ['Infinite']}, {'input': '2\r\n3 1\r\n', 'output': ['Finite\r\n4', 'Finite\n4']}, {'input': '99\r\n1 2 1 2 1 2 1 3 1 2 1 3 1 3 1 2 1 3 1 3 1 2 1 2 1 2 1 3 1 3 1 3 1 3 1 3 1 3 1 2 1 3 1 2 1 3 1 3 1 2 1 2 1 3 1 2 1 2 1 2 1 3 1 2 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1 2 1 3 1 2 1 3 1 2 1 3 1 3 1 3 1 2 1 3 1\r\n', 'output': ['Finite\r\n331', 'Finite\n331']}, {'input': '3\r\n2 1 3\r\n', 'output': ['Finite\r\n7', 'Finite\n7']}]
[{'input': '2\r\n3 1\r\n', 'output': ['Finite\r\n4', 'Finite\n4']}, {'input': '11\r\n3 1 2 1 3 1 2 1 3 1 2\r\n', 'output': ['Finite\r\n32', 'Finite\n32']}, {'input': '4\r\n3 1 2 3\r\n', 'output': ['Infinite']}, {'input': '4\r\n1 3 1 2\r\n', 'output': ['Finite\r\n10', 'Finite\n10']}, {'input': '2\r\n2 1\r\n', 'output': ['Finite\r\n3', 'Finite\n3']}]
100
100
100
100
100
100
100
100
100
100
94.44
88.89
94.44
94.44
88.89
250
100
100
92.22
["1 2 1000", "2 2 1000", "5 3 1103"]
Input consists of three integers n, k, m (1 ≀ n ≀ 1000, 1 ≀ k ≀ 100, 1 ≀ m ≀ 109).
656bf8df1e79499aa2ab2c28712851f0
import java.util.Arrays; import java.util.Scanner; import java.util.function.Function; public class CF287D { public static long modPower(long base, long exponent, long mod) { long result = 1; while (exponent > 0) { if ((exponent & 1) != 0) result = (result * base) % mod; base = (base * base) % mod; exponent >>= 1; } return result; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); long m = in.nextLong(); long[] dp = new long[k]; dp[0] = 1; long total = 0; for (int i = 0; i < n; i++) { long[] next = new long[k]; for (int j = 0; j < k; j++) for (int d = (i == n - 1) ? 1 : 0; d < 10; d++) { int res = (int) (modPower(10, i, k) * d + j) % k; next[res] = (next[res] + dp[j]) % m; } if (i < n - 1) total += (next[0] + m - 1) * 9 % m * modPower(10, n - 2 - i, m) % m; else total += next[0]; total %= m; dp = next; dp[0] = 1; } System.out.println(total); } }
["4", "45", "590"]
Java
NoteA suffix of a string S is a non-empty string that can be obtained by removing some number (possibly, zero) of first characters from S.
Print the required number modulo m.
Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher suspected that Amr is sleeping and asked him a question to make sure he wasn't.First he gave Amr two positive integers n and k. Then he asked Amr, how many integer numbers x &gt; 0 exist such that: Decimal representation of x (without leading zeroes) consists of exactly n digits; There exists some integer y &gt; 0 such that: ; decimal representation of y is a suffix of decimal representation of x. As the answer to this question may be pretty huge the teacher asked Amr to output only its remainder modulo a number m.Can you help Amr escape this embarrassing situation?
[{"input": "1 2 1000\r\n", "output": ["4"]}, {"input": "2 2 1000\r\n", "output": ["45"]}, {"input": "5 3 1103\r\n", "output": ["590"]}, {"input": "2 17 10000\r\n", "output": ["5"]}, {"input": "3 9 10000\r\n", "output": ["252"]}, {"input": "6 64 941761822\r\n", "output": ["46530"]}, {"input": "183 3 46847167\r\n", "output": ["29891566"]}, {"input": "472 44 364550669\r\n", "output": ["122479316"]}, {"input": "510 76 811693420\r\n", "output": ["546301720"]}, {"input": "783 30 602209107\r\n", "output": ["279682329"]}, {"input": "863 47 840397713\r\n", "output": ["433465398"]}, {"input": "422 22 411212542\r\n", "output": ["63862621"]}, {"input": "370 9 385481464\r\n", "output": ["163845824"]}, {"input": "312 41 915197716\r\n", "output": ["912219984"]}, {"input": "261 32 49719977\r\n", "output": ["19320923"]}, {"input": "434 6 56571287\r\n", "output": ["56257936"]}, {"input": "355 3 945669623\r\n", "output": ["219132384"]}, {"input": "905 71 999142682\r\n", "output": ["825882209"]}, {"input": "900 84 526417573\r\n", "output": ["281234824"]}, {"input": "387 3 521021345\r\n", "output": ["435545521"]}, {"input": "246 33 996704992\r\n", "output": ["385601286"]}, {"input": "443 29 106807555\r\n", "output": ["7872021"]}, {"input": "621 43 356382217\r\n", "output": ["251594310"]}, {"input": "782 84 643445347\r\n", "output": ["208138038"]}, {"input": "791 23 94030462\r\n", "output": ["41862326"]}, {"input": "543 98 508536403\r\n", "output": ["117587951"]}, {"input": "20 96 238661639\r\n", "output": ["198761428"]}, {"input": "845 60 888437864\r\n", "output": ["193926448"]}, {"input": "998 85 501663165\r\n", "output": ["145180249"]}, {"input": "123 72 56222855\r\n", "output": ["32350599"]}, {"input": "12 39 618421525\r\n", "output": ["115875938"]}, {"input": "462 35 144751085\r\n", "output": ["79931198"]}, {"input": "674 22 494819681\r\n", "output": ["19590614"]}, {"input": "650 66 579060528\r\n", "output": ["224930740"]}, {"input": "432 80 133016247\r\n", "output": ["25032672"]}, {"input": "176 70 196445230\r\n", "output": ["64904804"]}, {"input": "393 71 933802677\r\n", "output": ["366541352"]}, {"input": "37 92 9838905\r\n", "output": ["7980021"]}, {"input": "993 26 108974437\r\n", "output": ["87469631"]}, {"input": "433 93 36915724\r\n", "output": ["20722839"]}, {"input": "957 88 512982771\r\n", "output": ["161742313"]}, {"input": "170 94 82742818\r\n", "output": ["1117330"]}, {"input": "624 33 145653575\r\n", "output": ["99048377"]}, {"input": "56 48 961996131\r\n", "output": ["199203510"]}, {"input": "889 6 225765429\r\n", "output": ["193135878"]}, {"input": "1 93 727895661\r\n", "output": ["0"]}, {"input": "470 61 617307737\r\n", "output": ["428782123"]}, {"input": "520 94 712232167\r\n", "output": ["199435818"]}, {"input": "531 78 460047919\r\n", "output": ["117748792"]}, {"input": "776 32 523607700\r\n", "output": ["309970800"]}, {"input": "648 74 329538445\r\n", "output": ["177655063"]}, {"input": "885 6 743810885\r\n", "output": ["297512873"]}, {"input": "712 53 592302770\r\n", "output": ["147693148"]}, {"input": "426 72 589297447\r\n", "output": ["316207784"]}, {"input": "561 69 310141994\r\n", "output": ["245538618"]}, {"input": "604 97 26180786\r\n", "output": ["6950800"]}, {"input": "586 32 846994504\r\n", "output": ["579729448"]}, {"input": "514 67 260591607\r\n", "output": ["88291586"]}, {"input": "429 45 103817253\r\n", "output": ["41335161"]}, {"input": "767 27 364988776\r\n", "output": ["259490746"]}, {"input": "497 33 479662107\r\n", "output": ["84548778"]}, {"input": "262 71 404639692\r\n", "output": ["93447345"]}, {"input": "125 33 152527721\r\n", "output": ["59122415"]}, {"input": "857 98 70814341\r\n", "output": ["58423075"]}, {"input": "375 79 416634034\r\n", "output": ["175150318"]}, {"input": "886 10 902171654\r\n", "output": ["134375492"]}, {"input": "335 28 979397289\r\n", "output": ["675105408"]}, {"input": "769 30 474381420\r\n", "output": ["157049322"]}, {"input": "736 31 26855044\r\n", "output": ["24225276"]}, {"input": "891 7 814335325\r\n", "output": ["611862019"]}, {"input": "346 23 947672082\r\n", "output": ["59151110"]}, {"input": "1000 1 382210711\r\n", "output": ["372462157"]}, {"input": "1 1 10000\r\n", "output": ["9"]}, {"input": "1000 100 777767777\r\n", "output": ["577920877"]}, {"input": "1000 13 10619863\r\n", "output": ["8796170"]}, {"input": "1 100 1000\r\n", "output": ["0"]}, {"input": "11 11 11\r\n", "output": ["7"]}, {"input": "1 1 1\r\n", "output": ["0"]}, {"input": "1 2 2\r\n", "output": ["0"]}]
100
100
100
[{'input': '12 39 618421525\r\n', 'output': ['115875938']}, {'input': '791 23 94030462\r\n', 'output': ['41862326']}, {'input': '561 69 310141994\r\n', 'output': ['245538618']}, {'input': '262 71 404639692\r\n', 'output': ['93447345']}, {'input': '261 32 49719977\r\n', 'output': ['19320923']}]
[{'input': '510 76 811693420\r\n', 'output': ['546301720']}, {'input': '1 2 1000\r\n', 'output': ['4']}, {'input': '621 43 356382217\r\n', 'output': ['251594310']}, {'input': '472 44 364550669\r\n', 'output': ['122479316']}, {'input': '434 6 56571287\r\n', 'output': ['56257936']}]
[{'input': '472 44 364550669\r\n', 'output': ['122479316']}, {'input': '312 41 915197716\r\n', 'output': ['912219984']}, {'input': '183 3 46847167\r\n', 'output': ['29891566']}, {'input': '1 2 2\r\n', 'output': ['0']}, {'input': '604 97 26180786\r\n', 'output': ['6950800']}]
[{'input': '176 70 196445230\r\n', 'output': ['64904804']}, {'input': '863 47 840397713\r\n', 'output': ['433465398']}, {'input': '1000 1 382210711\r\n', 'output': ['372462157']}, {'input': '510 76 811693420\r\n', 'output': ['546301720']}, {'input': '393 71 933802677\r\n', 'output': ['366541352']}]
[{'input': '674 22 494819681\r\n', 'output': ['19590614']}, {'input': '1000 13 10619863\r\n', 'output': ['8796170']}, {'input': '170 94 82742818\r\n', 'output': ['1117330']}, {'input': '543 98 508536403\r\n', 'output': ['117587951']}, {'input': '346 23 947672082\r\n', 'output': ['59151110']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
251
100
100
100
["8 5\n10 9 8 7 7 7 5 5", "4 2\n0 0 0 0"]
The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 50) separated by a single space. The second line contains n space-separated integers a1, a2, ..., an (0 ≀ ai ≀ 100), where ai is the score earned by the participant who got the i-th place. The given sequence is non-increasing (that is, for all i from 1 to n - 1 the following condition is fulfilled: ai β‰₯ ai + 1).
193ec1226ffe07522caf63e84a7d007f
import java.util.Scanner; public class NextRound2 { public static void main(String[] args){ Scanner scan = new Scanner(System.in); int n,k,score=-1,count=0; n = scan.nextInt(); k = scan.nextInt(); int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = scan.nextInt(); } scan.close(); if(a[0]==0){ k=0; }else{ //6 2 //3 0 0 0 0 0 while(a[k-1]==0)k--; //non-incresing, next number from (k-1) must be the same (k). while(k<n && a[k-1]==a[k])k++; } System.out.println(k); } }
["6", "0"]
Java
NoteIn the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.In the second example nobody got a positive score.
Output the number of participants who advance to the next round.
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." β€” an excerpt from contest rules.A total of n participants took part in the contest (n β‰₯ k), and you already know their scores. Calculate how many participants will advance to the next round.
[{"input": "8 5\r\n10 9 8 7 7 7 5 5\r\n", "output": ["6"]}, {"input": "4 2\r\n0 0 0 0\r\n", "output": ["0"]}, {"input": "5 1\r\n1 1 1 1 1\r\n", "output": ["5"]}, {"input": "5 5\r\n1 1 1 1 1\r\n", "output": ["5"]}, {"input": "1 1\r\n10\r\n", "output": ["1"]}, {"input": "17 14\r\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0\r\n", "output": ["14"]}, {"input": "5 5\r\n3 2 1 0 0\r\n", "output": ["3"]}, {"input": "8 6\r\n10 9 8 7 7 7 5 5\r\n", "output": ["6"]}, {"input": "8 7\r\n10 9 8 7 7 7 5 5\r\n", "output": ["8"]}, {"input": "8 4\r\n10 9 8 7 7 7 5 5\r\n", "output": ["6"]}, {"input": "8 3\r\n10 9 8 7 7 7 5 5\r\n", "output": ["3"]}, {"input": "8 1\r\n10 9 8 7 7 7 5 5\r\n", "output": ["1"]}, {"input": "8 2\r\n10 9 8 7 7 7 5 5\r\n", "output": ["2"]}, {"input": "1 1\r\n100\r\n", "output": ["1"]}, {"input": "1 1\r\n0\r\n", "output": ["0"]}, {"input": "50 25\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["50"]}, {"input": "50 25\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["25"]}, {"input": "50 25\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["26"]}, {"input": "50 25\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["50"]}, {"input": "11 5\r\n100 99 98 97 96 95 94 93 92 91 90\r\n", "output": ["5"]}, {"input": "10 4\r\n100 81 70 69 64 43 34 29 15 3\r\n", "output": ["4"]}, {"input": "11 6\r\n87 71 62 52 46 46 43 35 32 25 12\r\n", "output": ["6"]}, {"input": "17 12\r\n99 88 86 82 75 75 74 65 58 52 45 30 21 16 7 2 2\r\n", "output": ["12"]}, {"input": "20 3\r\n98 98 96 89 87 82 82 80 76 74 74 68 61 60 43 32 30 22 4 2\r\n", "output": ["3"]}, {"input": "36 12\r\n90 87 86 85 83 80 79 78 76 70 69 69 61 61 59 58 56 48 45 44 42 41 33 31 27 25 23 21 20 19 15 14 12 7 5 5\r\n", "output": ["12"]}, {"input": "49 8\r\n99 98 98 96 92 92 90 89 89 86 86 85 83 80 79 76 74 69 67 67 58 56 55 51 49 47 47 46 45 41 41 40 39 34 34 33 25 23 18 15 13 13 11 9 5 4 3 3 1\r\n", "output": ["9"]}, {"input": "49 29\r\n100 98 98 96 96 96 95 87 85 84 81 76 74 70 63 63 63 62 57 57 56 54 53 52 50 47 45 41 41 39 38 31 30 28 27 26 23 22 20 15 15 11 7 6 6 4 2 1 0\r\n", "output": ["29"]}, {"input": "49 34\r\n99 98 96 96 93 92 90 89 88 86 85 85 82 76 73 69 66 64 63 63 60 59 57 57 56 55 54 54 51 48 47 44 42 42 40 39 38 36 33 26 24 23 19 17 17 14 12 7 4\r\n", "output": ["34"]}, {"input": "50 44\r\n100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4\r\n", "output": ["44"]}, {"input": "50 13\r\n99 95 94 94 88 87 81 79 78 76 74 72 72 69 68 67 67 67 66 63 62 61 58 57 55 55 54 51 50 50 48 48 42 41 38 35 34 32 31 30 26 24 13 13 12 6 5 4 3 3\r\n", "output": ["13"]}, {"input": "50 30\r\n100 98 96 94 91 89 88 81 81 81 81 81 76 73 72 71 70 69 66 64 61 59 59 56 52 50 49 48 43 39 36 35 34 34 31 29 27 26 24 22 16 16 15 14 14 14 9 7 4 3\r\n", "output": ["30"]}, {"input": "2 1\r\n10 10\r\n", "output": ["2"]}, {"input": "2 2\r\n10 10\r\n", "output": ["2"]}, {"input": "2 2\r\n10 0\r\n", "output": ["1"]}, {"input": "2 2\r\n10 1\r\n", "output": ["2"]}, {"input": "2 1\r\n10 0\r\n", "output": ["1"]}, {"input": "2 1\r\n10 2\r\n", "output": ["1"]}, {"input": "50 13\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n", "output": ["0"]}, {"input": "50 1\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n", "output": ["0"]}, {"input": "50 50\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n", "output": ["0"]}, {"input": "10 1\r\n5 5 5 3 3 3 0 0 0 0\r\n", "output": ["3"]}, {"input": "10 2\r\n5 5 5 3 3 3 0 0 0 0\r\n", "output": ["3"]}, {"input": "10 3\r\n5 5 5 3 3 3 0 0 0 0\r\n", "output": ["3"]}, {"input": "10 4\r\n5 5 5 3 3 3 0 0 0 0\r\n", "output": ["6"]}, {"input": "10 5\r\n5 5 5 3 3 3 0 0 0 0\r\n", "output": ["6"]}, {"input": "10 6\r\n5 5 5 3 3 3 0 0 0 0\r\n", "output": ["6"]}, {"input": "10 7\r\n5 5 5 3 3 3 0 0 0 0\r\n", "output": ["6"]}, {"input": "10 8\r\n5 5 5 3 3 3 0 0 0 0\r\n", "output": ["6"]}, {"input": "10 9\r\n5 5 5 3 3 3 0 0 0 0\r\n", "output": ["6"]}, {"input": "10 10\r\n5 5 5 3 3 3 0 0 0 0\r\n", "output": ["6"]}]
100
100
100
[{'input': '8 3\r\n10 9 8 7 7 7 5 5\r\n', 'output': ['3']}, {'input': '50 25\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n', 'output': ['26']}, {'input': '17 14\r\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0\r\n', 'output': ['14']}, {'input': '2 2\r\n10 10\r\n', 'output': ['2']}, {'input': '50 13\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n', 'output': ['0']}]
[{'input': '5 5\r\n3 2 1 0 0\r\n', 'output': ['3']}, {'input': '50 44\r\n100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4\r\n', 'output': ['44']}, {'input': '50 50\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n', 'output': ['0']}, {'input': '8 5\r\n10 9 8 7 7 7 5 5\r\n', 'output': ['6']}, {'input': '8 6\r\n10 9 8 7 7 7 5 5\r\n', 'output': ['6']}]
[{'input': '8 3\r\n10 9 8 7 7 7 5 5\r\n', 'output': ['3']}, {'input': '8 1\r\n10 9 8 7 7 7 5 5\r\n', 'output': ['1']}, {'input': '8 7\r\n10 9 8 7 7 7 5 5\r\n', 'output': ['8']}, {'input': '4 2\r\n0 0 0 0\r\n', 'output': ['0']}, {'input': '8 5\r\n10 9 8 7 7 7 5 5\r\n', 'output': ['6']}]
[{'input': '1 1\r\n10\r\n', 'output': ['1']}, {'input': '36 12\r\n90 87 86 85 83 80 79 78 76 70 69 69 61 61 59 58 56 48 45 44 42 41 33 31 27 25 23 21 20 19 15 14 12 7 5 5\r\n', 'output': ['12']}, {'input': '17 12\r\n99 88 86 82 75 75 74 65 58 52 45 30 21 16 7 2 2\r\n', 'output': ['12']}, {'input': '2 1\r\n10 0\r\n', 'output': ['1']}, {'input': '4 2\r\n0 0 0 0\r\n', 'output': ['0']}]
[{'input': '50 44\r\n100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4\r\n', 'output': ['44']}, {'input': '10 3\r\n5 5 5 3 3 3 0 0 0 0\r\n', 'output': ['3']}, {'input': '11 6\r\n87 71 62 52 46 46 43 35 32 25 12\r\n', 'output': ['6']}, {'input': '8 3\r\n10 9 8 7 7 7 5 5\r\n', 'output': ['3']}, {'input': '50 13\r\n99 95 94 94 88 87 81 79 78 76 74 72 72 69 68 67 67 67 66 63 62 61 58 57 55 55 54 51 50 50 48 48 42 41 38 35 34 32 31 30 26 24 13 13 12 6 5 4 3 3\r\n', 'output': ['13']}]
100
100
100
100
100
100
100
100
100
92.86
90
90
90
80
60
252
100
98.572
82
["1 10 7", "4 0 9"]
The first line contains three integers a, b, mod (0 ≀ a, b ≀ 109, 1 ≀ mod ≀ 107).
8b6f633802293202531264446d33fee5
import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; public class Game { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String[] input = bf.readLine().split(" "); String answer = ""; long a, b, mod, ans; boolean oneWin = false; a = Integer.parseInt(input[0]); b = Integer.parseInt(input[1]); mod = Integer.parseInt(input[2]); long limit = Math.min(a, mod); long res = 0; for (ans = 1; ans <= limit; ans++) { res = (((ans % mod) * (1000000000 % mod)) % mod); if ((mod - res)% mod > b) { oneWin = true; break; } } if (oneWin) { String temp = String.valueOf(ans); int digits = temp.length(); for (int i = 0;i < 9 - digits; i++) { answer += "0"; } answer += String.valueOf(ans); System.out.println("1 " + answer); } else { System.out.println(2); } } }
["2", "1 000000001"]
Java
NoteThe lexical comparison of strings is performed by the &lt; operator in modern programming languages. String x is lexicographically less than string y if exists such i (1 ≀ i ≀ 9), that xi &lt; yi, and for any j (1 ≀ j &lt; i) xj = yj. These strings always have length 9.
If the first player wins, print "1" and the lexicographically minimum string s1 he has to write to win. If the second player wins, print the single number "2".
In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string s1, consisting of exactly nine digits and representing a number that does not exceed a. After that second player looks at s1 and writes a string s2, consisting of exactly nine digits and representing a number that does not exceed b. Here a and b are some given constants, s1 and s2 are chosen by the players. The strings are allowed to contain leading zeroes.If a number obtained by the concatenation (joining together) of strings s1 and s2 is divisible by mod, then the second player wins. Otherwise the first player wins. You are given numbers a, b, mod. Your task is to determine who wins if both players play in the optimal manner. If the first player wins, you are also required to find the lexicographically minimum winning move.
[{"input": "1 10 7\r\n", "output": ["2"]}, {"input": "4 0 9\r\n", "output": ["1 000000001"]}, {"input": "10 7 8\r\n", "output": ["2"]}, {"input": "6 4 10\r\n", "output": ["2"]}, {"input": "4 1 4\r\n", "output": ["2"]}, {"input": "4 7 9\r\n", "output": ["1 000000001"]}, {"input": "13 4 51\r\n", "output": ["1 000000001"]}, {"input": "0 0 1\r\n", "output": ["2"]}, {"input": "1 0 1\r\n", "output": ["2"]}, {"input": "2 1 3\r\n", "output": ["1 000000001"]}, {"input": "0 2 2\r\n", "output": ["2"]}, {"input": "2 3 1\r\n", "output": ["2"]}, {"input": "3 0 3\r\n", "output": ["1 000000001"]}, {"input": "1 1 2\r\n", "output": ["2"]}, {"input": "3 2 1\r\n", "output": ["2"]}, {"input": "0 3 3\r\n", "output": ["2"]}, {"input": "4 0 13\r\n", "output": ["1 000000001"]}, {"input": "1 2 13\r\n", "output": ["2"]}, {"input": "4 3 12\r\n", "output": ["1 000000001"]}, {"input": "1 2 11\r\n", "output": ["2"]}, {"input": "815 216 182\r\n", "output": ["2"]}, {"input": "218 550 593\r\n", "output": ["1 000000011"]}, {"input": "116482865 344094604 3271060\r\n", "output": ["2"]}, {"input": "19749161 751031022 646204\r\n", "output": ["2"]}, {"input": "70499104 10483793 5504995\r\n", "output": ["2"]}, {"input": "1960930 562910 606828\r\n", "output": ["1 000000011"]}, {"input": "8270979 4785512 9669629\r\n", "output": ["1 000000001"]}, {"input": "9323791 4748006 5840080\r\n", "output": ["1 000000005"]}, {"input": "972037745 4602117 5090186\r\n", "output": ["1 000000011"]}, {"input": "585173560 4799128 5611727\r\n", "output": ["1 000000036"]}, {"input": "22033548 813958 4874712\r\n", "output": ["1 000000001"]}, {"input": "702034015 6007275 9777625\r\n", "output": ["1 000000001"]}, {"input": "218556 828183 7799410\r\n", "output": ["1 000000001"]}, {"input": "1167900 2709798 6800151\r\n", "output": ["1 000000001"]}, {"input": "7004769 3114686 4659684\r\n", "output": ["1 000000002"]}, {"input": "1000000000 1000000000 10000000\r\n", "output": ["2"]}, {"input": "3631 1628 367377\r\n", "output": ["1 000000009"]}, {"input": "3966 5002 273075\r\n", "output": ["1 000000008"]}, {"input": "2388 2896 73888\r\n", "output": ["1 000000016"]}, {"input": "0 1 1\r\n", "output": ["2"]}, {"input": "1 1 1\r\n", "output": ["2"]}, {"input": "1000000000 0 1\r\n", "output": ["2"]}, {"input": "0 1000000000 1\r\n", "output": ["2"]}, {"input": "1000000000 1000000000 1\r\n", "output": ["2"]}, {"input": "1000000000 0 10000000\r\n", "output": ["2"]}, {"input": "0 1000000000 10000000\r\n", "output": ["2"]}, {"input": "0 0 10000000\r\n", "output": ["2"]}, {"input": "0 999999999 10000000\r\n", "output": ["2"]}, {"input": "999999999 0 10000000\r\n", "output": ["2"]}, {"input": "999999999 999999999 10000000\r\n", "output": ["2"]}, {"input": "999999999 1000000000 10000000\r\n", "output": ["2"]}, {"input": "1000000000 999999999 10000000\r\n", "output": ["2"]}, {"input": "1000000000 10000 10000000\r\n", "output": ["2"]}, {"input": "1 1 1337\r\n", "output": ["1 000000001"]}, {"input": "576694 1234562 1234567\r\n", "output": ["2"]}, {"input": "12350 12000 12345\r\n", "output": ["1 000000011"]}, {"input": "576695 1234562 1234567\r\n", "output": ["1 000576695"]}, {"input": "0 0 11\r\n", "output": ["2"]}, {"input": "999999999 999999999 9009009\r\n", "output": ["2"]}, {"input": "1 0 7\r\n", "output": ["1 000000001"]}, {"input": "1 1 7\r\n", "output": ["2"]}, {"input": "1000000000 9999991 10000000\r\n", "output": ["2"]}, {"input": "9902593 9902584 9902593\r\n", "output": ["1 002490619"]}, {"input": "10000000 9999977 9999979\r\n", "output": ["1 009909503"]}, {"input": "1000000000 1000000000 9999999\r\n", "output": ["2"]}, {"input": "11 9 11\r\n", "output": ["1 000000010"]}, {"input": "0 7 13\r\n", "output": ["2"]}, {"input": "1 0 3\r\n", "output": ["1 000000001"]}, {"input": "100 2 3\r\n", "output": ["2"]}, {"input": "2 7 13\r\n", "output": ["2"]}, {"input": "1 0 9\r\n", "output": ["1 000000001"]}, {"input": "1000000000 9999995 10000000\r\n", "output": ["2"]}, {"input": "1000000000 25 30\r\n", "output": ["2"]}, {"input": "243 1001 1003\r\n", "output": ["2"]}, {"input": "9 9 11\r\n", "output": ["2"]}, {"input": "0 1 11\r\n", "output": ["2"]}, {"input": "4 4 7\r\n", "output": ["2"]}, {"input": "1000000000 1 10\r\n", "output": ["2"]}, {"input": "1 0 11\r\n", "output": ["1 000000001"]}, {"input": "0 0 3\r\n", "output": ["2"]}, {"input": "10 12000 12345\r\n", "output": ["2"]}, {"input": "1000000000 0 2\r\n", "output": ["2"]}, {"input": "0 1 3\r\n", "output": ["2"]}, {"input": "3 1 7\r\n", "output": ["1 000000002"]}, {"input": "1000000000 2 1000000\r\n", "output": ["2"]}, {"input": "23 0 23\r\n", "output": ["1 000000001"]}, {"input": "123456789 1234561 1234567\r\n", "output": ["1 000549636"]}, {"input": "11 10 13\r\n", "output": ["1 000000011"]}, {"input": "138 11711 11829\r\n", "output": ["2"]}, {"input": "1000000000 100050 1000001\r\n", "output": ["1 000000101"]}]
100
100
100
[{'input': '999999999 0 10000000\r\n', 'output': ['2']}, {'input': '2 1 3\r\n', 'output': ['1 000000001']}, {'input': '1000000000 9999991 10000000\r\n', 'output': ['2']}, {'input': '4 1 4\r\n', 'output': ['2']}, {'input': '116482865 344094604 3271060\r\n', 'output': ['2']}]
[{'input': '0 7 13\r\n', 'output': ['2']}, {'input': '0 3 3\r\n', 'output': ['2']}, {'input': '1000000000 0 2\r\n', 'output': ['2']}, {'input': '9902593 9902584 9902593\r\n', 'output': ['1 002490619']}, {'input': '815 216 182\r\n', 'output': ['2']}]
[{'input': '0 1 1\r\n', 'output': ['2']}, {'input': '1000000000 0 2\r\n', 'output': ['2']}, {'input': '1000000000 1000000000 9999999\r\n', 'output': ['2']}, {'input': '3966 5002 273075\r\n', 'output': ['1 000000008']}, {'input': '1 0 9\r\n', 'output': ['1 000000001']}]
[{'input': '0 0 11\r\n', 'output': ['2']}, {'input': '243 1001 1003\r\n', 'output': ['2']}, {'input': '1 0 9\r\n', 'output': ['1 000000001']}, {'input': '116482865 344094604 3271060\r\n', 'output': ['2']}, {'input': '4 3 12\r\n', 'output': ['1 000000001']}]
[{'input': '10 12000 12345\r\n', 'output': ['2']}, {'input': '1000000000 0 10000000\r\n', 'output': ['2']}, {'input': '0 1000000000 10000000\r\n', 'output': ['2']}, {'input': '23 0 23\r\n', 'output': ['1 000000001']}, {'input': '11 10 13\r\n', 'output': ['1 000000011']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
253
100
100
100
["3", "7"]
The only line of the input contains integer n (0 ≀ n ≀ 1018)Β β€” the number of Ayrat's moves.
a4b6a570f5e63462b68447713924b465
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; /** * CodeForces : 338 * * @author vinaysaini E. Hexagons */ public class cf338e { static int dx[] = { 1, -1, -2, -1, 1, 2 }; static int dy[] = { 2, 2, 0, -2, -2, 0 }; public static void main(String[] args) { long x = 0, y = 0; long n = in.nextLong(); long ringNumber = getRing(n); long stepsUpTo = 3 * ringNumber * ringNumber + 3 * ringNumber; x = 2 * ringNumber; long remainingSteps = n - stepsUpTo; if (remainingSteps > 0) { x = x + dx[0]; y = y + dy[0]; remainingSteps--; } if (remainingSteps >= ringNumber) { x += dx[1] * ringNumber; y += dy[1] * ringNumber; remainingSteps -= ringNumber; } else { x += dx[1] * remainingSteps; y += dy[1] * remainingSteps; remainingSteps -= remainingSteps; } if (remainingSteps >= ringNumber+1) { x += dx[2] * (ringNumber+1); y += dy[2] * (ringNumber+1); remainingSteps -= ringNumber+1; } else { x += dx[2] * remainingSteps; y += dy[2] * remainingSteps; remainingSteps -= remainingSteps; } if (remainingSteps >= ringNumber+1) { x += dx[3] * (ringNumber+1); y += dy[3] * (ringNumber+1); remainingSteps -= ringNumber+1; } else { x += dx[3] * remainingSteps; y += dy[3] * remainingSteps; remainingSteps -= remainingSteps; } if (remainingSteps >= ringNumber+1) { x += dx[4] * (ringNumber+1); y += dy[4] * (ringNumber+1); remainingSteps -= ringNumber+1; } else { x += dx[4] * remainingSteps; y += dy[4] * remainingSteps; remainingSteps -= remainingSteps; } if (remainingSteps >= ringNumber+1) { x += dx[5] * (ringNumber+1); y += dy[5] * (ringNumber+1); remainingSteps -= ringNumber+1; } else { x += dx[5] * remainingSteps; y += dy[5] * remainingSteps; remainingSteps -= remainingSteps; } if (remainingSteps >= ringNumber) { x += dx[0] * ringNumber; y += dy[0] * ringNumber; remainingSteps -= ringNumber; } else { x += dx[0] * remainingSteps; y += dy[0] * remainingSteps; remainingSteps -= remainingSteps; } out.println(x + " " + y); out.close(); } static long getRing(long n) { long l = 0; long r = (long) 1e9; while (l < r) { long m = (l + r) / 2; long sum = 3 * m * m + 3 * m; if (n < sum) { r = m; } else l = m + 1; } return l - 1; } public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static FastScanner in = new FastScanner(); public static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // --fast i/o ends here----// }
["-2 0", "3 2"]
Java
null
Print two integers x and yΒ β€” current coordinates of Ayrat coordinates.
Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined: Ayrat is searching through the field. He started at point (0, 0) and is moving along the spiral (see second picture). Sometimes he forgets where he is now. Help Ayrat determine his location after n moves.
[{"input": "3\r\n", "output": ["-2 0"]}, {"input": "7\r\n", "output": ["3 2"]}, {"input": "39\r\n", "output": ["5 6"]}, {"input": "14\r\n", "output": ["-2 -4"]}, {"input": "94\r\n", "output": ["8 8"]}, {"input": "60\r\n", "output": ["8 0"]}, {"input": "60\r\n", "output": ["8 0"]}, {"input": "59\r\n", "output": ["7 -2"]}, {"input": "181994\r\n", "output": ["154 -492"]}, {"input": "486639\r\n", "output": ["-33 806"]}, {"input": "34514\r\n", "output": ["13 -214"]}, {"input": "826594\r\n", "output": ["-769 562"]}, {"input": "1000000000000000000\r\n", "output": ["-418284973 -1154700538"]}, {"input": "854460\r\n", "output": ["414 1068"]}, {"input": "164960\r\n", "output": ["458 -20"]}, {"input": "618459\r\n", "output": ["-797 -222"]}, {"input": "496181994\r\n", "output": ["21108 9228"]}, {"input": "1000000000\r\n", "output": ["27596 -17836"]}, {"input": "228939226\r\n", "output": ["1516 17472"]}, {"input": "973034514\r\n", "output": ["27776 16488"]}, {"input": "984826594\r\n", "output": ["22704 -27064"]}, {"input": "19164960\r\n", "output": ["4864 384"]}, {"input": "249781780\r\n", "output": ["2815 18250"]}, {"input": "851838979\r\n", "output": ["8695 33702"]}, {"input": "978618459\r\n", "output": ["-15591 -36122"]}, {"input": "871854460\r\n", "output": ["31404 5384"]}, {"input": "302486639\r\n", "output": ["11555 -17054"]}, {"input": "0\r\n", "output": ["0 0"]}, {"input": "1\r\n", "output": ["1 2"]}, {"input": "2\r\n", "output": ["-1 2"]}, {"input": "3\r\n", "output": ["-2 0"]}, {"input": "4\r\n", "output": ["-1 -2"]}, {"input": "5\r\n", "output": ["1 -2"]}, {"input": "6\r\n", "output": ["2 0"]}, {"input": "7\r\n", "output": ["3 2"]}, {"input": "8\r\n", "output": ["2 4"]}, {"input": "9\r\n", "output": ["0 4"]}, {"input": "10\r\n", "output": ["-2 4"]}, {"input": "11\r\n", "output": ["-3 2"]}, {"input": "12\r\n", "output": ["-4 0"]}, {"input": "13\r\n", "output": ["-3 -2"]}, {"input": "14\r\n", "output": ["-2 -4"]}, {"input": "15\r\n", "output": ["0 -4"]}, {"input": "16\r\n", "output": ["2 -4"]}, {"input": "17\r\n", "output": ["3 -2"]}, {"input": "18\r\n", "output": ["4 0"]}, {"input": "19\r\n", "output": ["5 2"]}, {"input": "20\r\n", "output": ["4 4"]}, {"input": "21\r\n", "output": ["3 6"]}, {"input": "22\r\n", "output": ["1 6"]}, {"input": "23\r\n", "output": ["-1 6"]}, {"input": "24\r\n", "output": ["-3 6"]}, {"input": "25\r\n", "output": ["-4 4"]}, {"input": "26\r\n", "output": ["-5 2"]}, {"input": "27\r\n", "output": ["-6 0"]}, {"input": "28\r\n", "output": ["-5 -2"]}, {"input": "29\r\n", "output": ["-4 -4"]}, {"input": "30\r\n", "output": ["-3 -6"]}, {"input": "257947185131120683\r\n", "output": ["-53995102 -586455096"]}, {"input": "258773432604171403\r\n", "output": ["-438664202 297458800"]}, {"input": "259599671487287531\r\n", "output": ["-252460838 -588330600"]}, {"input": "260425914665370955\r\n", "output": ["-423141322 332249584"]}, {"input": "261252157843454379\r\n", "output": ["-164822562 -590200144"]}, {"input": "262078401021537803\r\n", "output": ["439863347 302538706"]}, {"input": "262904639904653932\r\n", "output": ["-378326148 -427475264"]}, {"input": "263730878787770060\r\n", "output": ["200309780 592993400"]}, {"input": "264557126260820780\r\n", "output": ["489196540 209450068"]}, {"input": "775736713043603670\r\n", "output": ["-794841963 -444342246"]}, {"input": "776562956221687094\r\n", "output": ["-623135314 -788838484"]}, {"input": "777389199399770518\r\n", "output": ["-328249537 -1018095738"]}, {"input": "778215438282886646\r\n", "output": ["-719067659 -599137942"]}, {"input": "779041681460970070\r\n", "output": ["-637165825 764022826"]}, {"input": "779867924639053494\r\n", "output": ["559082192 -921270732"]}, {"input": "780694167817136918\r\n", "output": ["7343027 1020257594"]}, {"input": "781520406700253046\r\n", "output": ["-707743686 626107308"]}, {"input": "782346645583369174\r\n", "output": ["797020774 -448632052"]}, {"input": "783172893056419894\r\n", "output": ["604133660 -835484644"]}, {"input": "294352484134170081\r\n", "output": ["-264428508 -626474244"]}, {"input": "34761473798667069\r\n", "output": ["-107643660 215287324"]}, {"input": "247761054921329978\r\n", "output": ["-287379568 574759144"]}, {"input": "88904985049714519\r\n", "output": ["344296355 2"]}, {"input": "64695994584418558\r\n", "output": ["146851396 293702780"]}, {"input": "2999472947040002\r\n", "output": ["31620002 63239992"]}, {"input": "134013960807648841\r\n", "output": ["-422711816 4"]}, {"input": "27719767248080188\r\n", "output": ["-96124517 -192249026"]}, {"input": "228296921967681448\r\n", "output": ["-275860421 551720850"]}, {"input": "622704061396296670\r\n", "output": ["-911192665 10"]}, {"input": "382830415035226081\r\n", "output": ["357225613 714451226"]}, {"input": "175683606088259879\r\n", "output": ["-483988434 8"]}, {"input": "533568904697339792\r\n", "output": ["-421730125 843460258"]}, {"input": "281824423976299408\r\n", "output": ["-306498737 -612997466"]}, {"input": "237223610332609448\r\n", "output": ["-281201952 -562403896"]}, {"input": "82638676376847406\r\n", "output": ["-331941110 4"]}, {"input": "358538881902627465\r\n", "output": ["-691412929 6"]}, {"input": "1941943667672759\r\n", "output": ["-25442382 -50884744"]}, {"input": "504819148029580024\r\n", "output": ["820421960 -4"]}, {"input": "24271330411219667\r\n", "output": ["179893783 -2"]}, {"input": "108364135632524999\r\n", "output": ["-380112498 8"]}, {"input": "16796277375911920\r\n", "output": ["74824856 -149649712"]}, {"input": "194403552286884865\r\n", "output": ["-509121532 4"]}, {"input": "565840809656836956\r\n", "output": ["868593352 0"]}, {"input": "39010293491965817\r\n", "output": ["-114032591 -228065170"]}, {"input": "746407891412272132\r\n", "output": ["498801191 -997602386"]}, {"input": "95626493228268863\r\n", "output": ["178537107 357074206"]}, {"input": "385078658398478614\r\n", "output": ["358273010 -716546028"]}, {"input": "177207687885798058\r\n", "output": ["486083238 -4"]}, {"input": "536222521732590352\r\n", "output": ["-422777531 845555062"]}, {"input": "1571429132955632\r\n", "output": ["45773778 4"]}, {"input": "498549006180463098\r\n", "output": ["407655496 -815310984"]}, {"input": "438594547809157461\r\n", "output": ["382358709 -764717418"]}, {"input": "214071008058709620\r\n", "output": ["534254630 0"]}, {"input": "599060227806517999\r\n", "output": ["-446863220 893726452"]}, {"input": "329939015655396840\r\n", "output": ["-331631832 663263664"]}, {"input": "281523482448806534\r\n", "output": ["306335045 612670094"]}, {"input": "109561818187625921\r\n", "output": ["191103653 382207306"]}, {"input": "412565943716413781\r\n", "output": ["370839563 741679126"]}, {"input": "196006607922989510\r\n", "output": ["-255608161 511216338"]}, {"input": "379604878823574823\r\n", "output": ["-355717526 711435056"]}, {"input": "173500741457825598\r\n", "output": ["240486136 480972264"]}, {"input": "138919367769131398\r\n", "output": ["-430378693 10"]}, {"input": "29974778103430162\r\n", "output": ["99957958 199915904"]}, {"input": "234685974076220810\r\n", "output": ["-279693865 559387730"]}, {"input": "633227154929081648\r\n", "output": ["-459429777 -918859546"]}, {"input": "58101264340386100\r\n", "output": ["-139165682 278331372"]}, {"input": "1718550904886625\r\n", "output": ["23934291 -47868582"]}, {"input": "124444652733481603\r\n", "output": ["203670197 -407340402"]}, {"input": "441000740540275741\r\n", "output": ["-383406115 -766812218"]}, {"input": "545168342596476149\r\n", "output": ["852579099 -2"]}, {"input": "138919367769131403\r\n", "output": ["-430378698 0"]}, {"input": "138919367984320752\r\n", "output": ["-215189349 -430378698"]}, {"input": "1\r\n", "output": ["1 2"]}, {"input": "2\r\n", "output": ["-1 2"]}, {"input": "4\r\n", "output": ["-1 -2"]}, {"input": "5\r\n", "output": ["1 -2"]}, {"input": "6\r\n", "output": ["2 0"]}]
100
100
100
[{'input': '11\r\n', 'output': ['-3 2']}, {'input': '486639\r\n', 'output': ['-33 806']}, {'input': '0\r\n', 'output': ['0 0']}, {'input': '39\r\n', 'output': ['5 6']}, {'input': '26\r\n', 'output': ['-5 2']}]
[{'input': '8\r\n', 'output': ['2 4']}, {'input': '385078658398478614\r\n', 'output': ['358273010 -716546028']}, {'input': '39\r\n', 'output': ['5 6']}, {'input': '302486639\r\n', 'output': ['11555 -17054']}, {'input': '27719767248080188\r\n', 'output': ['-96124517 -192249026']}]
[{'input': '1941943667672759\r\n', 'output': ['-25442382 -50884744']}, {'input': '261252157843454379\r\n', 'output': ['-164822562 -590200144']}, {'input': '262078401021537803\r\n', 'output': ['439863347 302538706']}, {'input': '25\r\n', 'output': ['-4 4']}, {'input': '329939015655396840\r\n', 'output': ['-331631832 663263664']}]
[{'input': '13\r\n', 'output': ['-3 -2']}, {'input': '60\r\n', 'output': ['8 0']}, {'input': '441000740540275741\r\n', 'output': ['-383406115 -766812218']}, {'input': '262904639904653932\r\n', 'output': ['-378326148 -427475264']}, {'input': '2\r\n', 'output': ['-1 2']}]
[{'input': '259599671487287531\r\n', 'output': ['-252460838 -588330600']}, {'input': '257947185131120683\r\n', 'output': ['-53995102 -586455096']}, {'input': '94\r\n', 'output': ['8 8']}, {'input': '15\r\n', 'output': ['0 -4']}, {'input': '281824423976299408\r\n', 'output': ['-306498737 -612997466']}]
100
100
100
100
100
86.96
95.65
91.3
91.3
91.3
83.33
88.89
83.33
88.89
83.33
254
100
91.302
85.554
["6 1", "6 2", "60 5"]
The only line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^{15}$$$, $$$1 \leq k \leq 10^4$$$).
dc466d9c24b7dcb37c0e99337b4124d2
import java.lang.*; import java.math.*; import java.util.*; import java.io.*; public class Main { class Node { long p; int a; public Node(long p,int a){ this.p=p; this.a=a; } } void solve() { long n=nl(); int k=ni(); ArrayList<Node> vec=new ArrayList<>(); for(long i=2;i*i<=n;i++){ if(n%i==0){ int cc=0; while(n%i==0){ n/=i; cc++; } vec.add(new Node(i,cc)); } } if(n>1) vec.add(new Node(n,1)); long dp[][]=new long[51][k+1]; long ans=1; long suf[]=new long[51]; long curSuf[]=new long[51]; long inv[]=new long[52]; for(int i=0;i<52;i++) inv[i]=modInverse(i); for(Node P : vec){ long p=P.p; int a=P.a; for(int i=0;i<=50;i++) Arrays.fill(dp[i],0); dp[a][0]=1; Arrays.fill(suf,inv[a+1]); for(int s=1;s<=k;s++){ Arrays.fill(curSuf,0); for(int i=a;i>=0;i--){ dp[i][s]=suf[i]; curSuf[i]=mul(dp[i][s],inv[i+1]); if(i+1<=a) curSuf[i]=add(curSuf[i],curSuf[i+1]); // for(int j=i;j<=a;j++) dp[i][s]=add(dp[i][s],mul(dp[j][s-1],inv[j+1])); } for(int i=0;i<=a;i++) suf[i]=curSuf[i]; } long ex=0; for(int i=0;i<=a;i++){ ex=add(ex,mul(dp[i][k],modpow(p,i))); } // if(p==2) pw.println(dp[0][k]+" "+dp[1][k]+" "+modInverse(2)+" "+ex+" "+mul(3,modInverse(2))); ans=mul(ans,ex); } pw.println(ans); } long add(long x,long y){ x+=y; if(x>=M) x-=M; return x; } long sub(long x,long y){ x-=y; if(x<0) x+=M; return x; } long mul(long x,long y){ x*=y; if(x>=M) x%=M; return x; } long modpow(long a, long b) { long r=1; while(b>0) { if((b&1)>0) r=mul(r,a); a=mul(a,a); b>>=1; } return r; } long modInverse(long A) { return modpow(A,M-2); } long M= (long)1e9+7; InputStream is; PrintWriter pw; String INPUT = ""; void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); pw = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); pw.flush(); if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms"); } public static void main(String[] args) throws Exception { new Main().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); } }
["3", "875000008", "237178099"]
Java
NoteIn the first example, after one step, the number written on the blackboard is $$$1$$$, $$$2$$$, $$$3$$$ or $$$6$$$ β€” each occurring with equal probability. Hence, the answer is $$$\frac{1+2+3+6}{4}=3$$$.In the second example, the answer is equal to $$$1 \cdot \frac{9}{16}+2 \cdot \frac{3}{16}+3 \cdot \frac{3}{16}+6 \cdot \frac{1}{16}=\frac{15}{8}$$$.
Print a single integer β€” the expected value of the number on the blackboard after $$$k$$$ steps as $$$P \cdot Q^{-1} \pmod{10^9+7}$$$ for $$$P$$$, $$$Q$$$ defined above.
Makoto has a big blackboard with a positive integer $$$n$$$ written on it. He will perform the following action exactly $$$k$$$ times:Suppose the number currently written on the blackboard is $$$v$$$. He will randomly pick one of the divisors of $$$v$$$ (possibly $$$1$$$ and $$$v$$$) and replace $$$v$$$ with this divisor. As Makoto uses his famous random number generator (RNG) and as he always uses $$$58$$$ as his generator seed, each divisor is guaranteed to be chosen with equal probability.He now wonders what is the expected value of the number written on the blackboard after $$$k$$$ steps.It can be shown that this value can be represented as $$$\frac{P}{Q}$$$ where $$$P$$$ and $$$Q$$$ are coprime integers and $$$Q \not\equiv 0 \pmod{10^9+7}$$$. Print the value of $$$P \cdot Q^{-1}$$$ modulo $$$10^9+7$$$.
[{"input": "6 1\r\n", "output": ["3"]}, {"input": "6 2\r\n", "output": ["875000008"]}, {"input": "60 5\r\n", "output": ["237178099"]}, {"input": "2 4\r\n", "output": ["562500005"]}, {"input": "12 3\r\n", "output": ["775462970"]}, {"input": "55 5\r\n", "output": ["789062507"]}, {"input": "935 9\r\n", "output": ["658825880"]}, {"input": "1 10000\r\n", "output": ["1"]}, {"input": "120 1\r\n", "output": ["500000026"]}, {"input": "1000000000000000 10000\r\n", "output": ["215514159"]}, {"input": "671058194037157 8673\r\n", "output": ["298638658"]}, {"input": "900018062553298 4801\r\n", "output": ["345432320"]}, {"input": "128973636102142 5521\r\n", "output": ["99152648"]}, {"input": "999999999999993 8123\r\n", "output": ["868053217"]}, {"input": "260858031033600 9696\r\n", "output": ["692221824"]}, {"input": "562949953421312 9779\r\n", "output": ["98057767"]}, {"input": "357933504618282 1649\r\n", "output": ["197730476"]}, {"input": "586884783199831 5073\r\n", "output": ["883678085"]}, {"input": "187877211524483 8497\r\n", "output": ["562808746"]}, {"input": "866421317361600 10000\r\n", "output": ["82212846"]}, {"input": "782574093100800 9999\r\n", "output": ["293217028"]}, {"input": "577614211574400 9998\r\n", "output": ["681915605"]}, {"input": "65214507758400 9997\r\n", "output": ["677959603"]}, {"input": "963761198400 9996\r\n", "output": ["669401143"]}, {"input": "5587021440 9995\r\n", "output": ["360750834"]}, {"input": "17297280 9994\r\n", "output": ["94383698"]}, {"input": "7560 9993\r\n", "output": ["412712546"]}, {"input": "120 9992\r\n", "output": ["167656619"]}, {"input": "1 1\r\n", "output": ["1"]}, {"input": "609359740010496 1337\r\n", "output": ["263703037"]}, {"input": "912750790581630 9876\r\n", "output": ["291557094"]}, {"input": "617673396283947 7777\r\n", "output": ["488769014"]}, {"input": "890604418498560 9119\r\n", "output": ["185509970"]}, {"input": "524288004718592 8888\r\n", "output": ["851726115"]}, {"input": "999999999999989 8998\r\n", "output": ["391873310"]}, {"input": "999999999999999 8123\r\n", "output": ["41003922"]}, {"input": "817237005720659 4233\r\n", "output": ["533017938"]}, {"input": "1000000007 1\r\n", "output": ["500000004"]}, {"input": "1000000007 2\r\n", "output": ["750000006"]}, {"input": "999999999999970 8998\r\n", "output": ["939941657"]}, {"input": "900000060000001 8123\r\n", "output": ["865356488"]}, {"input": "999011322032079 4233\r\n", "output": ["546309400"]}, {"input": "999005327998113 9119\r\n", "output": ["106270540"]}, {"input": "900000720000023 9876\r\n", "output": ["511266473"]}]
100
100
100
[{'input': '866421317361600 10000\r\n', 'output': ['82212846']}, {'input': '60 5\r\n', 'output': ['237178099']}, {'input': '935 9\r\n', 'output': ['658825880']}, {'input': '890604418498560 9119\r\n', 'output': ['185509970']}, {'input': '817237005720659 4233\r\n', 'output': ['533017938']}]
[{'input': '1 1\r\n', 'output': ['1']}, {'input': '6 1\r\n', 'output': ['3']}, {'input': '999999999999999 8123\r\n', 'output': ['41003922']}, {'input': '128973636102142 5521\r\n', 'output': ['99152648']}, {'input': '357933504618282 1649\r\n', 'output': ['197730476']}]
[{'input': '5587021440 9995\r\n', 'output': ['360750834']}, {'input': '17297280 9994\r\n', 'output': ['94383698']}, {'input': '617673396283947 7777\r\n', 'output': ['488769014']}, {'input': '260858031033600 9696\r\n', 'output': ['692221824']}, {'input': '65214507758400 9997\r\n', 'output': ['677959603']}]
[{'input': '900018062553298 4801\r\n', 'output': ['345432320']}, {'input': '2 4\r\n', 'output': ['562500005']}, {'input': '890604418498560 9119\r\n', 'output': ['185509970']}, {'input': '617673396283947 7777\r\n', 'output': ['488769014']}, {'input': '900000720000023 9876\r\n', 'output': ['511266473']}]
[{'input': '17297280 9994\r\n', 'output': ['94383698']}, {'input': '2 4\r\n', 'output': ['562500005']}, {'input': '1 1\r\n', 'output': ['1']}, {'input': '999999999999993 8123\r\n', 'output': ['868053217']}, {'input': '609359740010496 1337\r\n', 'output': ['263703037']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
255
100
100
100
["4\n1 3 3 2", "3\n1 1 1", "4\n42 0 0 42"]
The first line contains a single integer n (1 ≀ n ≀ 100)Β β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600)Β β€” participants' scores. It's guaranteed that at least one participant has non-zero score.
3b520c15ea9a11b16129da30dcfb5161
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Scanner; import java.util.StringTokenizer; import java.util.ArrayList; import java.util.TreeSet; import java.util.Collections; public class Hello { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader in=new FastReader(); //start code here int n=in.nextInt(); int res=0; ArrayList<Integer> al = new ArrayList<>(); for(int i=0;i<n;++i) { int x = in.nextInt(); if(x!=0&&!al.contains(x)) { ++res; al.add(x); } } System.out.print(res); } }
["3", "1", "1"]
Java
NoteThere are three ways to choose a subset in sample case one. Only participants with 3 points will get diplomas. Participants with 2 or 3 points will get diplomas. Everyone will get a diploma! The only option in sample case two is to award everyone.Note that in sample case three participants with zero scores cannot get anything.
Print a single integerΒ β€” the desired number of ways.
The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points.As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: At least one participant should get a diploma. None of those with score equal to zero should get awarded. When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas.
[{"input": "4\r\n1 3 3 2\r\n", "output": ["3"]}, {"input": "3\r\n1 1 1\r\n", "output": ["1"]}, {"input": "4\r\n42 0 0 42\r\n", "output": ["1"]}, {"input": "10\r\n1 0 1 0 1 0 0 0 0 1\r\n", "output": ["1"]}, {"input": "10\r\n572 471 540 163 50 30 561 510 43 200\r\n", "output": ["10"]}, {"input": "100\r\n122 575 426 445 172 81 247 429 97 202 175 325 382 384 417 356 132 502 328 537 57 339 518 211 479 306 140 168 268 16 140 263 593 249 391 310 555 468 231 180 157 18 334 328 276 155 21 280 322 545 111 267 467 274 291 304 235 34 365 180 21 95 501 552 325 331 302 353 296 22 289 399 7 466 32 302 568 333 75 192 284 10 94 128 154 512 9 480 243 521 551 492 420 197 207 125 367 117 438 600\r\n", "output": ["94"]}, {"input": "100\r\n600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600\r\n", "output": ["1"]}, {"input": "78\r\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12\r\n", "output": ["13"]}, {"input": "34\r\n220 387 408 343 184 447 197 307 337 414 251 319 426 322 347 242 208 412 188 185 241 235 216 259 331 372 322 284 444 384 214 297 389 391\r\n", "output": ["33"]}, {"input": "100\r\n1 2 1 0 3 0 2 0 0 1 2 0 1 3 0 3 3 1 3 0 0 2 1 2 2 1 3 3 3 3 3 2 0 0 2 1 2 3 2 3 0 1 1 3 3 2 0 3 1 0 2 2 2 1 2 3 2 1 0 3 0 2 0 3 0 2 1 0 3 1 0 2 2 1 3 1 3 0 2 3 3 1 1 3 1 3 0 3 2 0 2 3 3 0 2 0 2 0 1 3\r\n", "output": ["3"]}, {"input": "100\r\n572 471 540 163 50 30 561 510 43 200 213 387 500 424 113 487 357 333 294 337 435 202 447 494 485 465 161 344 470 559 104 356 393 207 224 213 511 514 60 386 149 216 392 229 429 173 165 401 395 150 127 579 344 390 529 296 225 425 318 79 465 447 177 110 367 212 459 270 41 500 277 567 125 436 178 9 214 342 203 112 144 24 79 155 495 556 40 549 463 281 241 316 2 246 1 396 510 293 332 55\r\n", "output": ["93"]}, {"input": "99\r\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12 2 3 9 3 7 13 7 13 0 11 8 12 2 5 9 4 0 6 6 2 13\r\n", "output": ["13"]}, {"input": "99\r\n1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0 0 0 0 0 1\r\n", "output": ["1"]}, {"input": "99\r\n21 74 25 44 71 80 46 28 96 1 74 24 81 83 16 55 31 1 27 36 56 38 17 10 78 5 39 67 67 15 39 62 92 48 90 9 54 67 30 79 56 17 33 27 75 54 20 79 21 44 10 66 66 73 90 3 34 33 64 79 20 94 0 51 24 30 1 52 95 21 88 98 6 65 31 1 67 32 74 91 83 9 93 27 53 11 8 79 42 20 50 91 19 96 6 24 66 16 37\r\n", "output": ["61"]}, {"input": "2\r\n0 1\r\n", "output": ["1"]}, {"input": "2\r\n0 600\r\n", "output": ["1"]}, {"input": "4\r\n1 1 1 2\r\n", "output": ["2"]}, {"input": "4\r\n0 0 1 2\r\n", "output": ["2"]}, {"input": "1\r\n5\r\n", "output": ["1"]}, {"input": "2\r\n0 5\r\n", "output": ["1"]}, {"input": "5\r\n1 0 0 1 2\r\n", "output": ["2"]}]
100
100
100
[{'input': '5\r\n1 0 0 1 2\r\n', 'output': ['2']}, {'input': '100\r\n572 471 540 163 50 30 561 510 43 200 213 387 500 424 113 487 357 333 294 337 435 202 447 494 485 465 161 344 470 559 104 356 393 207 224 213 511 514 60 386 149 216 392 229 429 173 165 401 395 150 127 579 344 390 529 296 225 425 318 79 465 447 177 110 367 212 459 270 41 500 277 567 125 436 178 9 214 342 203 112 144 24 79 155 495 556 40 549 463 281 241 316 2 246 1 396 510 293 332 55\r\n', 'output': ['93']}, {'input': '4\r\n1 3 3 2\r\n', 'output': ['3']}, {'input': '100\r\n600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600\r\n', 'output': ['1']}, {'input': '2\r\n0 600\r\n', 'output': ['1']}]
[{'input': '99\r\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12 2 3 9 3 7 13 7 13 0 11 8 12 2 5 9 4 0 6 6 2 13\r\n', 'output': ['13']}, {'input': '4\r\n1 1 1 2\r\n', 'output': ['2']}, {'input': '34\r\n220 387 408 343 184 447 197 307 337 414 251 319 426 322 347 242 208 412 188 185 241 235 216 259 331 372 322 284 444 384 214 297 389 391\r\n', 'output': ['33']}, {'input': '10\r\n572 471 540 163 50 30 561 510 43 200\r\n', 'output': ['10']}, {'input': '99\r\n1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0 0 0 0 0 1\r\n', 'output': ['1']}]
[{'input': '100\r\n1 2 1 0 3 0 2 0 0 1 2 0 1 3 0 3 3 1 3 0 0 2 1 2 2 1 3 3 3 3 3 2 0 0 2 1 2 3 2 3 0 1 1 3 3 2 0 3 1 0 2 2 2 1 2 3 2 1 0 3 0 2 0 3 0 2 1 0 3 1 0 2 2 1 3 1 3 0 2 3 3 1 1 3 1 3 0 3 2 0 2 3 3 0 2 0 2 0 1 3\r\n', 'output': ['3']}, {'input': '2\r\n0 600\r\n', 'output': ['1']}, {'input': '34\r\n220 387 408 343 184 447 197 307 337 414 251 319 426 322 347 242 208 412 188 185 241 235 216 259 331 372 322 284 444 384 214 297 389 391\r\n', 'output': ['33']}, {'input': '100\r\n572 471 540 163 50 30 561 510 43 200 213 387 500 424 113 487 357 333 294 337 435 202 447 494 485 465 161 344 470 559 104 356 393 207 224 213 511 514 60 386 149 216 392 229 429 173 165 401 395 150 127 579 344 390 529 296 225 425 318 79 465 447 177 110 367 212 459 270 41 500 277 567 125 436 178 9 214 342 203 112 144 24 79 155 495 556 40 549 463 281 241 316 2 246 1 396 510 293 332 55\r\n', 'output': ['93']}, {'input': '10\r\n572 471 540 163 50 30 561 510 43 200\r\n', 'output': ['10']}]
[{'input': '99\r\n21 74 25 44 71 80 46 28 96 1 74 24 81 83 16 55 31 1 27 36 56 38 17 10 78 5 39 67 67 15 39 62 92 48 90 9 54 67 30 79 56 17 33 27 75 54 20 79 21 44 10 66 66 73 90 3 34 33 64 79 20 94 0 51 24 30 1 52 95 21 88 98 6 65 31 1 67 32 74 91 83 9 93 27 53 11 8 79 42 20 50 91 19 96 6 24 66 16 37\r\n', 'output': ['61']}, {'input': '34\r\n220 387 408 343 184 447 197 307 337 414 251 319 426 322 347 242 208 412 188 185 241 235 216 259 331 372 322 284 444 384 214 297 389 391\r\n', 'output': ['33']}, {'input': '2\r\n0 1\r\n', 'output': ['1']}, {'input': '2\r\n0 600\r\n', 'output': ['1']}, {'input': '4\r\n0 0 1 2\r\n', 'output': ['2']}]
[{'input': '100\r\n122 575 426 445 172 81 247 429 97 202 175 325 382 384 417 356 132 502 328 537 57 339 518 211 479 306 140 168 268 16 140 263 593 249 391 310 555 468 231 180 157 18 334 328 276 155 21 280 322 545 111 267 467 274 291 304 235 34 365 180 21 95 501 552 325 331 302 353 296 22 289 399 7 466 32 302 568 333 75 192 284 10 94 128 154 512 9 480 243 521 551 492 420 197 207 125 367 117 438 600\r\n', 'output': ['94']}, {'input': '99\r\n1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0 0 0 0 0 1\r\n', 'output': ['1']}, {'input': '2\r\n0 5\r\n', 'output': ['1']}, {'input': '2\r\n0 1\r\n', 'output': ['1']}, {'input': '10\r\n1 0 1 0 1 0 0 0 0 1\r\n', 'output': ['1']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
256
100
100
100
["6\nxxxiii", "5\nxxoxx", "10\nxxxxxxxxxx"]
The first line contains integer $$$n$$$ $$$(3 \le n \le 100)$$$ β€” the length of the file name. The second line contains a string of length $$$n$$$ consisting of lowercase Latin letters only β€” the file name.
8de14db41d0acee116bd5d8079cb2b02
import java.util.*; import java.lang.*; import java.io.*; public class A { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n,i,j,count,k; String t=br.readLine(); n=Integer.parseInt(t); t=br.readLine(); char[] s=t.toCharArray(); k=0; for(i=0;i<n;) { if(s[i]=='x') { count=1; for(j=i+1;j<n;j++) { if(s[j]=='x') count=count+1; else break; } i=i+count; if(count!=1) k=k+(count-2); } else i=i+1; } System.out.println(k); } }
["1", "0", "8"]
Java
NoteIn the first example Polycarp tried to send a file with name contains number $$$33$$$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0.
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed.Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx".You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $$$1$$$. For example, if you delete the character in the position $$$2$$$ from the string "exxxii", then the resulting string is "exxii".
[{"input": "6\r\nxxxiii\r\n", "output": ["1\r\n", "1", "1\n"]}, {"input": "5\r\nxxoxx\r\n", "output": ["0\r\n", "0\n", "0"]}, {"input": "10\r\nxxxxxxxxxx\r\n", "output": ["8\n", "8", "8\r\n"]}, {"input": "100\r\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n", "output": ["98", "98\n", "98\r\n"]}, {"input": "99\r\nxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxa\r\n", "output": ["0\r\n", "0\n", "0"]}, {"input": "3\r\nxxx\r\n", "output": ["1\r\n", "1", "1\n"]}, {"input": "77\r\naaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxyyyzzz\r\n", "output": ["0\r\n", "0\n", "0"]}, {"input": "100\r\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxxxxmrx\r\n", "output": ["41", "41\r\n", "41\n"]}, {"input": "100\r\nxxxxxxxxxxxjtxxxxxxxxcxxxxxxcfxxxxzxxxxxxgxxxxxbxxxxbxxxxxxxxdycxxxxokixxxkizxxgcxxxxxxxxexxxxxfxxxc\r\n", "output": ["49", "49\n", "49\r\n"]}, {"input": "100\r\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx\r\n", "output": ["41", "41\r\n", "41\n"]}, {"input": "34\r\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": ["0\r\n", "0\n", "0"]}, {"input": "5\r\nfcyju\r\n", "output": ["0\r\n", "0\n", "0"]}, {"input": "100\r\nihygyvdvyeifomhxhkhdkimquvgallbqharcyriyqkidnwykozuhvkwdldlztpabgyuflikychqpdenwzgtlzotyumjgdsrbxxxx\r\n", "output": ["2", "2\n", "2\r\n"]}]
100
100
100
[{'input': '100\r\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx\r\n', 'output': ['41', '41\r\n', '41\n']}, {'input': '99\r\nxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxa\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '5\r\nfcyju\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '100\r\nxxxxxxxxxxxjtxxxxxxxxcxxxxxxcfxxxxzxxxxxxgxxxxxbxxxxbxxxxxxxxdycxxxxokixxxkizxxgcxxxxxxxxexxxxxfxxxc\r\n', 'output': ['49', '49\n', '49\r\n']}, {'input': '6\r\nxxxiii\r\n', 'output': ['1\r\n', '1', '1\n']}]
[{'input': '100\r\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n', 'output': ['98', '98\n', '98\r\n']}, {'input': '5\r\nfcyju\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '34\r\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '100\r\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx\r\n', 'output': ['41', '41\r\n', '41\n']}, {'input': '3\r\nxxx\r\n', 'output': ['1\r\n', '1', '1\n']}]
[{'input': '100\r\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx\r\n', 'output': ['41', '41\r\n', '41\n']}, {'input': '99\r\nxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxa\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '5\r\nfcyju\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '100\r\nxxxxxxxxxxxjtxxxxxxxxcxxxxxxcfxxxxzxxxxxxgxxxxxbxxxxbxxxxxxxxdycxxxxokixxxkizxxgcxxxxxxxxexxxxxfxxxc\r\n', 'output': ['49', '49\n', '49\r\n']}, {'input': '100\r\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n', 'output': ['98', '98\n', '98\r\n']}]
[{'input': '100\r\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx\r\n', 'output': ['41', '41\r\n', '41\n']}, {'input': '5\r\nxxoxx\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '10\r\nxxxxxxxxxx\r\n', 'output': ['8\n', '8', '8\r\n']}, {'input': '100\r\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n', 'output': ['98', '98\n', '98\r\n']}, {'input': '34\r\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n', 'output': ['0\r\n', '0\n', '0']}]
[{'input': '100\r\nihygyvdvyeifomhxhkhdkimquvgallbqharcyriyqkidnwykozuhvkwdldlztpabgyuflikychqpdenwzgtlzotyumjgdsrbxxxx\r\n', 'output': ['2', '2\n', '2\r\n']}, {'input': '100\r\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx\r\n', 'output': ['41', '41\r\n', '41\n']}, {'input': '5\r\nxxoxx\r\n', 'output': ['0\r\n', '0\n', '0']}, {'input': '10\r\nxxxxxxxxxx\r\n', 'output': ['8\n', '8', '8\r\n']}, {'input': '3\r\nxxx\r\n', 'output': ['1\r\n', '1', '1\n']}]
100
100
100
100
100
100
100
100
100
100
90
90
90
90
100
257
100
100
92
["4 6", "9 7", "1 1"]
The only line of input contains two integers r and g, separated by a single space β€” the number of available red and green blocks respectively (0 ≀ r, g ≀ 2Β·105, r + g β‰₯ 1).
34b6286350e3531c1fbda6b0c184addc
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class Abood2D { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int R = sc.nextInt(); int G = sc.nextInt(); int sum = G + R; int H = sum == 1? 1 : 0; while(sum >= H) sum -= H++; H--; int[] acc = new int[H + 1]; for (int i = 1; i <= H; i++) acc[i] = acc[i - 1] + i; int[] last = new int[R + 1]; Arrays.fill(last, 1); for (int i = H - 1; i >= 0; i--) { int[] cur = new int[R + 1]; for (int j = 0; j < cur.length; j++) { int r = j; int g = G - (acc[i] - (R - r)); if(g - i >= 1) cur[j] += last[j]; if(r - i >= 1) cur[j] += last[j - (i + 1)]; cur[j] %= (int) 1e9 + 7; } last = cur; } out.print(last[R]); out.flush(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if(x.charAt(0) == '-') { neg = true; start++; } for(int i = start; i < x.length(); i++) if(x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if(dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg?-1:1); } public boolean ready() throws IOException {return br.ready();} } }
["2", "6", "2"]
Java
NoteThe image in the problem statement shows all possible red-green towers for the first sample.
Output the only integer β€” the number of different possible red-green towers of height h moduloΒ 109 + 7.
There are r red and g green blocks for construction of the red-green tower. Red-green tower can be built following next rules: Red-green tower is consisting of some number of levels; Let the red-green tower consist of n levels, then the first level of this tower should consist of n blocks, second level β€” of n - 1 blocks, the third one β€” of n - 2 blocks, and so on β€” the last level of such tower should consist of the one block. In other words, each successive level should contain one block less than the previous one; Each level of the red-green tower should contain blocks of the same color. Let h be the maximum possible number of levels of red-green tower, that can be built out of r red and g green blocks meeting the rules above. The task is to determine how many different red-green towers having h levels can be built out of the available blocks.Two red-green towers are considered different if there exists some level, that consists of red blocks in the one tower and consists of green blocks in the other tower.You are to write a program that will find the number of different red-green towers of height h moduloΒ 109 + 7.
[{"input": "4 6\r\n", "output": ["2"]}, {"input": "9 7\r\n", "output": ["6"]}, {"input": "1 1\r\n", "output": ["2"]}, {"input": "3 3\r\n", "output": ["2"]}, {"input": "2 19\r\n", "output": ["1"]}, {"input": "18 3\r\n", "output": ["2"]}, {"input": "100000 1\r\n", "output": ["2"]}, {"input": "1 100000\r\n", "output": ["2"]}, {"input": "6 6\r\n", "output": ["6"]}, {"input": "10 10\r\n", "output": ["18"]}, {"input": "200000 200000\r\n", "output": ["206874596"]}, {"input": "0 1\r\n", "output": ["1"]}, {"input": "1 0\r\n", "output": ["1"]}, {"input": "0 200000\r\n", "output": ["1"]}, {"input": "200000 0\r\n", "output": ["1"]}, {"input": "199396 0\r\n", "output": ["1"]}, {"input": "199395 0\r\n", "output": ["1"]}, {"input": "0 199397\r\n", "output": ["1"]}, {"input": "121147 78249\r\n", "output": ["64290784"]}, {"input": "78250 121147\r\n", "output": ["981737243"]}, {"input": "121146 78249\r\n", "output": ["832902708"]}, {"input": "199585 199586\r\n", "output": ["438320405"]}, {"input": "199586 199586\r\n", "output": ["876640810"]}, {"input": "199585 199585\r\n", "output": ["199771918"]}, {"input": "107344 159729\r\n", "output": ["849320920"]}, {"input": "2954 1977\r\n", "output": ["835530858"]}, {"input": "25580 17318\r\n", "output": ["263898876"]}, {"input": "89671 32487\r\n", "output": ["654128709"]}, {"input": "38 36\r\n", "output": ["612"]}, {"input": "136749 183300\r\n", "output": ["906576609"]}, {"input": "10000 10000\r\n", "output": ["885988055"]}, {"input": "200000 199999\r\n", "output": ["396481680"]}]
100
100
100
[{'input': '18 3\r\n', 'output': ['2']}, {'input': '100000 1\r\n', 'output': ['2']}, {'input': '78250 121147\r\n', 'output': ['981737243']}, {'input': '121147 78249\r\n', 'output': ['64290784']}, {'input': '121146 78249\r\n', 'output': ['832902708']}]
[{'input': '10 10\r\n', 'output': ['18']}, {'input': '38 36\r\n', 'output': ['612']}, {'input': '100000 1\r\n', 'output': ['2']}, {'input': '199396 0\r\n', 'output': ['1']}, {'input': '199395 0\r\n', 'output': ['1']}]
[{'input': '0 199397\r\n', 'output': ['1']}, {'input': '199586 199586\r\n', 'output': ['876640810']}, {'input': '25580 17318\r\n', 'output': ['263898876']}, {'input': '1 1\r\n', 'output': ['2']}, {'input': '0 1\r\n', 'output': ['1']}]
[{'input': '0 199397\r\n', 'output': ['1']}, {'input': '200000 0\r\n', 'output': ['1']}, {'input': '18 3\r\n', 'output': ['2']}, {'input': '25580 17318\r\n', 'output': ['263898876']}, {'input': '100000 1\r\n', 'output': ['2']}]
[{'input': '200000 200000\r\n', 'output': ['206874596']}, {'input': '6 6\r\n', 'output': ['6']}, {'input': '199585 199585\r\n', 'output': ['199771918']}, {'input': '200000 0\r\n', 'output': ['1']}, {'input': '1 1\r\n', 'output': ['2']}]
100
100
100
100
100
100
100
100
100
100
92.86
92.86
100
92.86
92.86
258
100
100
94.288
["19", "16"]
The first and only line contains an integer $$$r$$$ ($$$1 \le r \le 10^{12}$$$).
3ff1c25a1026c90aeb14d148d7fb96ba
//1184A1 import java.util.*; public class heidiA1{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); long r=sc.nextLong(); if(r%2==0||r<=3) System.out.println("NO"); else{ System.out.println("1"+" "+((r-3)/2)); } } }
["1 8", "NO"]
Java
null
Output integers $$$x, y$$$ such that $$$H(x,y) = r$$$ and $$$x$$$ is smallest possible, or "NO" if no such pair exists.
Melody Pond was stolen from her parents as a newborn baby by Madame Kovarian, to become a weapon of the Silence in their crusade against the Doctor. Madame Kovarian changed Melody's name to River Song, giving her a new identity that allowed her to kill the Eleventh Doctor.Heidi figured out that Madame Kovarian uses a very complicated hashing function in order to change the names of the babies she steals. In order to prevent this from happening to future Doctors, Heidi decided to prepare herself by learning some basic hashing techniques.The first hashing function she designed is as follows.Given two positive integers $$$(x, y)$$$ she defines $$$H(x,y):=x^2+2xy+x+1$$$.Now, Heidi wonders if the function is reversible. That is, given a positive integer $$$r$$$, can you find a pair $$$(x, y)$$$ (of positive integers) such that $$$H(x, y) = r$$$?If multiple such pairs exist, output the one with smallest possible $$$x$$$. If there is no such pair, output "NO".
[{"input": "19\r\n", "output": ["1 8"]}, {"input": "16\r\n", "output": ["NO"]}, {"input": "1\r\n", "output": ["NO"]}, {"input": "2\r\n", "output": ["NO"]}, {"input": "3\r\n", "output": ["NO"]}, {"input": "4\r\n", "output": ["NO"]}, {"input": "5\r\n", "output": ["1 1"]}, {"input": "6\r\n", "output": ["NO"]}, {"input": "7\r\n", "output": ["1 2"]}, {"input": "8\r\n", "output": ["NO"]}, {"input": "9\r\n", "output": ["1 3"]}, {"input": "10\r\n", "output": ["NO"]}, {"input": "11\r\n", "output": ["1 4"]}, {"input": "12\r\n", "output": ["NO"]}, {"input": "13\r\n", "output": ["1 5"]}, {"input": "14\r\n", "output": ["NO"]}, {"input": "15\r\n", "output": ["1 6"]}, {"input": "17\r\n", "output": ["1 7"]}, {"input": "18\r\n", "output": ["NO"]}, {"input": "20\r\n", "output": ["NO"]}, {"input": "21\r\n", "output": ["1 9"]}, {"input": "260158260522\r\n", "output": ["NO"]}, {"input": "250877914575\r\n", "output": ["1 125438957286"]}, {"input": "116602436426\r\n", "output": ["NO"]}, {"input": "540024979445\r\n", "output": ["1 270012489721"]}, {"input": "917861648772\r\n", "output": ["NO"]}, {"input": "962623690081\r\n", "output": ["1 481311845039"]}, {"input": "54433933447\r\n", "output": ["1 27216966722"]}, {"input": "16476190629\r\n", "output": ["1 8238095313"]}, {"input": "426262703497\r\n", "output": ["1 213131351747"]}, {"input": "723211047202\r\n", "output": ["NO"]}, {"input": "652509336151\r\n", "output": ["1 326254668074"]}, {"input": "215283472163\r\n", "output": ["1 107641736080"]}, {"input": "29617919\r\n", "output": ["1 14808958"]}, {"input": "7505295085\r\n", "output": ["1 3752647541"]}, {"input": "149890929717\r\n", "output": ["1 74945464857"]}, {"input": "185589070745\r\n", "output": ["1 92794535371"]}, {"input": "419450839\r\n", "output": ["1 209725418"]}, {"input": "519397679401\r\n", "output": ["1 259698839699"]}, {"input": "943447972637\r\n", "output": ["1 471723986317"]}, {"input": "54336309171\r\n", "output": ["1 27168154584"]}, {"input": "688373050717\r\n", "output": ["1 344186525357"]}, {"input": "156231653273\r\n", "output": ["1 78115826635"]}, {"input": "23744498401\r\n", "output": ["1 11872249199"]}, {"input": "768407398177\r\n", "output": ["1 384203699087"]}, {"input": "963761198401\r\n", "output": ["1 481880599199"]}, {"input": "240940299601\r\n", "output": ["1 120470149799"]}]
100
100
100
[{'input': '943447972637\r\n', 'output': ['1 471723986317']}, {'input': '16\r\n', 'output': ['NO']}, {'input': '4\r\n', 'output': ['NO']}, {'input': '540024979445\r\n', 'output': ['1 270012489721']}, {'input': '16476190629\r\n', 'output': ['1 8238095313']}]
[{'input': '8\r\n', 'output': ['NO']}, {'input': '54433933447\r\n', 'output': ['1 27216966722']}, {'input': '7\r\n', 'output': ['1 2']}, {'input': '917861648772\r\n', 'output': ['NO']}, {'input': '29617919\r\n', 'output': ['1 14808958']}]
[{'input': '15\r\n', 'output': ['1 6']}, {'input': '18\r\n', 'output': ['NO']}, {'input': '29617919\r\n', 'output': ['1 14808958']}, {'input': '260158260522\r\n', 'output': ['NO']}, {'input': '2\r\n', 'output': ['NO']}]
[{'input': '10\r\n', 'output': ['NO']}, {'input': '15\r\n', 'output': ['1 6']}, {'input': '652509336151\r\n', 'output': ['1 326254668074']}, {'input': '426262703497\r\n', 'output': ['1 213131351747']}, {'input': '19\r\n', 'output': ['1 8']}]
[{'input': '688373050717\r\n', 'output': ['1 344186525357']}, {'input': '54336309171\r\n', 'output': ['1 27168154584']}, {'input': '962623690081\r\n', 'output': ['1 481311845039']}, {'input': '7505295085\r\n', 'output': ['1 3752647541']}, {'input': '250877914575\r\n', 'output': ['1 125438957286']}]
100
100
100
100
100
100
100
100
100
83.33
75
75
75
75
50
259
100
96.666
70
["24 0", "24 1", "24 -1", "4 -7", "1 1"]
The only line contains two integers $$$n$$$ and $$$p$$$ ($$$1 \leq n \leq 10^9$$$, $$$-1000 \leq p \leq 1000$$$).
9e86d87ce5a75c6a982894af84eb4ba8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.util.StringTokenizer; public class TaskC { public static String doMain(Reader reader) throws IOException { MyReader in = new MyReader(reader); int n = in.nextInt(); int p = in.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; n - i * p >= i; ++i) { int count = check(n - p * i); if (count > i){ continue; } return i+""; } return "-1"; } private static int check(int n) { int answer = 0; while (n > 0) { answer += n % 2; n /= 2; } return answer; } public static void main(String[] args) throws IOException { String result = doMain(new InputStreamReader(System.in)); System.out.println(result); } static class MyReader { BufferedReader bf; StringTokenizer st; String last; MyReader(Reader reader) throws IOException { bf = new BufferedReader(reader); readNextLine(); } String nextToken() throws IOException { while (!st.hasMoreTokens()) { readNextLine(); } return st.nextToken(); } void readNextLine() throws IOException { last = bf.readLine(); if (last == null) last = ""; st = new StringTokenizer(last); } String nextLine() throws IOException { String s = last; readNextLine(); return s; } long nextLong() throws IOException { return Long.parseLong(nextToken()); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } int[] readIntArray(int n) throws IOException { int[] answer = new int[n]; for (int i = 0; i < n; ++i) { answer[i] = nextInt(); } return answer; } long[] readLongArray(int n) throws IOException { long[] answer = new long[n]; for (int i = 0; i < n; ++i) { answer[i] = nextLong(); } return answer; } double[] readDoubleArray(int n) throws IOException { double[] answer = new double[n]; for (int i = 0; i < n; ++i) { answer[i] = nextDouble(); } return answer; } } }
["2", "3", "4", "2", "-1"]
Java
Note$$$0$$$-binary numbers are just regular binary powers, thus in the first sample case we can represent $$$24 = (2^4 + 0) + (2^3 + 0)$$$.In the second sample case, we can represent $$$24 = (2^4 + 1) + (2^2 + 1) + (2^0 + 1)$$$.In the third sample case, we can represent $$$24 = (2^4 - 1) + (2^2 - 1) + (2^2 - 1) + (2^2 - 1)$$$. Note that repeated summands are allowed.In the fourth sample case, we can represent $$$4 = (2^4 - 7) + (2^1 - 7)$$$. Note that the second summand is negative, which is allowed.In the fifth sample case, no representation is possible.
If it is impossible to represent $$$n$$$ as the sum of any number of $$$p$$$-binary numbers, print a single integer $$$-1$$$. Otherwise, print the smallest possible number of summands.
Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer $$$p$$$ (which may be positive, negative, or zero). To combine their tastes, they invented $$$p$$$-binary numbers of the form $$$2^x + p$$$, where $$$x$$$ is a non-negative integer.For example, some $$$-9$$$-binary ("minus nine" binary) numbers are: $$$-8$$$ (minus eight), $$$7$$$ and $$$1015$$$ ($$$-8=2^0-9$$$, $$$7=2^4-9$$$, $$$1015=2^{10}-9$$$).The boys now use $$$p$$$-binary numbers to represent everything. They now face a problem: given a positive integer $$$n$$$, what's the smallest number of $$$p$$$-binary numbers (not necessarily distinct) they need to represent $$$n$$$ as their sum? It may be possible that representation is impossible altogether. Help them solve this problem.For example, if $$$p=0$$$ we can represent $$$7$$$ as $$$2^0 + 2^1 + 2^2$$$.And if $$$p=-9$$$ we can represent $$$7$$$ as one number $$$(2^4-9)$$$.Note that negative $$$p$$$-binary numbers are allowed to be in the sum (see the Notes section for an example).
[{"input": "24 0\r\n", "output": ["2"]}, {"input": "24 1\r\n", "output": ["3"]}, {"input": "24 -1\r\n", "output": ["4"]}, {"input": "4 -7\r\n", "output": ["2"]}, {"input": "1 1\r\n", "output": ["-1"]}, {"input": "10 7\r\n", "output": ["-1"]}, {"input": "3 -179\r\n", "output": ["5"]}, {"input": "12345678 -123\r\n", "output": ["12"]}, {"input": "1000000000 1000\r\n", "output": ["16"]}, {"input": "1 0\r\n", "output": ["1"]}, {"input": "1 -1\r\n", "output": ["1"]}, {"input": "536870912 0\r\n", "output": ["1"]}, {"input": "536870911 0\r\n", "output": ["29"]}, {"input": "1 -1000\r\n", "output": ["8"]}, {"input": "100500 -179\r\n", "output": ["8"]}, {"input": "1000000000 -1000\r\n", "output": ["14"]}, {"input": "536870812 1\r\n", "output": ["24"]}, {"input": "536870812 -1\r\n", "output": ["26"]}, {"input": "1 1000\r\n", "output": ["-1"]}, {"input": "1001 1000\r\n", "output": ["1"]}, {"input": "13 -987\r\n", "output": ["7"]}, {"input": "101 50\r\n", "output": ["-1"]}, {"input": "1001 500\r\n", "output": ["-1"]}, {"input": "13 6\r\n", "output": ["-1"]}, {"input": "5 2\r\n", "output": ["-1"]}, {"input": "67108838 -1\r\n", "output": ["26"]}, {"input": "11 5\r\n", "output": ["-1"]}, {"input": "19 6\r\n", "output": ["-1"]}, {"input": "21 10\r\n", "output": ["-1"]}, {"input": "2001 1000\r\n", "output": ["-1"]}, {"input": "17 8\r\n", "output": ["-1"]}, {"input": "3002 1000\r\n", "output": ["-1"]}, {"input": "332639425 -399\r\n", "output": ["13"]}, {"input": "9 8\r\n", "output": ["1"]}, {"input": "3 2\r\n", "output": ["1"]}, {"input": "678 169\r\n", "output": ["-1"]}, {"input": "2 1\r\n", "output": ["1"]}, {"input": "9 4\r\n", "output": ["-1"]}, {"input": "29 9\r\n", "output": ["-1"]}, {"input": "782 156\r\n", "output": ["-1"]}, {"input": "1999 999\r\n", "output": ["-1"]}, {"input": "47 23\r\n", "output": ["-1"]}, {"input": "3998 999\r\n", "output": ["-1"]}, {"input": "4 3\r\n", "output": ["1"]}, {"input": "746 248\r\n", "output": ["-1"]}, {"input": "2 -1000\r\n", "output": ["8"]}, {"input": "35 11\r\n", "output": ["-1"]}, {"input": "16777215 0\r\n", "output": ["24"]}]
100
100
100
[{'input': '24 1\r\n', 'output': ['3']}, {'input': '2 1\r\n', 'output': ['1']}, {'input': '536870812 1\r\n', 'output': ['24']}, {'input': '536870812 -1\r\n', 'output': ['26']}, {'input': '9 8\r\n', 'output': ['1']}]
[{'input': '24 1\r\n', 'output': ['3']}, {'input': '1 -1\r\n', 'output': ['1']}, {'input': '13 6\r\n', 'output': ['-1']}, {'input': '12345678 -123\r\n', 'output': ['12']}, {'input': '3 2\r\n', 'output': ['1']}]
[{'input': '1 1\r\n', 'output': ['-1']}, {'input': '17 8\r\n', 'output': ['-1']}, {'input': '1999 999\r\n', 'output': ['-1']}, {'input': '2 1\r\n', 'output': ['1']}, {'input': '67108838 -1\r\n', 'output': ['26']}]
[{'input': '10 7\r\n', 'output': ['-1']}, {'input': '1001 500\r\n', 'output': ['-1']}, {'input': '13 -987\r\n', 'output': ['7']}, {'input': '536870812 1\r\n', 'output': ['24']}, {'input': '3 2\r\n', 'output': ['1']}]
[{'input': '24 1\r\n', 'output': ['3']}, {'input': '782 156\r\n', 'output': ['-1']}, {'input': '1 -1000\r\n', 'output': ['8']}, {'input': '1 1\r\n', 'output': ['-1']}, {'input': '678 169\r\n', 'output': ['-1']}]
100
100
100
100
100
94.44
100
100
100
100
83.33
100
100
100
100
260
100
98.888
96.666
["4", "3"]
The only line contains a single integer $$$n$$$ ($$$1 \le n \le 10^6$$$), denoting the required number of vertices.
821409c1b9bdcd18c4dcf35dc5116501
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class E { static int[] tree; static void fill(int idx) { if (idx >= tree.length) return; fill(2 * idx); fill(2 * idx + 1); tree[idx] = 1; if (2 * idx < tree.length) tree[idx] += tree[2 * idx]; if (2 * idx + 1 < tree.length) tree[idx] += tree[2 * idx + 1]; } static boolean shouldAdd(int idx) { if (idx % 2 == 1) return true; while (idx % 2 == 0) { idx /= 2; } return tree[2 * idx] % 2 == 0; } static void add(int idx) { while (idx >= 1) { tree[idx]++; idx /= 2; } } public static void main(String[] args) throws IOException { MyScanner sc = new MyScanner(); PrintWriter out = new PrintWriter(System.out); int N = sc.nextInt(); int level = 0, got = 1; while (N >= got) { N -= got; level++; got *= 2; } tree = new int[1 << level]; fill(1); for (int i = tree.length - 1; i > 1 << (level-1); i--) { if (shouldAdd(i)) { add(i); N--; } } out.println(N == 0 || N == 1 ? 1 : 0); out.flush(); } static class MyScanner { private BufferedReader br; private StringTokenizer tokenizer; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(br.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()); } } }
["1", "0"]
Java
NoteIn the first example, this is the only tree that satisfies the conditions: In the second example, here are various trees that don't satisfy some condition:
Output the number of perfectly balanced striped binary search trees with $$$n$$$ vertices and distinct integer keys between $$$1$$$ and $$$n$$$, inclusive, modulo $$$998\,244\,353$$$.
Recall that a binary search tree is a rooted binary tree, whose nodes each store a key and each have at most two distinguished subtrees, left and right. The key in each node must be greater than any key stored in the left subtree, and less than any key stored in the right subtree.The depth of a vertex is the number of edges on the simple path from the vertex to the root. In particular, the depth of the root is $$$0$$$.Let's call a binary search tree perfectly balanced if there doesn't exist a binary search tree with the same number of vertices that has a strictly smaller sum of depths of its vertices.Let's call a binary search tree with integer keys striped if both of the following conditions are satisfied for every vertex $$$v$$$: If $$$v$$$ has a left subtree whose root is $$$u$$$, then the parity of the key of $$$v$$$ is different from the parity of the key of $$$u$$$. If $$$v$$$ has a right subtree whose root is $$$w$$$, then the parity of the key of $$$v$$$ is the same as the parity of the key of $$$w$$$. You are given a single integer $$$n$$$. Find the number of perfectly balanced striped binary search trees with $$$n$$$ vertices that have distinct integer keys between $$$1$$$ and $$$n$$$, inclusive. Output this number modulo $$$998\,244\,353$$$.
[{"input": "4\r\n", "output": ["1"]}, {"input": "3\r\n", "output": ["0"]}, {"input": "2\r\n", "output": ["1"]}, {"input": "5\r\n", "output": ["1"]}, {"input": "7\r\n", "output": ["0"]}, {"input": "8\r\n", "output": ["0"]}, {"input": "9\r\n", "output": ["1"]}, {"input": "1\r\n", "output": ["1"]}, {"input": "21\r\n", "output": ["1"]}, {"input": "14\r\n", "output": ["0"]}, {"input": "360561\r\n", "output": ["0"]}, {"input": "25\r\n", "output": ["0"]}, {"input": "85\r\n", "output": ["1"]}, {"input": "699049\r\n", "output": ["1"]}, {"input": "699047\r\n", "output": ["0"]}, {"input": "6\r\n", "output": ["0"]}, {"input": "10\r\n", "output": ["1"]}, {"input": "699050\r\n", "output": ["1"]}, {"input": "699048\r\n", "output": ["0"]}, {"input": "1000000\r\n", "output": ["0"]}, {"input": "786432\r\n", "output": ["0"]}, {"input": "750096\r\n", "output": ["0"]}, {"input": "10922\r\n", "output": ["1"]}, {"input": "699051\r\n", "output": ["0"]}, {"input": "87380\r\n", "output": ["1"]}, {"input": "308545\r\n", "output": ["0"]}, {"input": "16\r\n", "output": ["0"]}, {"input": "20\r\n", "output": ["1"]}, {"input": "170\r\n", "output": ["1"]}, {"input": "22\r\n", "output": ["0"]}, {"input": "84\r\n", "output": ["1"]}, {"input": "174762\r\n", "output": ["1"]}, {"input": "341\r\n", "output": ["1"]}, {"input": "17\r\n", "output": ["0"]}, {"input": "530259\r\n", "output": ["0"]}, {"input": "181407\r\n", "output": ["0"]}, {"input": "5461\r\n", "output": ["1"]}, {"input": "21844\r\n", "output": ["1"]}, {"input": "472032\r\n", "output": ["0"]}, {"input": "325193\r\n", "output": ["0"]}, {"input": "43689\r\n", "output": ["1"]}, {"input": "43690\r\n", "output": ["1"]}, {"input": "31\r\n", "output": ["0"]}, {"input": "524288\r\n", "output": ["0"]}, {"input": "546029\r\n", "output": ["0"]}, {"input": "5460\r\n", "output": ["1"]}, {"input": "26\r\n", "output": ["0"]}, {"input": "682\r\n", "output": ["1"]}, {"input": "621012\r\n", "output": ["0"]}, {"input": "19\r\n", "output": ["0"]}, {"input": "334846\r\n", "output": ["0"]}, {"input": "549836\r\n", "output": ["0"]}, {"input": "797049\r\n", "output": ["0"]}, {"input": "174761\r\n", "output": ["1"]}, {"input": "320507\r\n", "output": ["0"]}, {"input": "699046\r\n", "output": ["0"]}, {"input": "681\r\n", "output": ["1"]}, {"input": "28\r\n", "output": ["0"]}, {"input": "87381\r\n", "output": ["1"]}, {"input": "27\r\n", "output": ["0"]}, {"input": "503375\r\n", "output": ["0"]}, {"input": "557479\r\n", "output": ["0"]}, {"input": "11\r\n", "output": ["0"]}, {"input": "13156\r\n", "output": ["0"]}, {"input": "349525\r\n", "output": ["1"]}, {"input": "10921\r\n", "output": ["1"]}, {"input": "259060\r\n", "output": ["0"]}, {"input": "21845\r\n", "output": ["1"]}, {"input": "175466\r\n", "output": ["0"]}, {"input": "796867\r\n", "output": ["0"]}, {"input": "527730\r\n", "output": ["0"]}, {"input": "737480\r\n", "output": ["0"]}, {"input": "740812\r\n", "output": ["0"]}, {"input": "631649\r\n", "output": ["0"]}, {"input": "1365\r\n", "output": ["1"]}, {"input": "581472\r\n", "output": ["0"]}, {"input": "622262\r\n", "output": ["0"]}, {"input": "42\r\n", "output": ["1"]}, {"input": "629191\r\n", "output": ["0"]}, {"input": "12\r\n", "output": ["0"]}, {"input": "2730\r\n", "output": ["1"]}, {"input": "988727\r\n", "output": ["0"]}, {"input": "999999\r\n", "output": ["0"]}, {"input": "169\r\n", "output": ["1"]}]
100
100
100
[{'input': '740812\r\n', 'output': ['0']}, {'input': '17\r\n', 'output': ['0']}, {'input': '549836\r\n', 'output': ['0']}, {'input': '796867\r\n', 'output': ['0']}, {'input': '7\r\n', 'output': ['0']}]
[{'input': '174762\r\n', 'output': ['1']}, {'input': '87380\r\n', 'output': ['1']}, {'input': '28\r\n', 'output': ['0']}, {'input': '43690\r\n', 'output': ['1']}, {'input': '360561\r\n', 'output': ['0']}]
[{'input': '16\r\n', 'output': ['0']}, {'input': '341\r\n', 'output': ['1']}, {'input': '175466\r\n', 'output': ['0']}, {'input': '174762\r\n', 'output': ['1']}, {'input': '20\r\n', 'output': ['1']}]
[{'input': '2730\r\n', 'output': ['1']}, {'input': '5460\r\n', 'output': ['1']}, {'input': '87381\r\n', 'output': ['1']}, {'input': '174761\r\n', 'output': ['1']}, {'input': '999999\r\n', 'output': ['0']}]
[{'input': '22\r\n', 'output': ['0']}, {'input': '988727\r\n', 'output': ['0']}, {'input': '699051\r\n', 'output': ['0']}, {'input': '11\r\n', 'output': ['0']}, {'input': '259060\r\n', 'output': ['0']}]
100
100
100
100
100
100
100
100
100
100
91.67
100
100
100
91.67
261
100
100
96.668
["1 3", "10 15"]
The only line contains two integers a, b (1 ≀ a ≀ b ≀ 106) β€” the first and the last number typed by Max.
1193de6f80a9feee8522a404d16425b9
/*package whatever //do not write package name here */ import java.io.*; import java.util.*; import java.math.*; public class S { public static void main (String[] args) { Scanner in=new Scanner(System.in); int a=in.nextInt(); int b=in.nextInt(); Map<Character,Integer> m= new HashMap<>(); m.put('0',6);m.put('1',2);m.put('2',5);m.put('3',5);m.put('4',4);m.put('5',5);m.put('6',6);m.put('7',3); m.put('8',7);m.put('9',6); int r=0; for(int i=a;i<=b;i++) { String s=String.valueOf(i); for(int j=0;j<s.length();j++) { r=r+m.get(s.charAt(j)); } } System.out.println(r); } }
["12", "39"]
Java
null
Print the only integer a β€” the total number of printed segments.
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators (https://en.wikipedia.org/wiki/Seven-segment_display). Max starts to type all the values from a to b. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.For example if a = 1 and b = 3 then at first the calculator will print 2 segments, then β€” 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.
[{"input": "1 3\r\n", "output": ["12"]}, {"input": "10 15\r\n", "output": ["39"]}, {"input": "1 100\r\n", "output": ["928"]}, {"input": "100 10000\r\n", "output": ["188446"]}, {"input": "213 221442\r\n", "output": ["5645356"]}, {"input": "1 1000000\r\n", "output": ["28733372"]}, {"input": "1000000 1000000\r\n", "output": ["38"]}, {"input": "222145 353252\r\n", "output": ["3860750"]}, {"input": "2 1000000\r\n", "output": ["28733370"]}, {"input": "1 999999\r\n", "output": ["28733334"]}, {"input": "192 200\r\n", "output": ["122"]}]
100
100
100
[{'input': '2 1000000\r\n', 'output': ['28733370']}, {'input': '1 1000000\r\n', 'output': ['28733372']}, {'input': '100 10000\r\n', 'output': ['188446']}, {'input': '222145 353252\r\n', 'output': ['3860750']}, {'input': '1 999999\r\n', 'output': ['28733334']}]
[{'input': '10 15\r\n', 'output': ['39']}, {'input': '1 1000000\r\n', 'output': ['28733372']}, {'input': '2 1000000\r\n', 'output': ['28733370']}, {'input': '213 221442\r\n', 'output': ['5645356']}, {'input': '1 999999\r\n', 'output': ['28733334']}]
[{'input': '1 1000000\r\n', 'output': ['28733372']}, {'input': '1000000 1000000\r\n', 'output': ['38']}, {'input': '213 221442\r\n', 'output': ['5645356']}, {'input': '10 15\r\n', 'output': ['39']}, {'input': '1 100\r\n', 'output': ['928']}]
[{'input': '100 10000\r\n', 'output': ['188446']}, {'input': '222145 353252\r\n', 'output': ['3860750']}, {'input': '1 3\r\n', 'output': ['12']}, {'input': '192 200\r\n', 'output': ['122']}, {'input': '213 221442\r\n', 'output': ['5645356']}]
[{'input': '1 999999\r\n', 'output': ['28733334']}, {'input': '192 200\r\n', 'output': ['122']}, {'input': '1 1000000\r\n', 'output': ['28733372']}, {'input': '1000000 1000000\r\n', 'output': ['38']}, {'input': '222145 353252\r\n', 'output': ['3860750']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
262
100
100
100
["3 2", "3 3"]
The input data contains two space-separated positive integer numbers n and h (n ≀ 35, h ≀ n).
faf12a603d0c27f8be6bf6b02531a931
//package com.company; import java.io.*; public class Main { public static void main(String[] args)throws IOException{ BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in)); String[] line = buffer.readLine().split(" "); int nodes = Integer.parseInt(line[0]); int height = Integer.parseInt(line[1]); int n = 36; long[][] dynamic = new long[n][n]; //fill first column with 1s, creates buffer for(int i = 0 ; i < n; i++) dynamic[0][i] = 1; //count all the trees for(int i = 1; i < n; i++){ for(int j = 1; j < n; j++){ for(int k = 0; k < i ;k++) dynamic[i][j] += dynamic[k][j - 1] * dynamic[i - k - 1][j - 1]; } } //the amount of trees to jump System.out.println(dynamic[nodes][35] - dynamic[nodes][height - 1]); } }
["5", "4"]
Java
null
Output one number β€” the answer to the problem. It is guaranteed that it does not exceed 9Β·1018.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong β€” the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure β€” and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus β€” Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem Β«heightΒ» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
[{"input": "3 2\r\n", "output": ["5"]}, {"input": "3 3\r\n", "output": ["4"]}, {"input": "1 1\r\n", "output": ["1"]}, {"input": "2 1\r\n", "output": ["2"]}, {"input": "2 2\r\n", "output": ["2"]}, {"input": "27 11\r\n", "output": ["61162698256896"]}, {"input": "32 27\r\n", "output": ["22643872890880"]}, {"input": "4 1\r\n", "output": ["14"]}, {"input": "9 1\r\n", "output": ["4862"]}, {"input": "33 4\r\n", "output": ["212336130412243110"]}, {"input": "4 4\r\n", "output": ["8"]}, {"input": "8 5\r\n", "output": ["1336"]}, {"input": "12 8\r\n", "output": ["127200"]}, {"input": "15 5\r\n", "output": ["9694844"]}, {"input": "19 18\r\n", "output": ["2424832"]}, {"input": "23 17\r\n", "output": ["19649347584"]}, {"input": "27 15\r\n", "output": ["25162319484928"]}, {"input": "29 14\r\n", "output": ["577801978306560"]}, {"input": "33 18\r\n", "output": ["54307238601375744"]}, {"input": "7 7\r\n", "output": ["64"]}, {"input": "23 21\r\n", "output": ["275251200"]}, {"input": "7 3\r\n", "output": ["429"]}, {"input": "21 18\r\n", "output": ["211156992"]}, {"input": "21 12\r\n", "output": ["12153990144"]}, {"input": "35 13\r\n", "output": ["2690352397519398400"]}, {"input": "19 2\r\n", "output": ["1767263190"]}, {"input": "33 26\r\n", "output": ["434871797284864"]}, {"input": "16 9\r\n", "output": ["25607552"]}, {"input": "16 14\r\n", "output": ["1032192"]}, {"input": "10 2\r\n", "output": ["16796"]}, {"input": "33 17\r\n", "output": ["75307983624118272"]}, {"input": "27 25\r\n", "output": ["6081740800"]}, {"input": "20 14\r\n", "output": ["1094473728"]}, {"input": "16 11\r\n", "output": ["11819008"]}, {"input": "10 10\r\n", "output": ["512"]}, {"input": "4 3\r\n", "output": ["14"]}, {"input": "33 21\r\n", "output": ["14830955929665536"]}, {"input": "24 20\r\n", "output": ["8171945984"]}, {"input": "30 16\r\n", "output": ["1375710400053248"]}, {"input": "9 4\r\n", "output": ["4862"]}, {"input": "16 5\r\n", "output": ["35357670"]}, {"input": "22 22\r\n", "output": ["2097152"]}, {"input": "28 23\r\n", "output": ["739948625920"]}, {"input": "34 1\r\n", "output": ["812944042149730764"]}, {"input": "7 4\r\n", "output": ["428"]}, {"input": "14 11\r\n", "output": ["488448"]}, {"input": "35 1\r\n", "output": ["3116285494907301262"]}, {"input": "35 35\r\n", "output": ["17179869184"]}]
100
100
100
[{'input': '23 21\r\n', 'output': ['275251200']}, {'input': '21 12\r\n', 'output': ['12153990144']}, {'input': '24 20\r\n', 'output': ['8171945984']}, {'input': '2 1\r\n', 'output': ['2']}, {'input': '3 3\r\n', 'output': ['4']}]
[{'input': '4 4\r\n', 'output': ['8']}, {'input': '28 23\r\n', 'output': ['739948625920']}, {'input': '21 12\r\n', 'output': ['12153990144']}, {'input': '3 3\r\n', 'output': ['4']}, {'input': '7 7\r\n', 'output': ['64']}]
[{'input': '22 22\r\n', 'output': ['2097152']}, {'input': '4 3\r\n', 'output': ['14']}, {'input': '14 11\r\n', 'output': ['488448']}, {'input': '27 25\r\n', 'output': ['6081740800']}, {'input': '21 18\r\n', 'output': ['211156992']}]
[{'input': '34 1\r\n', 'output': ['812944042149730764']}, {'input': '4 4\r\n', 'output': ['8']}, {'input': '9 4\r\n', 'output': ['4862']}, {'input': '23 21\r\n', 'output': ['275251200']}, {'input': '33 4\r\n', 'output': ['212336130412243110']}]
[{'input': '27 15\r\n', 'output': ['25162319484928']}, {'input': '4 1\r\n', 'output': ['14']}, {'input': '32 27\r\n', 'output': ['22643872890880']}, {'input': '2 1\r\n', 'output': ['2']}, {'input': '20 14\r\n', 'output': ['1094473728']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
263
100
100
100
["2 3", "3 1"]
In the only line you are given two integers a, b (0 ≀ a, b ≀ 100) β€” the number of even and odd steps, accordingly.
ec5e3b3f5ee6a13eaf01b9a9a66ff037
import java.util.*; public class A761 { public static void main(String []args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m =sc.nextInt(); if(Math.abs(m-n) == 1 || (m+n!=0 && m==n) ) { System.out.println("YES"); } else { System.out.println("NO"); } } }
["YES", "NO"]
Java
NoteIn the first example one of suitable intervals is from 1 to 5. The interval contains two even stepsΒ β€” 2 and 4, and three odd: 1, 3 and 5.
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
On her way to programming school tiger Dasha faced her first test β€” a huge staircase! The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values β€” the number of steps with even and odd numbers. You need to check whether there is an interval of steps from the l-th to the r-th (1 ≀ l ≀ r), for which values that Dasha has found are correct.
[{"input": "2 3\r\n", "output": ["YES"]}, {"input": "3 1\r\n", "output": ["NO"]}, {"input": "5 4\r\n", "output": ["YES"]}, {"input": "9 9\r\n", "output": ["YES"]}, {"input": "85 95\r\n", "output": ["NO"]}, {"input": "0 1\r\n", "output": ["YES"]}, {"input": "89 25\r\n", "output": ["NO"]}, {"input": "74 73\r\n", "output": ["YES"]}, {"input": "62 39\r\n", "output": ["NO"]}, {"input": "57 57\r\n", "output": ["YES"]}, {"input": "100 99\r\n", "output": ["YES"]}, {"input": "0 0\r\n", "output": ["NO"]}, {"input": "98 100\r\n", "output": ["NO"]}, {"input": "99 100\r\n", "output": ["YES"]}, {"input": "1 0\r\n", "output": ["YES"]}, {"input": "100 0\r\n", "output": ["NO"]}, {"input": "0 100\r\n", "output": ["NO"]}, {"input": "100 98\r\n", "output": ["NO"]}, {"input": "100 100\r\n", "output": ["YES"]}, {"input": "0 5\r\n", "output": ["NO"]}, {"input": "2 2\r\n", "output": ["YES"]}]
100
100
100
[{'input': '100 98\r\n', 'output': ['NO']}, {'input': '100 100\r\n', 'output': ['YES']}, {'input': '0 1\r\n', 'output': ['YES']}, {'input': '99 100\r\n', 'output': ['YES']}, {'input': '0 0\r\n', 'output': ['NO']}]
[{'input': '0 100\r\n', 'output': ['NO']}, {'input': '100 0\r\n', 'output': ['NO']}, {'input': '9 9\r\n', 'output': ['YES']}, {'input': '100 98\r\n', 'output': ['NO']}, {'input': '3 1\r\n', 'output': ['NO']}]
[{'input': '1 0\r\n', 'output': ['YES']}, {'input': '98 100\r\n', 'output': ['NO']}, {'input': '0 0\r\n', 'output': ['NO']}, {'input': '9 9\r\n', 'output': ['YES']}, {'input': '100 98\r\n', 'output': ['NO']}]
[{'input': '0 5\r\n', 'output': ['NO']}, {'input': '100 100\r\n', 'output': ['YES']}, {'input': '5 4\r\n', 'output': ['YES']}, {'input': '98 100\r\n', 'output': ['NO']}, {'input': '100 0\r\n', 'output': ['NO']}]
[{'input': '98 100\r\n', 'output': ['NO']}, {'input': '2 2\r\n', 'output': ['YES']}, {'input': '1 0\r\n', 'output': ['YES']}, {'input': '0 5\r\n', 'output': ['NO']}, {'input': '2 3\r\n', 'output': ['YES']}]
100
100
100
100
100
100
100
100
100
100
100
66.67
100
83.33
83.33
264
100
100
86.666
["3+2+1", "1+1+3+1+3", "2"]
The first line contains a non-empty string s β€” the sum Xenia needs to count. String s contains no spaces. It only contains digits and characters "+". Besides, string s is a correct sum of numbers 1, 2 and 3. String s is at most 100 characters long.
76c7312733ef9d8278521cf09d3ccbc8
import java.util.PriorityQueue; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner lector = new Scanner(System.in); PriorityQueue<Integer> list = new PriorityQueue(); String s = lector.next(); int x; for(char c:s.toCharArray()){ if(c!='+'){ list.add(c-48); } } x = list.size(); for (int i = 0; i < (x-1); i++) { System.out.print(list.poll()+"+"); } System.out.println(list.poll()); } } // 1509316386944
["1+2+3", "1+1+1+3+3", "2"]
Java
null
Print the new sum that Xenia can count.
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.
[{"input": "3+2+1\r\n", "output": ["1+2+3"]}, {"input": "1+1+3+1+3\r\n", "output": ["1+1+1+3+3"]}, {"input": "2\r\n", "output": ["2"]}, {"input": "2+2+1+1+3\r\n", "output": ["1+1+2+2+3"]}, {"input": "2+1+2+2+2+3+1+3+1+2\r\n", "output": ["1+1+1+2+2+2+2+2+3+3"]}, {"input": "1+2+1+2+2+2+2+1+3+3\r\n", "output": ["1+1+1+2+2+2+2+2+3+3"]}, {"input": "2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1\r\n", "output": ["1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"]}, {"input": "1\r\n", "output": ["1"]}, {"input": "2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1\r\n", "output": ["1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3"]}, {"input": "2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2\r\n", "output": ["1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3"]}, {"input": "3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3\r\n", "output": ["1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"]}, {"input": "3\r\n", "output": ["3"]}, {"input": "1+1\r\n", "output": ["1+1"]}, {"input": "1+2\r\n", "output": ["1+2"]}, {"input": "1+3\r\n", "output": ["1+3"]}, {"input": "2+1\r\n", "output": ["1+2"]}, {"input": "2+2\r\n", "output": ["2+2"]}, {"input": "2+3\r\n", "output": ["2+3"]}, {"input": "3+1\r\n", "output": ["1+3"]}, {"input": "3+2\r\n", "output": ["2+3"]}, {"input": "3+3\r\n", "output": ["3+3"]}]
100
100
100
[{'input': '2+2+1+1+3\r\n', 'output': ['1+1+2+2+3']}, {'input': '3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3\r\n', 'output': ['1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3']}, {'input': '3+2\r\n', 'output': ['2+3']}, {'input': '3+1\r\n', 'output': ['1+3']}, {'input': '2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1\r\n', 'output': ['1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3']}]
[{'input': '1\r\n', 'output': ['1']}, {'input': '2+2+1+1+3\r\n', 'output': ['1+1+2+2+3']}, {'input': '2+2\r\n', 'output': ['2+2']}, {'input': '1+1+3+1+3\r\n', 'output': ['1+1+1+3+3']}, {'input': '3+2+1\r\n', 'output': ['1+2+3']}]
[{'input': '3+2+1\r\n', 'output': ['1+2+3']}, {'input': '3\r\n', 'output': ['3']}, {'input': '1\r\n', 'output': ['1']}, {'input': '2+1+2+2+2+3+1+3+1+2\r\n', 'output': ['1+1+1+2+2+2+2+2+3+3']}, {'input': '2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1\r\n', 'output': ['1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3']}]
[{'input': '2+2\r\n', 'output': ['2+2']}, {'input': '3+2+1\r\n', 'output': ['1+2+3']}, {'input': '2+1\r\n', 'output': ['1+2']}, {'input': '2+2+1+1+3\r\n', 'output': ['1+1+2+2+3']}, {'input': '1+3\r\n', 'output': ['1+3']}]
[{'input': '3+1\r\n', 'output': ['1+3']}, {'input': '2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2\r\n', 'output': ['1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3']}, {'input': '2\r\n', 'output': ['2']}, {'input': '3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3\r\n', 'output': ['1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3']}, {'input': '3+2+1\r\n', 'output': ['1+2+3']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
265
100
100
100
["18 2", "9 10", "1000000000000 5", "1000000000000 499999999999"]
The first (and the only) line of input contains two integers n and k (1 ≀ n, k ≀ 1012), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas.
405a70c3b3f1561a9546910ab3fb5c80
import java.io.*; import java.util.*; public class Training { public static void main(String[] args) throws IOException { Scanner input = new Scanner(System.in); long n = input.nextLong(),k= input.nextLong(); long a = n/2/(k+1); long b = a *k ; System.out.println(a +" "+b+" "+(n-a-b)); } // end main }
["3 6 9", "0 0 9", "83333333333 416666666665 500000000002", "1 499999999999 500000000000"]
Java
null
Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.
There are n students who have taken part in an olympiad. Now it's time to award the students.Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners.You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.
[{"input": "18 2\r\n", "output": ["3 6 9"]}, {"input": "9 10\r\n", "output": ["0 0 9"]}, {"input": "1000000000000 5\r\n", "output": ["83333333333 416666666665 500000000002"]}, {"input": "1000000000000 499999999999\r\n", "output": ["1 499999999999 500000000000"]}, {"input": "1 1\r\n", "output": ["0 0 1"]}, {"input": "5 3\r\n", "output": ["0 0 5"]}, {"input": "42 6\r\n", "output": ["3 18 21"]}, {"input": "1000000000000 1000\r\n", "output": ["499500499 499500499000 500000000501"]}, {"input": "999999999999 999999\r\n", "output": ["499999 499998500001 500000999999"]}, {"input": "732577309725 132613\r\n", "output": ["2762066 366285858458 366288689201"]}, {"input": "152326362626 15\r\n", "output": ["4760198832 71402982480 76163181314"]}, {"input": "2 1\r\n", "output": ["0 0 2"]}, {"input": "1000000000000 500000000000\r\n", "output": ["0 0 1000000000000"]}, {"input": "100000000000 50000000011\r\n", "output": ["0 0 100000000000"]}, {"input": "1000000000000 32416187567\r\n", "output": ["15 486242813505 513757186480"]}, {"input": "1000000000000 7777777777\r\n", "output": ["64 497777777728 502222222208"]}, {"input": "1000000000000 77777777777\r\n", "output": ["6 466666666662 533333333332"]}, {"input": "100000000000 578485652\r\n", "output": ["86 49749766072 50250233842"]}, {"input": "999999999999 10000000000\r\n", "output": ["49 490000000000 509999999950"]}, {"input": "7 2\r\n", "output": ["1 2 4"]}, {"input": "420506530901 752346673804\r\n", "output": ["0 0 420506530901"]}, {"input": "960375521135 321688347872\r\n", "output": ["1 321688347872 638687173262"]}, {"input": "1000000000000 1000000000000\r\n", "output": ["0 0 1000000000000"]}, {"input": "99999999999 15253636363\r\n", "output": ["3 45760909089 54239090907"]}, {"input": "19 2\r\n", "output": ["3 6 10"]}, {"input": "999999999999 1000000000000\r\n", "output": ["0 0 999999999999"]}, {"input": "1000000000000 5915587276\r\n", "output": ["84 496909331184 503090668732"]}, {"input": "1000000000000 1000000006\r\n", "output": ["499 499000002994 500999996507"]}, {"input": "549755813888 134217728\r\n", "output": ["2047 274743689216 275012122625"]}, {"input": "99999999999 3333333\r\n", "output": ["14999 49996661667 50003323333"]}, {"input": "9 1\r\n", "output": ["2 2 5"]}, {"input": "1000000000000 250000000001\r\n", "output": ["1 250000000001 749999999998"]}, {"input": "5 1\r\n", "output": ["1 1 3"]}, {"input": "3107038133 596040207\r\n", "output": ["2 1192080414 1914957717"]}, {"input": "1000000000000 73786977\r\n", "output": ["6776 499980556152 500019437072"]}, {"input": "1000000000000 73786976\r\n", "output": ["6776 499980549376 500019443848"]}, {"input": "1000000000000 25000000000\r\n", "output": ["19 475000000000 524999999981"]}, {"input": "216929598879 768233755932\r\n", "output": ["0 0 216929598879"]}, {"input": "1000000000000 250000000000\r\n", "output": ["1 250000000000 749999999999"]}, {"input": "1000000000000 100000000001\r\n", "output": ["4 400000000004 599999999992"]}, {"input": "100000000000 100000000001\r\n", "output": ["0 0 100000000000"]}, {"input": "900000000000 100281800001\r\n", "output": ["4 401127200004 498872799992"]}, {"input": "906028900004 109123020071\r\n", "output": ["4 436492080284 469536819716"]}, {"input": "1000000000000 1\r\n", "output": ["250000000000 250000000000 500000000000"]}]
100
100
100
[{'input': '42 6\r\n', 'output': ['3 18 21']}, {'input': '1000000000000 1000000006\r\n', 'output': ['499 499000002994 500999996507']}, {'input': '1000000000000 100000000001\r\n', 'output': ['4 400000000004 599999999992']}, {'input': '420506530901 752346673804\r\n', 'output': ['0 0 420506530901']}, {'input': '999999999999 1000000000000\r\n', 'output': ['0 0 999999999999']}]
[{'input': '1000000000000 250000000001\r\n', 'output': ['1 250000000001 749999999998']}, {'input': '549755813888 134217728\r\n', 'output': ['2047 274743689216 275012122625']}, {'input': '420506530901 752346673804\r\n', 'output': ['0 0 420506530901']}, {'input': '1000000000000 32416187567\r\n', 'output': ['15 486242813505 513757186480']}, {'input': '1000000000000 250000000000\r\n', 'output': ['1 250000000000 749999999999']}]
[{'input': '100000000000 578485652\r\n', 'output': ['86 49749766072 50250233842']}, {'input': '732577309725 132613\r\n', 'output': ['2762066 366285858458 366288689201']}, {'input': '1000000000000 250000000001\r\n', 'output': ['1 250000000001 749999999998']}, {'input': '1000000000000 1000\r\n', 'output': ['499500499 499500499000 500000000501']}, {'input': '19 2\r\n', 'output': ['3 6 10']}]
[{'input': '1 1\r\n', 'output': ['0 0 1']}, {'input': '99999999999 15253636363\r\n', 'output': ['3 45760909089 54239090907']}, {'input': '1000000000000 7777777777\r\n', 'output': ['64 497777777728 502222222208']}, {'input': '999999999999 1000000000000\r\n', 'output': ['0 0 999999999999']}, {'input': '99999999999 3333333\r\n', 'output': ['14999 49996661667 50003323333']}]
[{'input': '99999999999 15253636363\r\n', 'output': ['3 45760909089 54239090907']}, {'input': '3107038133 596040207\r\n', 'output': ['2 1192080414 1914957717']}, {'input': '999999999999 10000000000\r\n', 'output': ['49 490000000000 509999999950']}, {'input': '100000000000 578485652\r\n', 'output': ['86 49749766072 50250233842']}, {'input': '960375521135 321688347872\r\n', 'output': ['1 321688347872 638687173262']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
266
100
100
100
["5", "12"]
The first line of the input contains an integer x (1 ≀ x ≀ 1 000 000)Β β€” The coordinate of the friend's house.
4b3d65b1b593829e92c852be213922b6
import java.util.Scanner; public class Slonik { public static void main(String[] args){ Scanner scan = new Scanner(System.in); int input = scan.nextInt(); float min = input / 5f; System.out.println((int)Math.ceil(min)); } }
["1", "3"]
Java
NoteIn the first sample the elephant needs to make one step of length 5 to reach the point x.In the second sample the elephant can get to point x if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach x in less than three moves.
Print the minimum number of steps that elephant needs to make to get from point 0 to point x.
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x &gt; 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
[{"input": "5\r\n", "output": ["1"]}, {"input": "12\r\n", "output": ["3"]}, {"input": "999999\r\n", "output": ["200000"]}, {"input": "41\r\n", "output": ["9"]}, {"input": "1000000\r\n", "output": ["200000"]}, {"input": "1\r\n", "output": ["1"]}, {"input": "2\r\n", "output": ["1"]}, {"input": "3\r\n", "output": ["1"]}, {"input": "4\r\n", "output": ["1"]}, {"input": "534204\r\n", "output": ["106841"]}, {"input": "469569\r\n", "output": ["93914"]}, {"input": "502877\r\n", "output": ["100576"]}, {"input": "942212\r\n", "output": ["188443"]}, {"input": "97\r\n", "output": ["20"]}, {"input": "53\r\n", "output": ["11"]}, {"input": "89\r\n", "output": ["18"]}, {"input": "574\r\n", "output": ["115"]}, {"input": "716\r\n", "output": ["144"]}, {"input": "729\r\n", "output": ["146"]}, {"input": "8901\r\n", "output": ["1781"]}, {"input": "3645\r\n", "output": ["729"]}, {"input": "4426\r\n", "output": ["886"]}, {"input": "46573\r\n", "output": ["9315"]}, {"input": "86380\r\n", "output": ["17276"]}, {"input": "94190\r\n", "output": ["18838"]}, {"input": "999990\r\n", "output": ["199998"]}, {"input": "999991\r\n", "output": ["199999"]}, {"input": "999992\r\n", "output": ["199999"]}, {"input": "999993\r\n", "output": ["199999"]}, {"input": "999994\r\n", "output": ["199999"]}, {"input": "999995\r\n", "output": ["199999"]}, {"input": "999996\r\n", "output": ["200000"]}, {"input": "999997\r\n", "output": ["200000"]}, {"input": "999998\r\n", "output": ["200000"]}]
100
100
100
[{'input': '999998\r\n', 'output': ['200000']}, {'input': '999995\r\n', 'output': ['199999']}, {'input': '999996\r\n', 'output': ['200000']}, {'input': '3\r\n', 'output': ['1']}, {'input': '999991\r\n', 'output': ['199999']}]
[{'input': '1\r\n', 'output': ['1']}, {'input': '8901\r\n', 'output': ['1781']}, {'input': '3\r\n', 'output': ['1']}, {'input': '2\r\n', 'output': ['1']}, {'input': '999994\r\n', 'output': ['199999']}]
[{'input': '502877\r\n', 'output': ['100576']}, {'input': '999998\r\n', 'output': ['200000']}, {'input': '53\r\n', 'output': ['11']}, {'input': '999996\r\n', 'output': ['200000']}, {'input': '1\r\n', 'output': ['1']}]
[{'input': '534204\r\n', 'output': ['106841']}, {'input': '999999\r\n', 'output': ['200000']}, {'input': '2\r\n', 'output': ['1']}, {'input': '999993\r\n', 'output': ['199999']}, {'input': '5\r\n', 'output': ['1']}]
[{'input': '999992\r\n', 'output': ['199999']}, {'input': '729\r\n', 'output': ['146']}, {'input': '999999\r\n', 'output': ['200000']}, {'input': '53\r\n', 'output': ['11']}, {'input': '3\r\n', 'output': ['1']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
267
100
100
100
["5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3", "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5"]
The first line contains a single integer n (1 ≀ n ≀ 5). Next n lines contain four integers each, describing a single rectangle: x1, y1, x2, y2 (0 ≀ x1 &lt; x2 ≀ 31400, 0 ≀ y1 &lt; y2 ≀ 31400) β€” x1 and x2 are x-coordinates of the left and right edges of the rectangle, and y1 and y2 are y-coordinates of the bottom and top edges of the rectangle. No two rectangles overlap (that is, there are no points that belong to the interior of more than one rectangle).
f63fc2d97fd88273241fce206cc217f2
import java.util.Scanner; public class Main { private static final int MAXN = 4000000; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] areas = new int[n]; int left = MAXN, right = 0, top = MAXN, bottom = 0; for(int i = 0; i < n; i++) { int x1, y1, x2, y2; x1 = scanner.nextInt(); y1 = scanner.nextInt(); x2 = scanner.nextInt(); y2 = scanner.nextInt(); areas[i] = (x2 - x1) * (y2 - y1); left = Math.min(x1, left); right = Math.max(x2, right); top = Math.min(y1, top); bottom = Math.max(y2, bottom); } int total = (right - left) * (bottom - top); int result = 0; for(int i = 0; i < n; i++) { result += areas[i]; } if((total == result) && ((right - left) == (bottom - top))) { System.out.println("YES"); } else { System.out.println("NO"); } } }
["YES", "NO"]
Java
null
In a single line print "YES", if the given rectangles form a square, or "NO" otherwise.
You are given n rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the Ox and Oy axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle). Your task is to determine if the rectangles form a square. In other words, determine if the set of points inside or on the border of at least one rectangle is precisely equal to the set of points inside or on the border of some square.
[{"input": "5\r\n0 0 2 3\r\n0 3 3 5\r\n2 0 5 2\r\n3 2 5 5\r\n2 2 3 3\r\n", "output": ["YES"]}, {"input": "4\r\n0 0 2 3\r\n0 3 3 5\r\n2 0 5 2\r\n3 2 5 5\r\n", "output": ["NO"]}, {"input": "5\r\n0 0 10000 20000\r\n10000 0 15000 19999\r\n10000 19999 14999 20000\r\n0 20000 15000 31400\r\n15000 0 31400 31400\r\n", "output": ["NO"]}, {"input": "5\r\n0 0 10000 20000\r\n10000 0 15000 19999\r\n10000 19999 15000 20000\r\n0 20000 15000 31400\r\n15000 0 31400 31400\r\n", "output": ["YES"]}, {"input": "5\r\n10359 859 28918 4384\r\n2895 26520 28918 26882\r\n2895 26424 28918 26520\r\n2895 859 10359 4384\r\n2895 4384 28918 26424\r\n", "output": ["YES"]}, {"input": "5\r\n12750 0 25688 1\r\n1094 0 12750 1\r\n0 0 956 1\r\n956 0 1094 1\r\n25688 0 31400 1\r\n", "output": ["NO"]}, {"input": "4\r\n18006 16484 25725 31400\r\n0 0 31400 16484\r\n29563 16484 31400 31400\r\n25725 16484 29563 31400\r\n", "output": ["NO"]}, {"input": "1\r\n0 0 31400 31400\r\n", "output": ["YES"]}, {"input": "2\r\n0 0 31400 13313\r\n0 13313 31400 31400\r\n", "output": ["YES"]}, {"input": "3\r\n0 9388 31400 31400\r\n26020 0 31400 9388\r\n0 0 26020 9388\r\n", "output": ["YES"]}, {"input": "5\r\n15164 0 19356 3925\r\n0 0 15164 31400\r\n15164 3925 31400 31400\r\n19356 3278 31400 3925\r\n19356 0 31400 3278\r\n", "output": ["YES"]}, {"input": "5\r\n20421 5189 23141 12511\r\n16414 10436 17880 12511\r\n17880 10436 20421 12511\r\n15819 10436 16414 12511\r\n15819 5189 20421 10436\r\n", "output": ["YES"]}, {"input": "1\r\n15819 5189 23141 12511\r\n", "output": ["YES"]}, {"input": "3\r\n12052 12345 12343 18147\r\n12343 12345 12345 18147\r\n6543 12345 12052 18147\r\n", "output": ["YES"]}, {"input": "5\r\n12750 0 25688 1\r\n1094 0 12750 1\r\n0 0 956 1\r\n956 0 1094 1\r\n25688 0 31400 1\r\n", "output": ["NO"]}, {"input": "5\r\n0 7098 1 7460\r\n0 7460 1 15218\r\n0 15218 1 31400\r\n0 4974 1 7098\r\n0 0 1 4974\r\n", "output": ["NO"]}, {"input": "1\r\n0 0 31400 1\r\n", "output": ["NO"]}, {"input": "1\r\n0 0 1 31400\r\n", "output": ["NO"]}, {"input": "5\r\n0 25169 1 27914\r\n0 0 1 1366\r\n0 10763 1 25169\r\n0 1366 1 10138\r\n0 27914 1 31400\r\n", "output": ["NO"]}, {"input": "1\r\n0 0 10575 1\r\n", "output": ["NO"]}, {"input": "1\r\n0 3006 1 17592\r\n", "output": ["NO"]}, {"input": "1\r\n123 4819 5819 29511\r\n", "output": ["NO"]}, {"input": "3\r\n123 4819 5819 6612\r\n123 6612 5819 12692\r\n123 12692 5819 29511\r\n", "output": ["NO"]}, {"input": "5\r\n3091 4819 5743 13222\r\n123 13222 5819 29511\r\n5743 4819 5819 13222\r\n123 4819 2215 13222\r\n2215 4819 3091 13222\r\n", "output": ["NO"]}, {"input": "5\r\n8030 7681 8491 7682\r\n8491 7681 8961 7682\r\n7666 7681 7963 7682\r\n7963 7681 8030 7682\r\n678 7681 7666 7682\r\n", "output": ["NO"]}, {"input": "5\r\n1234 1234 1235 1235\r\n1238 1234 1239 1235\r\n1235 1234 1236 1235\r\n1237 1234 1238 1235\r\n1236 1234 1237 1235\r\n", "output": ["NO"]}, {"input": "5\r\n20812 5661 27208 5898\r\n20812 581 29415 5661\r\n27539 5661 29415 5898\r\n18961 581 20812 5898\r\n27208 5661 27539 5898\r\n", "output": ["NO"]}, {"input": "1\r\n31399 31399 31400 31400\r\n", "output": ["YES"]}, {"input": "1\r\n20499 0 31400 22815\r\n", "output": ["NO"]}, {"input": "2\r\n0 1273 26470 9100\r\n0 16615 31400 31400\r\n", "output": ["NO"]}, {"input": "3\r\n25784 0 31400 20408\r\n0 20408 31400 20582\r\n15802 0 18106 20408\r\n", "output": ["NO"]}, {"input": "4\r\n18006 16484 25725 31400\r\n0 0 31400 16484\r\n29563 16484 31400 31400\r\n25725 16484 29563 31400\r\n", "output": ["NO"]}, {"input": "5\r\n26466 0 26474 6206\r\n10906 0 17073 6321\r\n19720 0 26356 31400\r\n0 0 10906 7852\r\n0 21437 18466 31400\r\n", "output": ["NO"]}, {"input": "5\r\n1338 31399 1525 31400\r\n1525 31399 2595 31400\r\n961 31399 1338 31400\r\n2956 31399 31400 31400\r\n2595 31399 2956 31400\r\n", "output": ["NO"]}, {"input": "5\r\n1349 0 1391 3766\r\n1234 0 1238 417\r\n1391 0 5000 3766\r\n1234 417 1238 3766\r\n1238 0 1349 3766\r\n", "output": ["YES"]}, {"input": "5\r\n0 0 100 30000\r\n100 0 31400 5000\r\n100 5000 20000 30000\r\n0 30000 20000 31400\r\n20000 5000 31400 31400\r\n", "output": ["YES"]}, {"input": "5\r\n0 0 100 30000\r\n100 0 31400 5000\r\n100 5000 20000 30000\r\n0 30000 20000 31000\r\n20000 5000 31400 31000\r\n", "output": ["NO"]}, {"input": "5\r\n8591 1234 9517 19512\r\n696 19512 9517 31400\r\n696 696 8591 19512\r\n8591 696 31400 1234\r\n9517 1234 31400 31400\r\n", "output": ["YES"]}, {"input": "5\r\n0 0 1 1\r\n0 3 1 4\r\n0 1 1 2\r\n0 2 1 3\r\n0 4 1 5\r\n", "output": ["NO"]}, {"input": "4\r\n0 0 1 2\r\n0 3 1 4\r\n0 4 1 5\r\n0 2 1 3\r\n", "output": ["NO"]}, {"input": "3\r\n0 1 1 3\r\n0 3 1 5\r\n0 0 1 1\r\n", "output": ["NO"]}, {"input": "1\r\n0 0 1 5\r\n", "output": ["NO"]}, {"input": "4\r\n0 0 2 1\r\n2 0 3 2\r\n0 1 1 3\r\n1 2 3 3\r\n", "output": ["NO"]}, {"input": "5\r\n0 0 2 1\r\n2 0 3 2\r\n0 1 1 3\r\n1 2 3 3\r\n1 1 2 2\r\n", "output": ["YES"]}, {"input": "1\r\n0 0 1 1\r\n", "output": ["YES"]}, {"input": "1\r\n0 0 31400 31400\r\n", "output": ["YES"]}, {"input": "2\r\n0 0 10000 31400\r\n10000 0 31400 31400\r\n", "output": ["YES"]}, {"input": "2\r\n0 0 10000 31400\r\n10000 0 31400 31399\r\n", "output": ["NO"]}, {"input": "2\r\n0 0 1 18\r\n5 0 6 18\r\n", "output": ["NO"]}, {"input": "1\r\n0 0 1 4\r\n", "output": ["NO"]}, {"input": "2\r\n0 0 2 6\r\n2 2 4 4\r\n", "output": ["NO"]}, {"input": "2\r\n2 2 3 3\r\n4 4 6 7\r\n", "output": ["NO"]}, {"input": "2\r\n0 0 1 1\r\n1 0 2 1\r\n", "output": ["NO"]}, {"input": "2\r\n0 0 1 1\r\n2 2 3 3\r\n", "output": ["NO"]}, {"input": "4\r\n0 0 1 1\r\n5 5 6 6\r\n10 10 11 11\r\n13 13 14 14\r\n", "output": ["NO"]}, {"input": "5\r\n1 1 3 5\r\n3 3 5 5\r\n4 1 5 3\r\n3 1 4 2\r\n2 5 3 6\r\n", "output": ["NO"]}, {"input": "4\r\n10 10 11 11\r\n11 11 12 12\r\n11 10 12 11\r\n9 12 10 13\r\n", "output": ["NO"]}, {"input": "2\r\n0 0 2 4\r\n10 0 12 4\r\n", "output": ["NO"]}, {"input": "4\r\n0 0 1 1\r\n0 1 1 2\r\n0 2 1 3\r\n0 3 1 4\r\n", "output": ["NO"]}, {"input": "2\r\n0 0 1 1\r\n3 3 4 4\r\n", "output": ["NO"]}, {"input": "2\r\n0 0 3 1\r\n0 2 3 3\r\n", "output": ["NO"]}, {"input": "2\r\n1 1 5 5\r\n1 5 5 7\r\n", "output": ["NO"]}, {"input": "3\r\n0 0 1 1\r\n1 0 3 3\r\n0 2 1 4\r\n", "output": ["NO"]}, {"input": "4\r\n0 0 10 10\r\n10 10 20 20\r\n10 0 20 10\r\n10 20 11 120\r\n", "output": ["NO"]}, {"input": "1\r\n0 0 1 7\r\n", "output": ["NO"]}, {"input": "4\r\n0 0 4 2\r\n0 2 3 6\r\n3 4 6 6\r\n4 0 6 4\r\n", "output": ["NO"]}, {"input": "2\r\n0 0 1 1\r\n1 1 2 2\r\n", "output": ["NO"]}, {"input": "2\r\n1 1 2 2\r\n3 3 4 4\r\n", "output": ["NO"]}]
100
100
100
[{'input': '5\r\n0 0 10000 20000\r\n10000 0 15000 19999\r\n10000 19999 15000 20000\r\n0 20000 15000 31400\r\n15000 0 31400 31400\r\n', 'output': ['YES']}, {'input': '3\r\n25784 0 31400 20408\r\n0 20408 31400 20582\r\n15802 0 18106 20408\r\n', 'output': ['NO']}, {'input': '4\r\n0 0 1 2\r\n0 3 1 4\r\n0 4 1 5\r\n0 2 1 3\r\n', 'output': ['NO']}, {'input': '5\r\n0 0 10000 20000\r\n10000 0 15000 19999\r\n10000 19999 14999 20000\r\n0 20000 15000 31400\r\n15000 0 31400 31400\r\n', 'output': ['NO']}, {'input': '2\r\n0 0 10000 31400\r\n10000 0 31400 31399\r\n', 'output': ['NO']}]
[{'input': '2\r\n0 0 1 1\r\n2 2 3 3\r\n', 'output': ['NO']}, {'input': '2\r\n0 0 1 1\r\n1 1 2 2\r\n', 'output': ['NO']}, {'input': '4\r\n0 0 1 1\r\n5 5 6 6\r\n10 10 11 11\r\n13 13 14 14\r\n', 'output': ['NO']}, {'input': '5\r\n1349 0 1391 3766\r\n1234 0 1238 417\r\n1391 0 5000 3766\r\n1234 417 1238 3766\r\n1238 0 1349 3766\r\n', 'output': ['YES']}, {'input': '5\r\n0 7098 1 7460\r\n0 7460 1 15218\r\n0 15218 1 31400\r\n0 4974 1 7098\r\n0 0 1 4974\r\n', 'output': ['NO']}]
[{'input': '5\r\n0 7098 1 7460\r\n0 7460 1 15218\r\n0 15218 1 31400\r\n0 4974 1 7098\r\n0 0 1 4974\r\n', 'output': ['NO']}, {'input': '5\r\n0 0 10000 20000\r\n10000 0 15000 19999\r\n10000 19999 14999 20000\r\n0 20000 15000 31400\r\n15000 0 31400 31400\r\n', 'output': ['NO']}, {'input': '2\r\n1 1 5 5\r\n1 5 5 7\r\n', 'output': ['NO']}, {'input': '4\r\n0 0 1 2\r\n0 3 1 4\r\n0 4 1 5\r\n0 2 1 3\r\n', 'output': ['NO']}, {'input': '5\r\n1349 0 1391 3766\r\n1234 0 1238 417\r\n1391 0 5000 3766\r\n1234 417 1238 3766\r\n1238 0 1349 3766\r\n', 'output': ['YES']}]
[{'input': '1\r\n123 4819 5819 29511\r\n', 'output': ['NO']}, {'input': '5\r\n10359 859 28918 4384\r\n2895 26520 28918 26882\r\n2895 26424 28918 26520\r\n2895 859 10359 4384\r\n2895 4384 28918 26424\r\n', 'output': ['YES']}, {'input': '5\r\n0 0 10000 20000\r\n10000 0 15000 19999\r\n10000 19999 15000 20000\r\n0 20000 15000 31400\r\n15000 0 31400 31400\r\n', 'output': ['YES']}, {'input': '1\r\n0 0 10575 1\r\n', 'output': ['NO']}, {'input': '4\r\n0 0 1 1\r\n0 1 1 2\r\n0 2 1 3\r\n0 3 1 4\r\n', 'output': ['NO']}]
[{'input': '5\r\n0 0 10000 20000\r\n10000 0 15000 19999\r\n10000 19999 15000 20000\r\n0 20000 15000 31400\r\n15000 0 31400 31400\r\n', 'output': ['YES']}, {'input': '5\r\n26466 0 26474 6206\r\n10906 0 17073 6321\r\n19720 0 26356 31400\r\n0 0 10906 7852\r\n0 21437 18466 31400\r\n', 'output': ['NO']}, {'input': '4\r\n18006 16484 25725 31400\r\n0 0 31400 16484\r\n29563 16484 31400 31400\r\n25725 16484 29563 31400\r\n', 'output': ['NO']}, {'input': '1\r\n0 0 1 31400\r\n', 'output': ['NO']}, {'input': '5\r\n0 0 100 30000\r\n100 0 31400 5000\r\n100 5000 20000 30000\r\n0 30000 20000 31400\r\n20000 5000 31400 31400\r\n', 'output': ['YES']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
87.5
100
268
100
100
97.5
["2 3 1000000", "3 3 2"]
The first line contains three integers n, m, s (1 ≀ n, m, s ≀ 106) β€” length of the board, width of the board and length of the flea's jump.
e853733fb2ed87c56623ff9a5ac09c36
import java.io.*; import java.util.*; public class practice { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class Print { private final BufferedWriter bw; public Print() { bw=new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(String str)throws IOException { bw.append(str); } public void println(String str)throws IOException { print(str); bw.append("\n"); } public void close()throws IOException { bw.close(); }} public static void main(String[] args) throws IOException { FastReader scn=new FastReader(); Print p=new Print(); long n=scn.nextLong(),m=scn.nextLong(),s=scn.nextLong(); long ans=((n-1)/s+1)*((m-1)/s+1)*((n-1)%s+1)*((m-1)%s+1); p.println(Long.toString(ans)); p.close(); } }
["6", "4"]
Java
null
Output the only integer β€” the number of the required starting positions of the flea.
It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board of the size n × m centimeters (each cell is 1 × 1 centimeters). She can jump as she wishes for an arbitrary number of times, she can even visit a cell more than once. The only restriction is that she cannot jump out of the board.The flea can count the amount of cells that she can reach from the starting position (x, y). Let's denote this amount by dx, y. Your task is to find the number of such starting positions (x, y), which have the maximum possible value of dx, y.
[{"input": "2 3 1000000\r\n", "output": ["6"]}, {"input": "3 3 2\r\n", "output": ["4"]}, {"input": "1 2 3\r\n", "output": ["2"]}, {"input": "4 5 6\r\n", "output": ["20"]}, {"input": "9 8 7\r\n", "output": ["8"]}, {"input": "1000 1000 1000\r\n", "output": ["1000000"]}, {"input": "1 1 1\r\n", "output": ["1"]}, {"input": "1 1 2\r\n", "output": ["1"]}, {"input": "1 1 1000000\r\n", "output": ["1"]}, {"input": "1000000 1000000 1\r\n", "output": ["1000000000000"]}, {"input": "1000000 1000000 2\r\n", "output": ["1000000000000"]}, {"input": "1000000 1000000 999999\r\n", "output": ["4"]}, {"input": "1000000 1000000 12345\r\n", "output": ["20340100"]}, {"input": "1000000 1000000 123456\r\n", "output": ["12358324224"]}, {"input": "43496 179847 327622\r\n", "output": ["7822625112"]}, {"input": "105126 379125 460772\r\n", "output": ["39855894750"]}, {"input": "999463 261665 981183\r\n", "output": ["9566472400"]}, {"input": "836832 336228 50\r\n", "output": ["100850467200"]}, {"input": "303307 400683 999941\r\n", "output": ["121529958681"]}, {"input": "40224 890892 54\r\n", "output": ["31858297920"]}, {"input": "109785 447109 990618\r\n", "output": ["49085861565"]}, {"input": "228385 744978 699604\r\n", "output": ["20725481980"]}, {"input": "694117 431924 737\r\n", "output": ["13934440800"]}, {"input": "923179 799988 998430\r\n", "output": ["738532121852"]}, {"input": "61043 55049 998379\r\n", "output": ["3360356107"]}, {"input": "402841 635488 997633\r\n", "output": ["256000621408"]}, {"input": "213927 672636 865\r\n", "output": ["27867287808"]}, {"input": "391814 220151 3756\r\n", "output": ["16977831150"]}, {"input": "313667 778854 999813\r\n", "output": ["244300797618"]}, {"input": "933241 558702 1\r\n", "output": ["521403613182"]}, {"input": "38614 941895 999986\r\n", "output": ["36370333530"]}, {"input": "242366 216591 4\r\n", "output": ["19685613696"]}, {"input": "282798 941695 999998\r\n", "output": ["266309462610"]}, {"input": "43054 191 1\r\n", "output": ["8223314"]}]
100
100
100
[{'input': '1 2 3\r\n', 'output': ['2']}, {'input': '1000000 1000000 2\r\n', 'output': ['1000000000000']}, {'input': '1000 1000 1000\r\n', 'output': ['1000000']}, {'input': '303307 400683 999941\r\n', 'output': ['121529958681']}, {'input': '3 3 2\r\n', 'output': ['4']}]
[{'input': '9 8 7\r\n', 'output': ['8']}, {'input': '109785 447109 990618\r\n', 'output': ['49085861565']}, {'input': '923179 799988 998430\r\n', 'output': ['738532121852']}, {'input': '282798 941695 999998\r\n', 'output': ['266309462610']}, {'input': '105126 379125 460772\r\n', 'output': ['39855894750']}]
[{'input': '1 2 3\r\n', 'output': ['2']}, {'input': '999463 261665 981183\r\n', 'output': ['9566472400']}, {'input': '213927 672636 865\r\n', 'output': ['27867287808']}, {'input': '1000000 1000000 999999\r\n', 'output': ['4']}, {'input': '391814 220151 3756\r\n', 'output': ['16977831150']}]
[{'input': '43054 191 1\r\n', 'output': ['8223314']}, {'input': '1000000 1000000 123456\r\n', 'output': ['12358324224']}, {'input': '1000000 1000000 999999\r\n', 'output': ['4']}, {'input': '313667 778854 999813\r\n', 'output': ['244300797618']}, {'input': '61043 55049 998379\r\n', 'output': ['3360356107']}]
[{'input': '2 3 1000000\r\n', 'output': ['6']}, {'input': '3 3 2\r\n', 'output': ['4']}, {'input': '694117 431924 737\r\n', 'output': ['13934440800']}, {'input': '836832 336228 50\r\n', 'output': ['100850467200']}, {'input': '43496 179847 327622\r\n', 'output': ['7822625112']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
269
100
100
100
["7", "8", "9"]
The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$).
5551742f6ab39fdac3930d866f439e3e
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Scanner; public class Main { public static void main(String[] args) throws ParseException, IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); long n=Long.parseLong(br.readLine()); System.out.println((int)Math.ceil(1.0*(n+1)/2)); } }
["4", "5", "5"]
Java
NoteIn the first sample, there are following possible weights of splits of $$$7$$$:Weight 1: [$$$\textbf 7$$$] Weight 2: [$$$\textbf 3$$$, $$$\textbf 3$$$, 1] Weight 3: [$$$\textbf 2$$$, $$$\textbf 2$$$, $$$\textbf 2$$$, 1] Weight 7: [$$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$]
Output one integerΒ β€” the answer to the problem.
Let's define a split of $$$n$$$ as a nonincreasing sequence of positive integers, the sum of which is $$$n$$$. For example, the following sequences are splits of $$$8$$$: $$$[4, 4]$$$, $$$[3, 3, 2]$$$, $$$[2, 2, 1, 1, 1, 1]$$$, $$$[5, 2, 1]$$$.The following sequences aren't splits of $$$8$$$: $$$[1, 7]$$$, $$$[5, 4]$$$, $$$[11, -3]$$$, $$$[1, 1, 4, 1, 1]$$$.The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $$$[1, 1, 1, 1, 1]$$$ is $$$5$$$, the weight of the split $$$[5, 5, 3, 3, 3]$$$ is $$$2$$$ and the weight of the split $$$[9]$$$ equals $$$1$$$.For a given $$$n$$$, find out the number of different weights of its splits.
[{"input": "7\r\n", "output": ["4"]}, {"input": "8\r\n", "output": ["5"]}, {"input": "9\r\n", "output": ["5"]}, {"input": "1\r\n", "output": ["1"]}, {"input": "286\r\n", "output": ["144"]}, {"input": "48\r\n", "output": ["25"]}, {"input": "941\r\n", "output": ["471"]}, {"input": "45154\r\n", "output": ["22578"]}, {"input": "60324\r\n", "output": ["30163"]}, {"input": "91840\r\n", "output": ["45921"]}, {"input": "41909\r\n", "output": ["20955"]}, {"input": "58288\r\n", "output": ["29145"]}, {"input": "91641\r\n", "output": ["45821"]}, {"input": "62258\r\n", "output": ["31130"]}, {"input": "79811\r\n", "output": ["39906"]}, {"input": "88740\r\n", "output": ["44371"]}, {"input": "12351\r\n", "output": ["6176"]}, {"input": "1960\r\n", "output": ["981"]}, {"input": "29239\r\n", "output": ["14620"]}, {"input": "85801\r\n", "output": ["42901"]}, {"input": "43255\r\n", "output": ["21628"]}, {"input": "13439\r\n", "output": ["6720"]}, {"input": "35668\r\n", "output": ["17835"]}, {"input": "19122\r\n", "output": ["9562"]}, {"input": "60169\r\n", "output": ["30085"]}, {"input": "50588\r\n", "output": ["25295"]}, {"input": "2467\r\n", "output": ["1234"]}, {"input": "39315\r\n", "output": ["19658"]}, {"input": "29950\r\n", "output": ["14976"]}, {"input": "17286\r\n", "output": ["8644"]}, {"input": "7359066\r\n", "output": ["3679534"]}, {"input": "1016391\r\n", "output": ["508196"]}, {"input": "7928871\r\n", "output": ["3964436"]}, {"input": "3968891\r\n", "output": ["1984446"]}, {"input": "2636452\r\n", "output": ["1318227"]}, {"input": "5076901\r\n", "output": ["2538451"]}, {"input": "9870265\r\n", "output": ["4935133"]}, {"input": "2453786\r\n", "output": ["1226894"]}, {"input": "7263670\r\n", "output": ["3631836"]}, {"input": "1890845\r\n", "output": ["945423"]}, {"input": "574128507\r\n", "output": ["287064254"]}, {"input": "648476655\r\n", "output": ["324238328"]}, {"input": "97349542\r\n", "output": ["48674772"]}, {"input": "716489761\r\n", "output": ["358244881"]}, {"input": "858771038\r\n", "output": ["429385520"]}, {"input": "520778784\r\n", "output": ["260389393"]}, {"input": "439004204\r\n", "output": ["219502103"]}, {"input": "589992198\r\n", "output": ["294996100"]}, {"input": "371106544\r\n", "output": ["185553273"]}, {"input": "894241590\r\n", "output": ["447120796"]}, {"input": "123957268\r\n", "output": ["61978635"]}, {"input": "234149297\r\n", "output": ["117074649"]}, {"input": "789954052\r\n", "output": ["394977027"]}, {"input": "667978920\r\n", "output": ["333989461"]}, {"input": "154647261\r\n", "output": ["77323631"]}, {"input": "751453521\r\n", "output": ["375726761"]}, {"input": "848862308\r\n", "output": ["424431155"]}, {"input": "323926781\r\n", "output": ["161963391"]}, {"input": "576768825\r\n", "output": ["288384413"]}, {"input": "31293802\r\n", "output": ["15646902"]}, {"input": "2\r\n", "output": ["2"]}, {"input": "1000000000\r\n", "output": ["500000001"]}, {"input": "3\r\n", "output": ["2"]}]
100
100
100
[{'input': '41909\r\n', 'output': ['20955']}, {'input': '97349542\r\n', 'output': ['48674772']}, {'input': '574128507\r\n', 'output': ['287064254']}, {'input': '5076901\r\n', 'output': ['2538451']}, {'input': '123957268\r\n', 'output': ['61978635']}]
[{'input': '60169\r\n', 'output': ['30085']}, {'input': '323926781\r\n', 'output': ['161963391']}, {'input': '751453521\r\n', 'output': ['375726761']}, {'input': '858771038\r\n', 'output': ['429385520']}, {'input': '58288\r\n', 'output': ['29145']}]
[{'input': '43255\r\n', 'output': ['21628']}, {'input': '29239\r\n', 'output': ['14620']}, {'input': '576768825\r\n', 'output': ['288384413']}, {'input': '31293802\r\n', 'output': ['15646902']}, {'input': '45154\r\n', 'output': ['22578']}]
[{'input': '17286\r\n', 'output': ['8644']}, {'input': '574128507\r\n', 'output': ['287064254']}, {'input': '29950\r\n', 'output': ['14976']}, {'input': '60324\r\n', 'output': ['30163']}, {'input': '79811\r\n', 'output': ['39906']}]
[{'input': '520778784\r\n', 'output': ['260389393']}, {'input': '2\r\n', 'output': ['2']}, {'input': '1960\r\n', 'output': ['981']}, {'input': '79811\r\n', 'output': ['39906']}, {'input': '60169\r\n', 'output': ['30085']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
270
100
100
100
["390", "7", "1000000000"]
The only input line contains the integer $$$n$$$ ($$$1 \le n \le 2\cdot10^9$$$).
38690bd32e7d0b314f701f138ce19dfb
import java.util.Scanner; public class Nirvana { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n=in.nextInt(); Nirvana obj = new Nirvana(); System.out.println(obj.maxMultiply(n)); in.close(); } int maxMultiply(int n) { if(n == 0) return 1; int nextNum = n/10; int digit = n%10; if(digit == 9) { // No need to borrow return 9*maxMultiply(nextNum); } int result9 = -1; int resultNormal = -1; if(nextNum>0) { // Can borrow result9 = 9*maxMultiply(nextNum-1); } resultNormal = digit*maxMultiply(nextNum); return Math.max(result9, resultNormal); } }
["216", "7", "387420489"]
Java
NoteIn the first example the maximum product is achieved for $$$389$$$ (the product of digits is $$$3\cdot8\cdot9=216$$$).In the second example the maximum product is achieved for $$$7$$$ (the product of digits is $$$7$$$).In the third example the maximum product is achieved for $$$999999999$$$ (the product of digits is $$$9^9=387420489$$$).
Print the maximum product of digits among all integers from $$$1$$$ to $$$n$$$.
Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper.Help Kurt find the maximum possible product of digits among all integers from $$$1$$$ to $$$n$$$.
[{"input": "390\r\n", "output": ["216"]}, {"input": "7\r\n", "output": ["7"]}, {"input": "1000000000\r\n", "output": ["387420489"]}, {"input": "1\r\n", "output": ["1"]}, {"input": "9\r\n", "output": ["9"]}, {"input": "2000000000\r\n", "output": ["387420489"]}, {"input": "4876\r\n", "output": ["2268"]}, {"input": "889878787\r\n", "output": ["301327047"]}, {"input": "1382011913\r\n", "output": ["387420489"]}, {"input": "999999999\r\n", "output": ["387420489"]}, {"input": "396579088\r\n", "output": ["114791256"]}, {"input": "890133136\r\n", "output": ["306110016"]}, {"input": "485908655\r\n", "output": ["133923132"]}, {"input": "261560170\r\n", "output": ["47829690"]}, {"input": "391789744\r\n", "output": ["114791256"]}, {"input": "480330141\r\n", "output": ["133923132"]}, {"input": "691993260\r\n", "output": ["229582512"]}, {"input": "483212601\r\n", "output": ["133923132"]}, {"input": "892295273\r\n", "output": ["306110016"]}, {"input": "389041744\r\n", "output": ["102036672"]}, {"input": "282587478\r\n", "output": ["66961566"]}, {"input": "791812587\r\n", "output": ["267846264"]}, {"input": "2\r\n", "output": ["2"]}, {"input": "3\r\n", "output": ["3"]}, {"input": "4\r\n", "output": ["4"]}, {"input": "10\r\n", "output": ["9"]}, {"input": "11\r\n", "output": ["9"]}, {"input": "12\r\n", "output": ["9"]}, {"input": "19\r\n", "output": ["9"]}, {"input": "20\r\n", "output": ["9"]}, {"input": "98\r\n", "output": ["72"]}, {"input": "99\r\n", "output": ["81"]}, {"input": "100\r\n", "output": ["81"]}, {"input": "101\r\n", "output": ["81"]}, {"input": "997\r\n", "output": ["648"]}, {"input": "998\r\n", "output": ["648"]}, {"input": "999\r\n", "output": ["729"]}, {"input": "1000\r\n", "output": ["729"]}, {"input": "1001\r\n", "output": ["729"]}, {"input": "25\r\n", "output": ["10"]}, {"input": "278\r\n", "output": ["112"]}, {"input": "1999999999\r\n", "output": ["387420489"]}, {"input": "2690\r\n", "output": ["864"]}, {"input": "268\r\n", "output": ["96"]}, {"input": "289664200\r\n", "output": ["68024448"]}, {"input": "288\r\n", "output": ["128"]}, {"input": "1999999998\r\n", "output": ["387420489"]}]
100
100
100
[{'input': '1999999999\r\n', 'output': ['387420489']}, {'input': '261560170\r\n', 'output': ['47829690']}, {'input': '4876\r\n', 'output': ['2268']}, {'input': '480330141\r\n', 'output': ['133923132']}, {'input': '999\r\n', 'output': ['729']}]
[{'input': '1000000000\r\n', 'output': ['387420489']}, {'input': '25\r\n', 'output': ['10']}, {'input': '691993260\r\n', 'output': ['229582512']}, {'input': '19\r\n', 'output': ['9']}, {'input': '1\r\n', 'output': ['1']}]
[{'input': '3\r\n', 'output': ['3']}, {'input': '278\r\n', 'output': ['112']}, {'input': '389041744\r\n', 'output': ['102036672']}, {'input': '100\r\n', 'output': ['81']}, {'input': '9\r\n', 'output': ['9']}]
[{'input': '997\r\n', 'output': ['648']}, {'input': '2690\r\n', 'output': ['864']}, {'input': '480330141\r\n', 'output': ['133923132']}, {'input': '396579088\r\n', 'output': ['114791256']}, {'input': '1\r\n', 'output': ['1']}]
[{'input': '389041744\r\n', 'output': ['102036672']}, {'input': '892295273\r\n', 'output': ['306110016']}, {'input': '1999999999\r\n', 'output': ['387420489']}, {'input': '289664200\r\n', 'output': ['68024448']}, {'input': '997\r\n', 'output': ['648']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
271
100
100
100
["0 2", "2 0", "2 2", "2000 2000"]
The only line contains two integers $$$n$$$ and $$$m$$$ ($$$0 \le n,m \le 2\,000$$$).
a2fcad987e9b2bb3e6395654cd4fcfbb
/* If you want to aim high, aim high Don't let that studying and grades consume you Just live life young ****************************** If I'm the sun, you're the moon Because when I go up, you go down ******************************* I'm working for the day I will surpass you https://www.a2oj.com/Ladder16.html */ import java.util.*; import java.io.*; import java.math.*; public class x1204E { static long MOD = 998244853L; public static void main(String omkar[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(infile.readLine()); int N = Integer.parseInt(st.nextToken()); int M = Integer.parseInt(st.nextToken()); fac = new long[4001]; invfac = new long[4001]; fac[0] = invfac[0] = 1L; for(int i=1; i <= 4000; i++) { fac[i] = (fac[i-1]*i)%MOD; invfac[i] = power(fac[i], MOD-2, MOD); } long[][] zero = new long[N+1][M+1]; Arrays.fill(zero[0], 1L); for(int a=1; a <= N; a++) for(int b=a; b <= M; b++) zero[a][b] = (zero[a-1][b]+zero[a][b-1])%MOD; long[][] dp = new long[N+1][M+1]; for(int a=0; a <= N; a++) dp[a][0] = a; for(int a=1; a <= N; a++) for(int b=1; b <= M; b++) { long temp = (dp[a-1][b]+dp[a][b-1])%MOD; temp = (temp+cnt(a-1,b)-cnt(a,b-1)+MOD)%MOD; dp[a][b] = (temp+zero[a][b-1])%MOD; } System.out.println(dp[N][M]); } static long fac[]; static long invfac[]; public static long cnt(int a, int b) { long val = fac[a+b]; val = (val*invfac[a])%MOD; return (val*invfac[b])%MOD; } public static long power(long x, long y, long p) { long res = 1L; x = x % p; while (y > 0) { if((y & 1)==1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } }
["0", "2", "5", "674532367"]
Java
NoteIn the first example the only possible array is [-1,-1], its maximal prefix sum is equal to $$$0$$$. In the second example the only possible array is [1,1], its maximal prefix sum is equal to $$$2$$$. There are $$$6$$$ possible arrays in the third example:[1,1,-1,-1], f([1,1,-1,-1]) = 2[1,-1,1,-1], f([1,-1,1,-1]) = 1[1,-1,-1,1], f([1,-1,-1,1]) = 1[-1,1,1,-1], f([-1,1,1,-1]) = 1[-1,1,-1,1], f([-1,1,-1,1]) = 0[-1,-1,1,1], f([-1,-1,1,1]) = 0So the answer for the third example is $$$2+1+1+1+0+0 = 5$$$.
Output the answer to the problem modulo $$$998\: 244\: 853$$$.
Natasha's favourite numbers are $$$n$$$ and $$$1$$$, and Sasha's favourite numbers are $$$m$$$ and $$$-1$$$. One day Natasha and Sasha met and wrote down every possible array of length $$$n+m$$$ such that some $$$n$$$ of its elements are equal to $$$1$$$ and another $$$m$$$ elements are equal to $$$-1$$$. For each such array they counted its maximal prefix sum, probably an empty one which is equal to $$$0$$$ (in another words, if every nonempty prefix sum is less to zero, then it is considered equal to zero). Formally, denote as $$$f(a)$$$ the maximal prefix sum of an array $$$a_{1, \ldots ,l}$$$ of length $$$l \geq 0$$$. Then: $$$$$$f(a) = \max (0, \smash{\displaystyle\max_{1 \leq i \leq l}} \sum_{j=1}^{i} a_j )$$$$$$Now they want to count the sum of maximal prefix sums for each such an array and they are asking you to help. As this sum can be very large, output it modulo $$$998\: 244\: 853$$$.
[{"input": "0 2\r\n", "output": ["0"]}, {"input": "2 0\r\n", "output": ["2"]}, {"input": "2 2\r\n", "output": ["5"]}, {"input": "2000 2000\r\n", "output": ["674532367"]}, {"input": "0 0\r\n", "output": ["0"]}, {"input": "11 2\r\n", "output": ["716"]}, {"input": "1 4\r\n", "output": ["1"]}, {"input": "5 13\r\n", "output": ["4048"]}, {"input": "60 59\r\n", "output": ["271173738"]}, {"input": "27 16\r\n", "output": ["886006554"]}, {"input": "1134 1092\r\n", "output": ["134680101"]}, {"input": "756 1061\r\n", "output": ["72270489"]}, {"input": "953 1797\r\n", "output": ["557692333"]}, {"input": "76 850\r\n", "output": ["103566263"]}, {"input": "24 1508\r\n", "output": ["540543518"]}, {"input": "1087 1050\r\n", "output": ["973930225"]}, {"input": "149 821\r\n", "output": ["64450770"]}, {"input": "983 666\r\n", "output": ["917123830"]}, {"input": "45 1323\r\n", "output": ["357852234"]}, {"input": "1994 1981\r\n", "output": ["596939902"]}, {"input": "1942 1523\r\n", "output": ["89088577"]}, {"input": "1891 1294\r\n", "output": ["696966158"]}, {"input": "1132 1727\r\n", "output": ["878164775"]}, {"input": "1080 383\r\n", "output": ["161999131"]}, {"input": "1028 1040\r\n", "output": ["119840364"]}, {"input": "976 1698\r\n", "output": ["621383232"]}, {"input": "38 656\r\n", "output": ["814958661"]}, {"input": "872 1313\r\n", "output": ["261808476"]}, {"input": "1935 856\r\n", "output": ["707458926"]}, {"input": "1883 1513\r\n", "output": ["265215482"]}, {"input": "0 2000\r\n", "output": ["0"]}, {"input": "2000 0\r\n", "output": ["2000"]}, {"input": "1991 1992\r\n", "output": ["518738831"]}, {"input": "1935 1977\r\n", "output": ["16604630"]}, {"input": "1990 2000\r\n", "output": ["516468539"]}, {"input": "1915 1915\r\n", "output": ["534527105"]}]
100
100
100
[{'input': '983 666\r\n', 'output': ['917123830']}, {'input': '2 0\r\n', 'output': ['2']}, {'input': '0 2000\r\n', 'output': ['0']}, {'input': '953 1797\r\n', 'output': ['557692333']}, {'input': '1 4\r\n', 'output': ['1']}]
[{'input': '1132 1727\r\n', 'output': ['878164775']}, {'input': '27 16\r\n', 'output': ['886006554']}, {'input': '1080 383\r\n', 'output': ['161999131']}, {'input': '983 666\r\n', 'output': ['917123830']}, {'input': '1942 1523\r\n', 'output': ['89088577']}]
[{'input': '756 1061\r\n', 'output': ['72270489']}, {'input': '27 16\r\n', 'output': ['886006554']}, {'input': '45 1323\r\n', 'output': ['357852234']}, {'input': '60 59\r\n', 'output': ['271173738']}, {'input': '149 821\r\n', 'output': ['64450770']}]
[{'input': '0 2\r\n', 'output': ['0']}, {'input': '1883 1513\r\n', 'output': ['265215482']}, {'input': '1994 1981\r\n', 'output': ['596939902']}, {'input': '2000 2000\r\n', 'output': ['674532367']}, {'input': '149 821\r\n', 'output': ['64450770']}]
[{'input': '1087 1050\r\n', 'output': ['973930225']}, {'input': '976 1698\r\n', 'output': ['621383232']}, {'input': '0 2000\r\n', 'output': ['0']}, {'input': '1132 1727\r\n', 'output': ['878164775']}, {'input': '2000 2000\r\n', 'output': ['674532367']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
272
100
100
100
["4", "5"]
The single line contains the positive integer n (1 ≀ n ≀ 1015).
689e7876048ee4eb7479e838c981f068
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; public class _486A_CalculatingFunction { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BigInteger n = new BigInteger(br.readLine()); if (n.remainder(new BigInteger("2")).equals(new BigInteger("0"))) { System.out.println(n.divide(new BigInteger("2"))); } else { System.out.println(n.divide(new BigInteger("2")).add(new BigInteger("1")).multiply(new BigInteger("-1"))); } br.close(); } }
["2", "-3"]
Java
Notef(4) =  - 1 + 2 - 3 + 4 = 2f(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
Print f(n) in a single line.
For a positive integer n let's define a function f:f(n) =  - 1 + 2 - 3 + .. + ( - 1)nn Your task is to calculate f(n) for a given integer n.
[{"input": "4\r\n", "output": ["2"]}, {"input": "5\r\n", "output": ["-3"]}, {"input": "1000000000\r\n", "output": ["500000000"]}, {"input": "1000000001\r\n", "output": ["-500000001"]}, {"input": "1000000000000000\r\n", "output": ["500000000000000"]}, {"input": "100\r\n", "output": ["50"]}, {"input": "101\r\n", "output": ["-51"]}, {"input": "102\r\n", "output": ["51"]}, {"input": "103\r\n", "output": ["-52"]}, {"input": "104\r\n", "output": ["52"]}, {"input": "105\r\n", "output": ["-53"]}, {"input": "106\r\n", "output": ["53"]}, {"input": "107\r\n", "output": ["-54"]}, {"input": "108\r\n", "output": ["54"]}, {"input": "109\r\n", "output": ["-55"]}, {"input": "208170109961052\r\n", "output": ["104085054980526"]}, {"input": "46017661651072\r\n", "output": ["23008830825536"]}, {"input": "4018154546667\r\n", "output": ["-2009077273334"]}, {"input": "288565475053\r\n", "output": ["-144282737527"]}, {"input": "3052460231\r\n", "output": ["-1526230116"]}, {"input": "29906716\r\n", "output": ["14953358"]}, {"input": "87897701693326\r\n", "output": ["43948850846663"]}, {"input": "8240\r\n", "output": ["4120"]}, {"input": "577935\r\n", "output": ["-288968"]}, {"input": "62\r\n", "output": ["31"]}, {"input": "1\r\n", "output": ["-1"]}, {"input": "2\r\n", "output": ["1"]}, {"input": "9999999999999\r\n", "output": ["-5000000000000"]}, {"input": "1000000000000\r\n", "output": ["500000000000"]}, {"input": "99999999999999\r\n", "output": ["-50000000000000"]}, {"input": "999999999999999\r\n", "output": ["-500000000000000"]}, {"input": "42191359342\r\n", "output": ["21095679671"]}, {"input": "100000000000000\r\n", "output": ["50000000000000"]}, {"input": "145645214654154\r\n", "output": ["72822607327077"]}, {"input": "4294967296\r\n", "output": ["2147483648"]}, {"input": "3037000499\r\n", "output": ["-1518500250"]}, {"input": "10000000000001\r\n", "output": ["-5000000000001"]}, {"input": "100000017040846\r\n", "output": ["50000008520423"]}, {"input": "98979894985999\r\n", "output": ["-49489947493000"]}]
100
100
100
[{'input': '5\r\n', 'output': ['-3']}, {'input': '10000000000001\r\n', 'output': ['-5000000000001']}, {'input': '101\r\n', 'output': ['-51']}, {'input': '29906716\r\n', 'output': ['14953358']}, {'input': '62\r\n', 'output': ['31']}]
[{'input': '105\r\n', 'output': ['-53']}, {'input': '10000000000001\r\n', 'output': ['-5000000000001']}, {'input': '103\r\n', 'output': ['-52']}, {'input': '100000000000000\r\n', 'output': ['50000000000000']}, {'input': '999999999999999\r\n', 'output': ['-500000000000000']}]
[{'input': '104\r\n', 'output': ['52']}, {'input': '145645214654154\r\n', 'output': ['72822607327077']}, {'input': '5\r\n', 'output': ['-3']}, {'input': '100\r\n', 'output': ['50']}, {'input': '98979894985999\r\n', 'output': ['-49489947493000']}]
[{'input': '208170109961052\r\n', 'output': ['104085054980526']}, {'input': '4018154546667\r\n', 'output': ['-2009077273334']}, {'input': '103\r\n', 'output': ['-52']}, {'input': '109\r\n', 'output': ['-55']}, {'input': '100\r\n', 'output': ['50']}]
[{'input': '98979894985999\r\n', 'output': ['-49489947493000']}, {'input': '1000000000\r\n', 'output': ['500000000']}, {'input': '1000000000000000\r\n', 'output': ['500000000000000']}, {'input': '5\r\n', 'output': ['-3']}, {'input': '100\r\n', 'output': ['50']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
273
100
100
100
["4\n6\n1\n1\n1\n1", "1\n10\n5", "3\n6\n1\n6\n5", "3\n7\n1\n6\n5"]
The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β€” the number of benches in the park. The second line contains a single integer $$$m$$$ $$$(1 \le m \le 10\,000)$$$ β€” the number of people additionally coming to the park. Each of the next $$$n$$$ lines contains a single integer $$$a_i$$$ $$$(1 \le a_i \le 100)$$$ β€” the initial number of people on the $$$i$$$-th bench.
78f696bd954c9f0f9bb502e515d85a8d
import java.util.* ; public class contes { public static void main(String ar[]) { Scanner sc = new Scanner(System.in) ; int n = sc.nextInt() ; int m = sc.nextInt() ; int max = 0 ; int sum = 0 ; for(int i = 0 ; i <n ; i++) { int k = sc.nextInt() ; max = Math.max(max, k) ; sum += k ; } int ans2 = m + max ; int ans1 = Math.max(max, (sum + n + m - 1) / (n)) ; System.out.println(ans1+" "+ans2) ; } }
["3 7", "15 15", "6 12", "7 13"]
Java
NoteIn the first example, each of four benches is occupied by a single person. The minimum $$$k$$$ is $$$3$$$. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum $$$k$$$ is $$$7$$$. That requires all six new people to occupy the same bench.The second example has its minimum $$$k$$$ equal to $$$15$$$ and maximum $$$k$$$ equal to $$$15$$$, as there is just a single bench in the park and all $$$10$$$ people will occupy it.
Print the minimum possible $$$k$$$ and the maximum possible $$$k$$$, where $$$k$$$ is the maximum number of people sitting on one bench after additional $$$m$$$ people came to the park.
There are $$$n$$$ benches in the Berland Central park. It is known that $$$a_i$$$ people are currently sitting on the $$$i$$$-th bench. Another $$$m$$$ people are coming to the park and each of them is going to have a seat on some bench out of $$$n$$$ available.Let $$$k$$$ be the maximum number of people sitting on one bench after additional $$$m$$$ people came to the park. Calculate the minimum possible $$$k$$$ and the maximum possible $$$k$$$.Nobody leaves the taken seat during the whole process.
[{"input": "4\r\n6\r\n1\r\n1\r\n1\r\n1\r\n", "output": ["3 7"]}, {"input": "1\r\n10\r\n5\r\n", "output": ["15 15"]}, {"input": "3\r\n6\r\n1\r\n6\r\n5\r\n", "output": ["6 12"]}, {"input": "3\r\n7\r\n1\r\n6\r\n5\r\n", "output": ["7 13"]}, {"input": "10\r\n1000\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n", "output": ["200 1100"]}, {"input": "10\r\n1\r\n3\r\n3\r\n2\r\n3\r\n3\r\n3\r\n3\r\n3\r\n3\r\n3\r\n", "output": ["3 4"]}, {"input": "51\r\n10000\r\n54\r\n23\r\n93\r\n86\r\n57\r\n68\r\n42\r\n33\r\n47\r\n18\r\n78\r\n41\r\n35\r\n92\r\n32\r\n97\r\n74\r\n93\r\n27\r\n59\r\n90\r\n23\r\n79\r\n96\r\n77\r\n29\r\n88\r\n83\r\n83\r\n46\r\n94\r\n61\r\n56\r\n68\r\n43\r\n15\r\n79\r\n26\r\n36\r\n99\r\n36\r\n55\r\n77\r\n23\r\n15\r\n12\r\n84\r\n57\r\n82\r\n33\r\n14\r\n", "output": ["254 10099"]}, {"input": "100\r\n8000\r\n88\r\n40\r\n39\r\n88\r\n33\r\n2\r\n60\r\n93\r\n62\r\n18\r\n44\r\n53\r\n79\r\n55\r\n34\r\n71\r\n45\r\n82\r\n97\r\n96\r\n96\r\n25\r\n83\r\n83\r\n54\r\n45\r\n47\r\n59\r\n94\r\n84\r\n12\r\n33\r\n97\r\n24\r\n71\r\n28\r\n81\r\n89\r\n52\r\n87\r\n96\r\n35\r\n34\r\n31\r\n45\r\n42\r\n14\r\n74\r\n8\r\n68\r\n61\r\n36\r\n65\r\n87\r\n31\r\n18\r\n38\r\n84\r\n28\r\n74\r\n98\r\n77\r\n15\r\n85\r\n82\r\n64\r\n2\r\n93\r\n31\r\n78\r\n64\r\n35\r\n6\r\n77\r\n55\r\n70\r\n83\r\n42\r\n98\r\n38\r\n59\r\n99\r\n27\r\n66\r\n10\r\n54\r\n22\r\n94\r\n21\r\n21\r\n89\r\n86\r\n73\r\n12\r\n86\r\n1\r\n98\r\n94\r\n48\r\n51\r\n", "output": ["137 8099"]}, {"input": "10\r\n10\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n", "output": ["2 11"]}, {"input": "10\r\n10\r\n1\r\n1\r\n1\r\n2\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n", "output": ["3 12"]}, {"input": "100\r\n1000\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n", "output": ["11 1001"]}, {"input": "1\r\n10000\r\n57\r\n", "output": ["10057 10057"]}, {"input": "1\r\n1000\r\n48\r\n", "output": ["1048 1048"]}, {"input": "2\r\n1000\r\n1\r\n7\r\n", "output": ["504 1007"]}, {"input": "5\r\n10\r\n68\r\n87\r\n14\r\n68\r\n23\r\n", "output": ["87 97"]}, {"input": "10\r\n20\r\n80\r\n41\r\n15\r\n77\r\n91\r\n82\r\n15\r\n83\r\n36\r\n3\r\n", "output": ["91 111"]}, {"input": "20\r\n3303\r\n25\r\n14\r\n77\r\n85\r\n66\r\n97\r\n9\r\n60\r\n79\r\n39\r\n47\r\n2\r\n97\r\n71\r\n45\r\n36\r\n92\r\n54\r\n62\r\n53\r\n", "output": ["221 3400"]}, {"input": "40\r\n10000\r\n54\r\n5\r\n23\r\n10\r\n10\r\n77\r\n15\r\n84\r\n92\r\n63\r\n34\r\n21\r\n12\r\n56\r\n25\r\n32\r\n28\r\n50\r\n50\r\n86\r\n3\r\n26\r\n39\r\n69\r\n43\r\n99\r\n71\r\n38\r\n15\r\n33\r\n50\r\n79\r\n54\r\n84\r\n33\r\n47\r\n14\r\n66\r\n99\r\n25\r\n", "output": ["296 10099"]}, {"input": "66\r\n1000\r\n27\r\n10\r\n63\r\n17\r\n28\r\n89\r\n34\r\n86\r\n27\r\n62\r\n26\r\n18\r\n25\r\n31\r\n45\r\n44\r\n92\r\n56\r\n47\r\n18\r\n53\r\n56\r\n79\r\n3\r\n9\r\n32\r\n88\r\n52\r\n21\r\n57\r\n97\r\n84\r\n50\r\n12\r\n6\r\n52\r\n21\r\n37\r\n24\r\n84\r\n44\r\n81\r\n41\r\n47\r\n7\r\n67\r\n93\r\n43\r\n100\r\n64\r\n82\r\n46\r\n28\r\n48\r\n1\r\n34\r\n28\r\n82\r\n15\r\n47\r\n1\r\n19\r\n34\r\n12\r\n48\r\n48\r\n", "output": ["100 1100"]}, {"input": "78\r\n9909\r\n63\r\n38\r\n36\r\n74\r\n56\r\n3\r\n27\r\n99\r\n71\r\n95\r\n81\r\n39\r\n45\r\n75\r\n32\r\n42\r\n5\r\n23\r\n45\r\n46\r\n63\r\n69\r\n75\r\n80\r\n89\r\n48\r\n86\r\n74\r\n18\r\n87\r\n4\r\n55\r\n54\r\n8\r\n15\r\n91\r\n39\r\n13\r\n89\r\n95\r\n75\r\n38\r\n31\r\n27\r\n48\r\n81\r\n47\r\n91\r\n62\r\n88\r\n53\r\n45\r\n73\r\n79\r\n42\r\n57\r\n72\r\n99\r\n16\r\n52\r\n15\r\n52\r\n95\r\n98\r\n26\r\n84\r\n4\r\n88\r\n31\r\n26\r\n9\r\n86\r\n29\r\n45\r\n62\r\n18\r\n99\r\n78\r\n", "output": ["182 10008"]}, {"input": "89\r\n9080\r\n29\r\n88\r\n62\r\n50\r\n63\r\n91\r\n24\r\n3\r\n93\r\n76\r\n73\r\n50\r\n26\r\n32\r\n87\r\n93\r\n48\r\n52\r\n97\r\n68\r\n100\r\n84\r\n42\r\n93\r\n59\r\n68\r\n46\r\n19\r\n53\r\n30\r\n53\r\n20\r\n65\r\n43\r\n22\r\n98\r\n46\r\n45\r\n38\r\n37\r\n45\r\n31\r\n2\r\n24\r\n56\r\n74\r\n93\r\n48\r\n40\r\n68\r\n7\r\n4\r\n68\r\n44\r\n31\r\n63\r\n32\r\n21\r\n94\r\n92\r\n99\r\n93\r\n17\r\n18\r\n18\r\n48\r\n71\r\n38\r\n67\r\n67\r\n29\r\n87\r\n38\r\n66\r\n73\r\n61\r\n59\r\n98\r\n91\r\n33\r\n22\r\n56\r\n75\r\n91\r\n73\r\n83\r\n61\r\n41\r\n70\r\n", "output": ["158 9180"]}, {"input": "90\r\n10000\r\n43\r\n85\r\n87\r\n11\r\n50\r\n66\r\n30\r\n90\r\n23\r\n22\r\n16\r\n20\r\n2\r\n60\r\n8\r\n26\r\n56\r\n89\r\n50\r\n40\r\n3\r\n23\r\n9\r\n66\r\n36\r\n85\r\n19\r\n49\r\n87\r\n97\r\n20\r\n23\r\n75\r\n32\r\n3\r\n38\r\n71\r\n54\r\n79\r\n46\r\n62\r\n27\r\n16\r\n2\r\n24\r\n55\r\n76\r\n83\r\n55\r\n47\r\n46\r\n41\r\n63\r\n30\r\n22\r\n84\r\n70\r\n81\r\n59\r\n44\r\n56\r\n23\r\n67\r\n9\r\n60\r\n54\r\n95\r\n36\r\n73\r\n60\r\n33\r\n20\r\n18\r\n67\r\n20\r\n18\r\n7\r\n65\r\n55\r\n54\r\n45\r\n32\r\n38\r\n52\r\n15\r\n15\r\n88\r\n44\r\n47\r\n88\r\n", "output": ["157 10097"]}, {"input": "99\r\n1092\r\n28\r\n89\r\n65\r\n40\r\n96\r\n47\r\n76\r\n2\r\n62\r\n59\r\n60\r\n90\r\n91\r\n12\r\n10\r\n71\r\n57\r\n97\r\n18\r\n52\r\n82\r\n32\r\n71\r\n77\r\n39\r\n16\r\n84\r\n89\r\n26\r\n95\r\n45\r\n15\r\n93\r\n73\r\n63\r\n32\r\n33\r\n3\r\n64\r\n12\r\n92\r\n12\r\n92\r\n80\r\n3\r\n80\r\n47\r\n26\r\n69\r\n84\r\n96\r\n40\r\n86\r\n95\r\n55\r\n13\r\n64\r\n73\r\n52\r\n37\r\n13\r\n98\r\n86\r\n95\r\n43\r\n67\r\n18\r\n98\r\n100\r\n66\r\n5\r\n25\r\n87\r\n25\r\n37\r\n10\r\n29\r\n43\r\n84\r\n72\r\n17\r\n70\r\n31\r\n96\r\n27\r\n38\r\n1\r\n40\r\n74\r\n17\r\n58\r\n39\r\n18\r\n5\r\n41\r\n15\r\n95\r\n53\r\n77\r\n", "output": ["100 1192"]}, {"input": "100\r\n66\r\n95\r\n19\r\n88\r\n15\r\n29\r\n52\r\n37\r\n75\r\n21\r\n90\r\n93\r\n75\r\n91\r\n71\r\n53\r\n55\r\n90\r\n78\r\n19\r\n63\r\n43\r\n25\r\n52\r\n10\r\n55\r\n76\r\n47\r\n42\r\n57\r\n45\r\n35\r\n53\r\n2\r\n62\r\n61\r\n99\r\n59\r\n59\r\n43\r\n45\r\n31\r\n37\r\n50\r\n68\r\n51\r\n91\r\n34\r\n48\r\n40\r\n69\r\n77\r\n33\r\n16\r\n64\r\n19\r\n82\r\n76\r\n35\r\n41\r\n41\r\n79\r\n29\r\n69\r\n100\r\n30\r\n81\r\n47\r\n55\r\n79\r\n21\r\n59\r\n3\r\n11\r\n43\r\n49\r\n100\r\n27\r\n87\r\n64\r\n8\r\n6\r\n7\r\n88\r\n71\r\n98\r\n6\r\n32\r\n53\r\n91\r\n85\r\n60\r\n35\r\n55\r\n5\r\n44\r\n66\r\n76\r\n99\r\n7\r\n58\r\n", "output": ["100 166"]}, {"input": "100\r\n50\r\n20\r\n63\r\n60\r\n88\r\n7\r\n22\r\n90\r\n15\r\n27\r\n82\r\n37\r\n44\r\n42\r\n50\r\n33\r\n46\r\n7\r\n97\r\n93\r\n5\r\n68\r\n79\r\n76\r\n3\r\n82\r\n5\r\n51\r\n79\r\n17\r\n1\r\n1\r\n93\r\n52\r\n88\r\n23\r\n23\r\n49\r\n86\r\n64\r\n18\r\n36\r\n53\r\n49\r\n47\r\n11\r\n19\r\n6\r\n79\r\n64\r\n59\r\n56\r\n96\r\n15\r\n72\r\n81\r\n45\r\n24\r\n55\r\n31\r\n2\r\n74\r\n64\r\n57\r\n65\r\n71\r\n44\r\n8\r\n7\r\n38\r\n50\r\n67\r\n1\r\n79\r\n89\r\n16\r\n35\r\n10\r\n72\r\n69\r\n8\r\n56\r\n42\r\n44\r\n95\r\n25\r\n26\r\n16\r\n84\r\n36\r\n73\r\n17\r\n61\r\n91\r\n15\r\n19\r\n78\r\n44\r\n77\r\n96\r\n58\r\n", "output": ["97 147"]}, {"input": "100\r\n100\r\n82\r\n51\r\n81\r\n14\r\n37\r\n17\r\n78\r\n92\r\n64\r\n15\r\n8\r\n86\r\n89\r\n8\r\n87\r\n77\r\n66\r\n10\r\n15\r\n12\r\n100\r\n25\r\n92\r\n47\r\n21\r\n78\r\n20\r\n63\r\n13\r\n49\r\n41\r\n36\r\n41\r\n79\r\n16\r\n87\r\n87\r\n69\r\n3\r\n76\r\n80\r\n60\r\n100\r\n49\r\n70\r\n59\r\n72\r\n8\r\n38\r\n71\r\n45\r\n97\r\n71\r\n14\r\n76\r\n54\r\n81\r\n4\r\n59\r\n46\r\n39\r\n29\r\n92\r\n3\r\n49\r\n22\r\n53\r\n99\r\n59\r\n52\r\n74\r\n31\r\n92\r\n43\r\n42\r\n23\r\n44\r\n9\r\n82\r\n47\r\n7\r\n40\r\n12\r\n9\r\n3\r\n55\r\n37\r\n85\r\n46\r\n22\r\n84\r\n52\r\n98\r\n41\r\n21\r\n77\r\n63\r\n17\r\n62\r\n91\r\n", "output": ["100 200"]}, {"input": "100\r\n1000\r\n91\r\n17\r\n88\r\n51\r\n92\r\n47\r\n85\r\n3\r\n82\r\n61\r\n2\r\n48\r\n55\r\n56\r\n71\r\n1\r\n12\r\n78\r\n80\r\n31\r\n42\r\n33\r\n85\r\n99\r\n25\r\n25\r\n37\r\n18\r\n29\r\n53\r\n84\r\n88\r\n4\r\n55\r\n24\r\n3\r\n53\r\n53\r\n1\r\n95\r\n36\r\n84\r\n65\r\n5\r\n40\r\n52\r\n49\r\n77\r\n48\r\n5\r\n77\r\n50\r\n31\r\n80\r\n100\r\n46\r\n28\r\n29\r\n34\r\n83\r\n26\r\n3\r\n100\r\n63\r\n100\r\n23\r\n76\r\n4\r\n70\r\n57\r\n10\r\n58\r\n7\r\n20\r\n84\r\n44\r\n86\r\n54\r\n2\r\n11\r\n85\r\n3\r\n35\r\n83\r\n96\r\n97\r\n55\r\n75\r\n39\r\n39\r\n39\r\n61\r\n19\r\n86\r\n76\r\n72\r\n29\r\n69\r\n20\r\n17\r\n", "output": ["100 1100"]}, {"input": "100\r\n2000\r\n77\r\n39\r\n49\r\n44\r\n85\r\n10\r\n28\r\n49\r\n92\r\n64\r\n67\r\n39\r\n65\r\n53\r\n81\r\n58\r\n63\r\n80\r\n74\r\n27\r\n10\r\n45\r\n9\r\n26\r\n31\r\n98\r\n55\r\n61\r\n51\r\n43\r\n2\r\n95\r\n77\r\n52\r\n79\r\n42\r\n89\r\n99\r\n68\r\n6\r\n29\r\n71\r\n63\r\n96\r\n11\r\n10\r\n77\r\n32\r\n89\r\n28\r\n12\r\n19\r\n84\r\n34\r\n22\r\n69\r\n86\r\n24\r\n35\r\n40\r\n5\r\n100\r\n55\r\n35\r\n69\r\n60\r\n74\r\n72\r\n37\r\n44\r\n82\r\n83\r\n91\r\n1\r\n68\r\n24\r\n79\r\n39\r\n47\r\n57\r\n16\r\n76\r\n64\r\n34\r\n72\r\n3\r\n48\r\n35\r\n15\r\n70\r\n33\r\n78\r\n31\r\n48\r\n10\r\n30\r\n55\r\n43\r\n6\r\n93\r\n", "output": ["100 2100"]}, {"input": "100\r\n5000\r\n30\r\n90\r\n42\r\n18\r\n55\r\n6\r\n50\r\n65\r\n31\r\n89\r\n47\r\n48\r\n76\r\n58\r\n10\r\n18\r\n2\r\n79\r\n39\r\n9\r\n7\r\n89\r\n100\r\n1\r\n44\r\n23\r\n99\r\n12\r\n23\r\n15\r\n55\r\n16\r\n95\r\n40\r\n23\r\n37\r\n87\r\n42\r\n54\r\n51\r\n11\r\n57\r\n44\r\n61\r\n32\r\n74\r\n44\r\n5\r\n1\r\n96\r\n32\r\n30\r\n21\r\n13\r\n77\r\n48\r\n62\r\n6\r\n28\r\n7\r\n49\r\n87\r\n33\r\n60\r\n72\r\n64\r\n88\r\n86\r\n34\r\n13\r\n23\r\n59\r\n46\r\n39\r\n5\r\n45\r\n81\r\n88\r\n75\r\n97\r\n40\r\n88\r\n46\r\n100\r\n87\r\n30\r\n37\r\n13\r\n68\r\n43\r\n9\r\n32\r\n48\r\n28\r\n100\r\n14\r\n28\r\n67\r\n73\r\n26\r\n", "output": ["100 5100"]}, {"input": "100\r\n9990\r\n22\r\n89\r\n54\r\n55\r\n92\r\n20\r\n84\r\n12\r\n93\r\n6\r\n73\r\n50\r\n23\r\n62\r\n97\r\n88\r\n59\r\n87\r\n4\r\n14\r\n49\r\n28\r\n47\r\n93\r\n5\r\n36\r\n50\r\n78\r\n83\r\n99\r\n100\r\n27\r\n24\r\n23\r\n27\r\n84\r\n67\r\n72\r\n45\r\n51\r\n53\r\n32\r\n60\r\n9\r\n77\r\n63\r\n15\r\n98\r\n17\r\n49\r\n58\r\n77\r\n50\r\n31\r\n10\r\n6\r\n16\r\n74\r\n50\r\n99\r\n100\r\n36\r\n51\r\n71\r\n89\r\n65\r\n17\r\n62\r\n32\r\n3\r\n25\r\n39\r\n19\r\n2\r\n25\r\n75\r\n25\r\n89\r\n87\r\n13\r\n96\r\n91\r\n10\r\n1\r\n94\r\n39\r\n10\r\n64\r\n26\r\n28\r\n32\r\n7\r\n16\r\n34\r\n96\r\n28\r\n24\r\n35\r\n82\r\n99\r\n", "output": ["150 10090"]}, {"input": "100\r\n10000\r\n25\r\n90\r\n88\r\n97\r\n71\r\n24\r\n53\r\n4\r\n32\r\n69\r\n53\r\n93\r\n80\r\n14\r\n30\r\n65\r\n9\r\n56\r\n3\r\n23\r\n70\r\n25\r\n31\r\n6\r\n13\r\n19\r\n49\r\n58\r\n95\r\n40\r\n26\r\n72\r\n75\r\n44\r\n86\r\n13\r\n94\r\n11\r\n83\r\n75\r\n26\r\n64\r\n100\r\n84\r\n82\r\n35\r\n80\r\n41\r\n40\r\n8\r\n5\r\n28\r\n3\r\n98\r\n1\r\n22\r\n73\r\n33\r\n44\r\n22\r\n2\r\n72\r\n68\r\n80\r\n39\r\n92\r\n75\r\n67\r\n61\r\n26\r\n89\r\n59\r\n19\r\n29\r\n7\r\n60\r\n91\r\n34\r\n73\r\n53\r\n22\r\n2\r\n85\r\n22\r\n47\r\n92\r\n90\r\n99\r\n100\r\n44\r\n82\r\n19\r\n1\r\n49\r\n100\r\n13\r\n67\r\n32\r\n75\r\n98\r\n", "output": ["151 10100"]}, {"input": "100\r\n10000\r\n45\r\n35\r\n50\r\n78\r\n28\r\n97\r\n37\r\n92\r\n91\r\n51\r\n93\r\n33\r\n70\r\n43\r\n53\r\n78\r\n31\r\n14\r\n29\r\n67\r\n11\r\n7\r\n41\r\n85\r\n70\r\n27\r\n74\r\n15\r\n15\r\n10\r\n52\r\n50\r\n66\r\n81\r\n95\r\n25\r\n28\r\n86\r\n17\r\n89\r\n19\r\n87\r\n85\r\n38\r\n79\r\n19\r\n92\r\n85\r\n62\r\n71\r\n18\r\n72\r\n92\r\n18\r\n93\r\n56\r\n64\r\n54\r\n3\r\n38\r\n18\r\n77\r\n3\r\n54\r\n70\r\n49\r\n56\r\n91\r\n60\r\n56\r\n34\r\n54\r\n42\r\n41\r\n75\r\n90\r\n43\r\n21\r\n18\r\n69\r\n76\r\n51\r\n24\r\n50\r\n82\r\n56\r\n62\r\n45\r\n50\r\n67\r\n20\r\n31\r\n12\r\n10\r\n10\r\n7\r\n75\r\n84\r\n17\r\n18\r\n", "output": ["151 10097"]}, {"input": "2\r\n50\r\n1\r\n51\r\n", "output": ["51 101"]}, {"input": "3\r\n100\r\n52\r\n2\r\n2\r\n", "output": ["52 152"]}, {"input": "100\r\n300\r\n1\r\n1\r\n2\r\n2\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n2\r\n2\r\n1\r\n2\r\n2\r\n1\r\n2\r\n2\r\n2\r\n2\r\n2\r\n1\r\n1\r\n1\r\n2\r\n1\r\n2\r\n1\r\n1\r\n1\r\n2\r\n1\r\n1\r\n1\r\n2\r\n1\r\n2\r\n1\r\n2\r\n1\r\n2\r\n1\r\n2\r\n1\r\n2\r\n1\r\n1\r\n1\r\n1\r\n2\r\n2\r\n2\r\n1\r\n1\r\n2\r\n1\r\n2\r\n2\r\n2\r\n1\r\n1\r\n2\r\n2\r\n2\r\n2\r\n2\r\n2\r\n1\r\n1\r\n2\r\n2\r\n2\r\n2\r\n1\r\n2\r\n2\r\n2\r\n1\r\n2\r\n1\r\n1\r\n2\r\n2\r\n1\r\n1\r\n1\r\n1\r\n2\r\n1\r\n2\r\n2\r\n1\r\n2\r\n2\r\n1\r\n1\r\n2\r\n1\r\n2\r\n2\r\n", "output": ["5 302"]}, {"input": "100\r\n3000\r\n99\r\n100\r\n99\r\n99\r\n100\r\n99\r\n100\r\n99\r\n99\r\n100\r\n99\r\n100\r\n100\r\n99\r\n100\r\n100\r\n99\r\n99\r\n99\r\n100\r\n100\r\n100\r\n100\r\n100\r\n99\r\n100\r\n100\r\n99\r\n100\r\n100\r\n99\r\n99\r\n99\r\n99\r\n100\r\n100\r\n99\r\n99\r\n99\r\n100\r\n99\r\n100\r\n100\r\n99\r\n99\r\n100\r\n100\r\n100\r\n99\r\n99\r\n99\r\n100\r\n99\r\n99\r\n99\r\n100\r\n99\r\n99\r\n100\r\n99\r\n100\r\n100\r\n100\r\n99\r\n99\r\n100\r\n100\r\n100\r\n99\r\n100\r\n100\r\n99\r\n99\r\n100\r\n100\r\n99\r\n100\r\n100\r\n100\r\n99\r\n99\r\n100\r\n100\r\n99\r\n100\r\n99\r\n99\r\n100\r\n99\r\n99\r\n99\r\n100\r\n99\r\n100\r\n100\r\n100\r\n99\r\n100\r\n99\r\n100\r\n", "output": ["130 3100"]}, {"input": "100\r\n10000\r\n54\r\n54\r\n50\r\n52\r\n55\r\n51\r\n50\r\n53\r\n50\r\n56\r\n50\r\n51\r\n51\r\n52\r\n54\r\n50\r\n54\r\n52\r\n53\r\n56\r\n55\r\n51\r\n52\r\n55\r\n56\r\n52\r\n52\r\n56\r\n51\r\n56\r\n51\r\n51\r\n55\r\n54\r\n52\r\n55\r\n51\r\n55\r\n56\r\n54\r\n55\r\n54\r\n56\r\n56\r\n51\r\n52\r\n52\r\n56\r\n51\r\n52\r\n52\r\n55\r\n53\r\n51\r\n55\r\n51\r\n54\r\n52\r\n56\r\n51\r\n50\r\n52\r\n52\r\n55\r\n53\r\n52\r\n53\r\n53\r\n51\r\n52\r\n54\r\n50\r\n53\r\n53\r\n56\r\n52\r\n52\r\n54\r\n54\r\n52\r\n55\r\n53\r\n54\r\n53\r\n54\r\n55\r\n56\r\n51\r\n54\r\n55\r\n50\r\n56\r\n52\r\n50\r\n55\r\n55\r\n54\r\n55\r\n50\r\n50\r\n", "output": ["154 10056"]}, {"input": "100\r\n2325\r\n78\r\n78\r\n80\r\n78\r\n79\r\n80\r\n79\r\n80\r\n79\r\n80\r\n78\r\n80\r\n79\r\n80\r\n78\r\n78\r\n79\r\n80\r\n80\r\n80\r\n79\r\n79\r\n79\r\n79\r\n80\r\n80\r\n79\r\n80\r\n79\r\n80\r\n79\r\n79\r\n79\r\n79\r\n80\r\n80\r\n80\r\n78\r\n80\r\n80\r\n80\r\n78\r\n80\r\n80\r\n80\r\n80\r\n78\r\n78\r\n79\r\n79\r\n79\r\n79\r\n80\r\n78\r\n80\r\n78\r\n80\r\n80\r\n80\r\n79\r\n78\r\n79\r\n80\r\n80\r\n78\r\n78\r\n80\r\n78\r\n80\r\n79\r\n78\r\n80\r\n78\r\n78\r\n80\r\n80\r\n78\r\n78\r\n79\r\n78\r\n78\r\n79\r\n79\r\n78\r\n80\r\n78\r\n78\r\n80\r\n80\r\n80\r\n78\r\n80\r\n78\r\n79\r\n80\r\n78\r\n80\r\n79\r\n78\r\n79\r\n", "output": ["103 2405"]}, {"input": "100\r\n3241\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n", "output": ["133 3341"]}, {"input": "100\r\n9675\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n", "output": ["98 9676"]}, {"input": "100\r\n9435\r\n36\r\n37\r\n36\r\n36\r\n37\r\n34\r\n35\r\n37\r\n36\r\n34\r\n37\r\n35\r\n34\r\n35\r\n35\r\n36\r\n36\r\n37\r\n37\r\n36\r\n37\r\n34\r\n36\r\n35\r\n37\r\n36\r\n34\r\n35\r\n35\r\n35\r\n34\r\n36\r\n37\r\n36\r\n35\r\n34\r\n35\r\n34\r\n34\r\n34\r\n36\r\n37\r\n37\r\n34\r\n37\r\n34\r\n37\r\n36\r\n35\r\n36\r\n37\r\n35\r\n37\r\n35\r\n36\r\n34\r\n36\r\n35\r\n35\r\n35\r\n37\r\n37\r\n36\r\n34\r\n35\r\n35\r\n36\r\n35\r\n34\r\n35\r\n35\r\n35\r\n37\r\n36\r\n34\r\n35\r\n37\r\n36\r\n36\r\n36\r\n36\r\n35\r\n34\r\n37\r\n35\r\n34\r\n37\r\n37\r\n36\r\n37\r\n37\r\n34\r\n36\r\n35\r\n36\r\n35\r\n34\r\n37\r\n34\r\n35\r\n", "output": ["130 9472"]}, {"input": "100\r\n9999\r\n4\r\n5\r\n1\r\n8\r\n8\r\n2\r\n9\r\n5\r\n8\r\n6\r\n10\r\n8\r\n2\r\n10\r\n5\r\n10\r\n10\r\n3\r\n3\r\n1\r\n9\r\n7\r\n1\r\n5\r\n3\r\n7\r\n1\r\n3\r\n7\r\n3\r\n7\r\n8\r\n8\r\n8\r\n10\r\n3\r\n9\r\n9\r\n5\r\n9\r\n4\r\n7\r\n3\r\n8\r\n8\r\n6\r\n9\r\n4\r\n4\r\n8\r\n3\r\n6\r\n3\r\n3\r\n7\r\n10\r\n4\r\n2\r\n4\r\n3\r\n9\r\n10\r\n2\r\n4\r\n3\r\n1\r\n3\r\n4\r\n4\r\n4\r\n5\r\n8\r\n6\r\n3\r\n9\r\n10\r\n7\r\n7\r\n10\r\n2\r\n6\r\n10\r\n7\r\n7\r\n10\r\n6\r\n2\r\n9\r\n8\r\n1\r\n6\r\n7\r\n3\r\n5\r\n8\r\n6\r\n1\r\n3\r\n8\r\n5\r\n", "output": ["106 10009"]}, {"input": "100\r\n2344\r\n42\r\n40\r\n69\r\n62\r\n79\r\n43\r\n36\r\n55\r\n44\r\n13\r\n48\r\n69\r\n46\r\n61\r\n70\r\n75\r\n51\r\n67\r\n57\r\n35\r\n5\r\n19\r\n6\r\n92\r\n78\r\n59\r\n42\r\n3\r\n81\r\n41\r\n70\r\n90\r\n99\r\n93\r\n44\r\n22\r\n80\r\n62\r\n69\r\n95\r\n12\r\n63\r\n99\r\n42\r\n12\r\n9\r\n72\r\n8\r\n19\r\n33\r\n81\r\n33\r\n66\r\n32\r\n10\r\n50\r\n98\r\n83\r\n11\r\n25\r\n81\r\n13\r\n56\r\n60\r\n4\r\n89\r\n75\r\n59\r\n92\r\n7\r\n55\r\n84\r\n48\r\n85\r\n82\r\n18\r\n29\r\n68\r\n60\r\n25\r\n26\r\n37\r\n12\r\n15\r\n27\r\n17\r\n85\r\n20\r\n16\r\n47\r\n76\r\n55\r\n75\r\n66\r\n47\r\n98\r\n90\r\n32\r\n47\r\n9\r\n", "output": ["99 2443"]}, {"input": "100\r\n1\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n", "output": ["101 101"]}, {"input": "100\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n", "output": ["2 2"]}, {"input": "100\r\n2\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n50\r\n", "output": ["51 52"]}, {"input": "100\r\n300\r\n1\r\n1\r\n2\r\n2\r\n1\r\n2\r\n2\r\n2\r\n1\r\n2\r\n2\r\n2\r\n1\r\n2\r\n1\r\n1\r\n2\r\n2\r\n1\r\n1\r\n2\r\n1\r\n1\r\n2\r\n1\r\n2\r\n2\r\n2\r\n2\r\n2\r\n2\r\n1\r\n1\r\n1\r\n2\r\n2\r\n2\r\n2\r\n1\r\n1\r\n1\r\n2\r\n1\r\n1\r\n2\r\n2\r\n2\r\n1\r\n2\r\n2\r\n2\r\n1\r\n2\r\n2\r\n1\r\n2\r\n1\r\n1\r\n2\r\n2\r\n2\r\n2\r\n1\r\n2\r\n2\r\n2\r\n1\r\n1\r\n2\r\n1\r\n1\r\n1\r\n1\r\n2\r\n2\r\n2\r\n2\r\n2\r\n1\r\n2\r\n1\r\n1\r\n1\r\n1\r\n2\r\n1\r\n1\r\n2\r\n2\r\n1\r\n2\r\n1\r\n1\r\n1\r\n2\r\n2\r\n93\r\n1\r\n2\r\n2\r\n", "output": ["93 393"]}, {"input": "100\r\n3000\r\n2\r\n4\r\n4\r\n5\r\n3\r\n3\r\n5\r\n5\r\n2\r\n4\r\n4\r\n2\r\n3\r\n1\r\n5\r\n5\r\n5\r\n3\r\n3\r\n1\r\n2\r\n2\r\n3\r\n3\r\n5\r\n5\r\n3\r\n5\r\n2\r\n1\r\n4\r\n4\r\n5\r\n3\r\n4\r\n3\r\n1\r\n3\r\n5\r\n1\r\n3\r\n3\r\n3\r\n5\r\n3\r\n4\r\n1\r\n3\r\n1\r\n5\r\n5\r\n5\r\n5\r\n3\r\n5\r\n5\r\n2\r\n1\r\n4\r\n2\r\n5\r\n1\r\n1\r\n5\r\n1\r\n3\r\n3\r\n1\r\n4\r\n2\r\n4\r\n3\r\n4\r\n4\r\n5\r\n2\r\n5\r\n95\r\n1\r\n2\r\n1\r\n2\r\n5\r\n3\r\n3\r\n2\r\n3\r\n4\r\n2\r\n3\r\n3\r\n2\r\n3\r\n4\r\n4\r\n4\r\n4\r\n3\r\n3\r\n2\r\n", "output": ["95 3095"]}, {"input": "100\r\n10000\r\n51\r\n53\r\n53\r\n54\r\n52\r\n52\r\n51\r\n53\r\n52\r\n55\r\n53\r\n51\r\n56\r\n55\r\n55\r\n50\r\n53\r\n53\r\n50\r\n52\r\n53\r\n50\r\n51\r\n56\r\n54\r\n50\r\n53\r\n51\r\n54\r\n50\r\n50\r\n55\r\n50\r\n53\r\n52\r\n52\r\n54\r\n56\r\n56\r\n52\r\n54\r\n56\r\n52\r\n52\r\n55\r\n54\r\n56\r\n53\r\n54\r\n53\r\n55\r\n50\r\n55\r\n54\r\n54\r\n56\r\n50\r\n50\r\n56\r\n55\r\n55\r\n53\r\n52\r\n54\r\n52\r\n53\r\n50\r\n53\r\n54\r\n52\r\n53\r\n52\r\n52\r\n56\r\n51\r\n53\r\n53\r\n55\r\n50\r\n50\r\n51\r\n55\r\n55\r\n51\r\n50\r\n51\r\n50\r\n54\r\n93\r\n50\r\n50\r\n55\r\n55\r\n50\r\n54\r\n55\r\n55\r\n53\r\n53\r\n56\r\n", "output": ["154 10093"]}, {"input": "100\r\n2325\r\n30\r\n18\r\n24\r\n24\r\n23\r\n23\r\n18\r\n28\r\n26\r\n28\r\n29\r\n23\r\n22\r\n19\r\n26\r\n26\r\n29\r\n20\r\n26\r\n30\r\n30\r\n26\r\n27\r\n25\r\n24\r\n25\r\n27\r\n22\r\n22\r\n19\r\n23\r\n22\r\n25\r\n27\r\n25\r\n21\r\n25\r\n26\r\n22\r\n20\r\n29\r\n21\r\n21\r\n22\r\n26\r\n29\r\n18\r\n22\r\n19\r\n23\r\n29\r\n30\r\n25\r\n22\r\n24\r\n30\r\n22\r\n23\r\n22\r\n26\r\n24\r\n19\r\n27\r\n20\r\n27\r\n29\r\n30\r\n22\r\n30\r\n26\r\n22\r\n19\r\n23\r\n20\r\n21\r\n26\r\n20\r\n30\r\n26\r\n24\r\n30\r\n20\r\n26\r\n24\r\n97\r\n25\r\n23\r\n19\r\n22\r\n19\r\n23\r\n29\r\n28\r\n28\r\n26\r\n29\r\n23\r\n26\r\n28\r\n20\r\n", "output": ["97 2422"]}, {"input": "100\r\n3241\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n93\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n", "output": ["93 3334"]}, {"input": "100\r\n9675\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n99\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n", "output": ["99 9774"]}, {"input": "10\r\n1\r\n5\r\n5\r\n5\r\n5\r\n4\r\n5\r\n5\r\n5\r\n5\r\n5\r\n", "output": ["5 6"]}, {"input": "100\r\n9435\r\n15\r\n16\r\n21\r\n24\r\n22\r\n27\r\n24\r\n18\r\n26\r\n25\r\n17\r\n25\r\n14\r\n26\r\n15\r\n20\r\n17\r\n21\r\n17\r\n24\r\n26\r\n26\r\n27\r\n21\r\n24\r\n20\r\n26\r\n25\r\n25\r\n20\r\n22\r\n19\r\n14\r\n16\r\n17\r\n27\r\n16\r\n21\r\n16\r\n27\r\n21\r\n14\r\n24\r\n27\r\n24\r\n19\r\n25\r\n23\r\n21\r\n19\r\n16\r\n14\r\n25\r\n18\r\n96\r\n25\r\n24\r\n15\r\n20\r\n21\r\n22\r\n15\r\n24\r\n23\r\n14\r\n22\r\n26\r\n26\r\n16\r\n17\r\n23\r\n17\r\n25\r\n22\r\n21\r\n27\r\n26\r\n19\r\n25\r\n25\r\n23\r\n16\r\n25\r\n19\r\n15\r\n19\r\n18\r\n27\r\n17\r\n21\r\n25\r\n20\r\n27\r\n14\r\n26\r\n15\r\n27\r\n15\r\n24\r\n18\r\n", "output": ["117 9531"]}, {"input": "100\r\n9999\r\n1\r\n10\r\n5\r\n2\r\n9\r\n2\r\n10\r\n10\r\n9\r\n6\r\n10\r\n8\r\n10\r\n2\r\n10\r\n8\r\n5\r\n4\r\n8\r\n6\r\n3\r\n4\r\n8\r\n6\r\n1\r\n3\r\n8\r\n8\r\n7\r\n7\r\n5\r\n3\r\n2\r\n8\r\n4\r\n3\r\n7\r\n9\r\n9\r\n10\r\n7\r\n1\r\n10\r\n6\r\n2\r\n8\r\n7\r\n4\r\n3\r\n5\r\n9\r\n1\r\n10\r\n3\r\n4\r\n10\r\n1\r\n7\r\n1\r\n91\r\n10\r\n4\r\n7\r\n6\r\n4\r\n3\r\n2\r\n6\r\n3\r\n5\r\n5\r\n2\r\n3\r\n3\r\n1\r\n10\r\n10\r\n7\r\n10\r\n7\r\n8\r\n4\r\n6\r\n6\r\n1\r\n10\r\n2\r\n9\r\n6\r\n5\r\n1\r\n10\r\n8\r\n2\r\n10\r\n7\r\n8\r\n5\r\n3\r\n6\r\n", "output": ["107 10090"]}, {"input": "100\r\n2344\r\n23\r\n10\r\n18\r\n15\r\n32\r\n22\r\n10\r\n38\r\n32\r\n31\r\n39\r\n8\r\n26\r\n16\r\n22\r\n10\r\n23\r\n11\r\n25\r\n36\r\n24\r\n40\r\n7\r\n27\r\n43\r\n28\r\n23\r\n25\r\n7\r\n23\r\n22\r\n7\r\n43\r\n6\r\n22\r\n38\r\n7\r\n32\r\n35\r\n12\r\n41\r\n43\r\n97\r\n3\r\n37\r\n29\r\n27\r\n36\r\n17\r\n2\r\n27\r\n35\r\n16\r\n10\r\n3\r\n19\r\n12\r\n20\r\n29\r\n7\r\n14\r\n5\r\n31\r\n26\r\n10\r\n4\r\n3\r\n15\r\n32\r\n42\r\n24\r\n36\r\n41\r\n43\r\n36\r\n23\r\n14\r\n32\r\n3\r\n32\r\n21\r\n30\r\n32\r\n25\r\n32\r\n8\r\n27\r\n11\r\n19\r\n15\r\n34\r\n12\r\n41\r\n11\r\n39\r\n20\r\n14\r\n23\r\n7\r\n43\r\n", "output": ["97 2441"]}, {"input": "2\r\n1\r\n5\r\n1\r\n", "output": ["5 6"]}, {"input": "4\r\n1\r\n1\r\n9\r\n9\r\n9\r\n", "output": ["9 10"]}, {"input": "2\r\n3\r\n1\r\n100\r\n", "output": ["100 103"]}, {"input": "2\r\n16\r\n2\r\n100\r\n", "output": ["100 116"]}, {"input": "2\r\n1\r\n1\r\n100\r\n", "output": ["100 101"]}, {"input": "3\r\n7\r\n1\r\n6\r\n1\r\n", "output": ["6 13"]}, {"input": "2\r\n1\r\n10\r\n1\r\n", "output": ["10 11"]}, {"input": "3\r\n1\r\n1\r\n1\r\n99\r\n", "output": ["99 100"]}, {"input": "2\r\n2\r\n1\r\n100\r\n", "output": ["100 102"]}]
100
100
100
[{'input': '2\r\n16\r\n2\r\n100\r\n', 'output': ['100 116']}, {'input': '10\r\n1\r\n5\r\n5\r\n5\r\n5\r\n4\r\n5\r\n5\r\n5\r\n5\r\n5\r\n', 'output': ['5 6']}, {'input': '100\r\n300\r\n1\r\n1\r\n2\r\n2\r\n1\r\n2\r\n2\r\n2\r\n1\r\n2\r\n2\r\n2\r\n1\r\n2\r\n1\r\n1\r\n2\r\n2\r\n1\r\n1\r\n2\r\n1\r\n1\r\n2\r\n1\r\n2\r\n2\r\n2\r\n2\r\n2\r\n2\r\n1\r\n1\r\n1\r\n2\r\n2\r\n2\r\n2\r\n1\r\n1\r\n1\r\n2\r\n1\r\n1\r\n2\r\n2\r\n2\r\n1\r\n2\r\n2\r\n2\r\n1\r\n2\r\n2\r\n1\r\n2\r\n1\r\n1\r\n2\r\n2\r\n2\r\n2\r\n1\r\n2\r\n2\r\n2\r\n1\r\n1\r\n2\r\n1\r\n1\r\n1\r\n1\r\n2\r\n2\r\n2\r\n2\r\n2\r\n1\r\n2\r\n1\r\n1\r\n1\r\n1\r\n2\r\n1\r\n1\r\n2\r\n2\r\n1\r\n2\r\n1\r\n1\r\n1\r\n2\r\n2\r\n93\r\n1\r\n2\r\n2\r\n', 'output': ['93 393']}, {'input': '100\r\n2000\r\n77\r\n39\r\n49\r\n44\r\n85\r\n10\r\n28\r\n49\r\n92\r\n64\r\n67\r\n39\r\n65\r\n53\r\n81\r\n58\r\n63\r\n80\r\n74\r\n27\r\n10\r\n45\r\n9\r\n26\r\n31\r\n98\r\n55\r\n61\r\n51\r\n43\r\n2\r\n95\r\n77\r\n52\r\n79\r\n42\r\n89\r\n99\r\n68\r\n6\r\n29\r\n71\r\n63\r\n96\r\n11\r\n10\r\n77\r\n32\r\n89\r\n28\r\n12\r\n19\r\n84\r\n34\r\n22\r\n69\r\n86\r\n24\r\n35\r\n40\r\n5\r\n100\r\n55\r\n35\r\n69\r\n60\r\n74\r\n72\r\n37\r\n44\r\n82\r\n83\r\n91\r\n1\r\n68\r\n24\r\n79\r\n39\r\n47\r\n57\r\n16\r\n76\r\n64\r\n34\r\n72\r\n3\r\n48\r\n35\r\n15\r\n70\r\n33\r\n78\r\n31\r\n48\r\n10\r\n30\r\n55\r\n43\r\n6\r\n93\r\n', 'output': ['100 2100']}, {'input': '100\r\n3000\r\n99\r\n100\r\n99\r\n99\r\n100\r\n99\r\n100\r\n99\r\n99\r\n100\r\n99\r\n100\r\n100\r\n99\r\n100\r\n100\r\n99\r\n99\r\n99\r\n100\r\n100\r\n100\r\n100\r\n100\r\n99\r\n100\r\n100\r\n99\r\n100\r\n100\r\n99\r\n99\r\n99\r\n99\r\n100\r\n100\r\n99\r\n99\r\n99\r\n100\r\n99\r\n100\r\n100\r\n99\r\n99\r\n100\r\n100\r\n100\r\n99\r\n99\r\n99\r\n100\r\n99\r\n99\r\n99\r\n100\r\n99\r\n99\r\n100\r\n99\r\n100\r\n100\r\n100\r\n99\r\n99\r\n100\r\n100\r\n100\r\n99\r\n100\r\n100\r\n99\r\n99\r\n100\r\n100\r\n99\r\n100\r\n100\r\n100\r\n99\r\n99\r\n100\r\n100\r\n99\r\n100\r\n99\r\n99\r\n100\r\n99\r\n99\r\n99\r\n100\r\n99\r\n100\r\n100\r\n100\r\n99\r\n100\r\n99\r\n100\r\n', 'output': ['130 3100']}]
[{'input': '10\r\n1000\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n', 'output': ['200 1100']}, {'input': '100\r\n3241\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n', 'output': ['133 3341']}, {'input': '100\r\n3000\r\n99\r\n100\r\n99\r\n99\r\n100\r\n99\r\n100\r\n99\r\n99\r\n100\r\n99\r\n100\r\n100\r\n99\r\n100\r\n100\r\n99\r\n99\r\n99\r\n100\r\n100\r\n100\r\n100\r\n100\r\n99\r\n100\r\n100\r\n99\r\n100\r\n100\r\n99\r\n99\r\n99\r\n99\r\n100\r\n100\r\n99\r\n99\r\n99\r\n100\r\n99\r\n100\r\n100\r\n99\r\n99\r\n100\r\n100\r\n100\r\n99\r\n99\r\n99\r\n100\r\n99\r\n99\r\n99\r\n100\r\n99\r\n99\r\n100\r\n99\r\n100\r\n100\r\n100\r\n99\r\n99\r\n100\r\n100\r\n100\r\n99\r\n100\r\n100\r\n99\r\n99\r\n100\r\n100\r\n99\r\n100\r\n100\r\n100\r\n99\r\n99\r\n100\r\n100\r\n99\r\n100\r\n99\r\n99\r\n100\r\n99\r\n99\r\n99\r\n100\r\n99\r\n100\r\n100\r\n100\r\n99\r\n100\r\n99\r\n100\r\n', 'output': ['130 3100']}, {'input': '89\r\n9080\r\n29\r\n88\r\n62\r\n50\r\n63\r\n91\r\n24\r\n3\r\n93\r\n76\r\n73\r\n50\r\n26\r\n32\r\n87\r\n93\r\n48\r\n52\r\n97\r\n68\r\n100\r\n84\r\n42\r\n93\r\n59\r\n68\r\n46\r\n19\r\n53\r\n30\r\n53\r\n20\r\n65\r\n43\r\n22\r\n98\r\n46\r\n45\r\n38\r\n37\r\n45\r\n31\r\n2\r\n24\r\n56\r\n74\r\n93\r\n48\r\n40\r\n68\r\n7\r\n4\r\n68\r\n44\r\n31\r\n63\r\n32\r\n21\r\n94\r\n92\r\n99\r\n93\r\n17\r\n18\r\n18\r\n48\r\n71\r\n38\r\n67\r\n67\r\n29\r\n87\r\n38\r\n66\r\n73\r\n61\r\n59\r\n98\r\n91\r\n33\r\n22\r\n56\r\n75\r\n91\r\n73\r\n83\r\n61\r\n41\r\n70\r\n', 'output': ['158 9180']}, {'input': '100\r\n2000\r\n77\r\n39\r\n49\r\n44\r\n85\r\n10\r\n28\r\n49\r\n92\r\n64\r\n67\r\n39\r\n65\r\n53\r\n81\r\n58\r\n63\r\n80\r\n74\r\n27\r\n10\r\n45\r\n9\r\n26\r\n31\r\n98\r\n55\r\n61\r\n51\r\n43\r\n2\r\n95\r\n77\r\n52\r\n79\r\n42\r\n89\r\n99\r\n68\r\n6\r\n29\r\n71\r\n63\r\n96\r\n11\r\n10\r\n77\r\n32\r\n89\r\n28\r\n12\r\n19\r\n84\r\n34\r\n22\r\n69\r\n86\r\n24\r\n35\r\n40\r\n5\r\n100\r\n55\r\n35\r\n69\r\n60\r\n74\r\n72\r\n37\r\n44\r\n82\r\n83\r\n91\r\n1\r\n68\r\n24\r\n79\r\n39\r\n47\r\n57\r\n16\r\n76\r\n64\r\n34\r\n72\r\n3\r\n48\r\n35\r\n15\r\n70\r\n33\r\n78\r\n31\r\n48\r\n10\r\n30\r\n55\r\n43\r\n6\r\n93\r\n', 'output': ['100 2100']}]
[{'input': '10\r\n10\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n', 'output': ['2 11']}, {'input': '100\r\n3241\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n93\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n10\r\n', 'output': ['93 3334']}, {'input': '10\r\n1000\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n', 'output': ['200 1100']}, {'input': '100\r\n9435\r\n15\r\n16\r\n21\r\n24\r\n22\r\n27\r\n24\r\n18\r\n26\r\n25\r\n17\r\n25\r\n14\r\n26\r\n15\r\n20\r\n17\r\n21\r\n17\r\n24\r\n26\r\n26\r\n27\r\n21\r\n24\r\n20\r\n26\r\n25\r\n25\r\n20\r\n22\r\n19\r\n14\r\n16\r\n17\r\n27\r\n16\r\n21\r\n16\r\n27\r\n21\r\n14\r\n24\r\n27\r\n24\r\n19\r\n25\r\n23\r\n21\r\n19\r\n16\r\n14\r\n25\r\n18\r\n96\r\n25\r\n24\r\n15\r\n20\r\n21\r\n22\r\n15\r\n24\r\n23\r\n14\r\n22\r\n26\r\n26\r\n16\r\n17\r\n23\r\n17\r\n25\r\n22\r\n21\r\n27\r\n26\r\n19\r\n25\r\n25\r\n23\r\n16\r\n25\r\n19\r\n15\r\n19\r\n18\r\n27\r\n17\r\n21\r\n25\r\n20\r\n27\r\n14\r\n26\r\n15\r\n27\r\n15\r\n24\r\n18\r\n', 'output': ['117 9531']}, {'input': '100\r\n300\r\n1\r\n1\r\n2\r\n2\r\n1\r\n2\r\n2\r\n2\r\n1\r\n2\r\n2\r\n2\r\n1\r\n2\r\n1\r\n1\r\n2\r\n2\r\n1\r\n1\r\n2\r\n1\r\n1\r\n2\r\n1\r\n2\r\n2\r\n2\r\n2\r\n2\r\n2\r\n1\r\n1\r\n1\r\n2\r\n2\r\n2\r\n2\r\n1\r\n1\r\n1\r\n2\r\n1\r\n1\r\n2\r\n2\r\n2\r\n1\r\n2\r\n2\r\n2\r\n1\r\n2\r\n2\r\n1\r\n2\r\n1\r\n1\r\n2\r\n2\r\n2\r\n2\r\n1\r\n2\r\n2\r\n2\r\n1\r\n1\r\n2\r\n1\r\n1\r\n1\r\n1\r\n2\r\n2\r\n2\r\n2\r\n2\r\n1\r\n2\r\n1\r\n1\r\n1\r\n1\r\n2\r\n1\r\n1\r\n2\r\n2\r\n1\r\n2\r\n1\r\n1\r\n1\r\n2\r\n2\r\n93\r\n1\r\n2\r\n2\r\n', 'output': ['93 393']}]
[{'input': '100\r\n10000\r\n54\r\n54\r\n50\r\n52\r\n55\r\n51\r\n50\r\n53\r\n50\r\n56\r\n50\r\n51\r\n51\r\n52\r\n54\r\n50\r\n54\r\n52\r\n53\r\n56\r\n55\r\n51\r\n52\r\n55\r\n56\r\n52\r\n52\r\n56\r\n51\r\n56\r\n51\r\n51\r\n55\r\n54\r\n52\r\n55\r\n51\r\n55\r\n56\r\n54\r\n55\r\n54\r\n56\r\n56\r\n51\r\n52\r\n52\r\n56\r\n51\r\n52\r\n52\r\n55\r\n53\r\n51\r\n55\r\n51\r\n54\r\n52\r\n56\r\n51\r\n50\r\n52\r\n52\r\n55\r\n53\r\n52\r\n53\r\n53\r\n51\r\n52\r\n54\r\n50\r\n53\r\n53\r\n56\r\n52\r\n52\r\n54\r\n54\r\n52\r\n55\r\n53\r\n54\r\n53\r\n54\r\n55\r\n56\r\n51\r\n54\r\n55\r\n50\r\n56\r\n52\r\n50\r\n55\r\n55\r\n54\r\n55\r\n50\r\n50\r\n', 'output': ['154 10056']}, {'input': '51\r\n10000\r\n54\r\n23\r\n93\r\n86\r\n57\r\n68\r\n42\r\n33\r\n47\r\n18\r\n78\r\n41\r\n35\r\n92\r\n32\r\n97\r\n74\r\n93\r\n27\r\n59\r\n90\r\n23\r\n79\r\n96\r\n77\r\n29\r\n88\r\n83\r\n83\r\n46\r\n94\r\n61\r\n56\r\n68\r\n43\r\n15\r\n79\r\n26\r\n36\r\n99\r\n36\r\n55\r\n77\r\n23\r\n15\r\n12\r\n84\r\n57\r\n82\r\n33\r\n14\r\n', 'output': ['254 10099']}, {'input': '10\r\n10\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n', 'output': ['2 11']}, {'input': '20\r\n3303\r\n25\r\n14\r\n77\r\n85\r\n66\r\n97\r\n9\r\n60\r\n79\r\n39\r\n47\r\n2\r\n97\r\n71\r\n45\r\n36\r\n92\r\n54\r\n62\r\n53\r\n', 'output': ['221 3400']}, {'input': '2\r\n1\r\n10\r\n1\r\n', 'output': ['10 11']}]
[{'input': '51\r\n10000\r\n54\r\n23\r\n93\r\n86\r\n57\r\n68\r\n42\r\n33\r\n47\r\n18\r\n78\r\n41\r\n35\r\n92\r\n32\r\n97\r\n74\r\n93\r\n27\r\n59\r\n90\r\n23\r\n79\r\n96\r\n77\r\n29\r\n88\r\n83\r\n83\r\n46\r\n94\r\n61\r\n56\r\n68\r\n43\r\n15\r\n79\r\n26\r\n36\r\n99\r\n36\r\n55\r\n77\r\n23\r\n15\r\n12\r\n84\r\n57\r\n82\r\n33\r\n14\r\n', 'output': ['254 10099']}, {'input': '100\r\n2344\r\n23\r\n10\r\n18\r\n15\r\n32\r\n22\r\n10\r\n38\r\n32\r\n31\r\n39\r\n8\r\n26\r\n16\r\n22\r\n10\r\n23\r\n11\r\n25\r\n36\r\n24\r\n40\r\n7\r\n27\r\n43\r\n28\r\n23\r\n25\r\n7\r\n23\r\n22\r\n7\r\n43\r\n6\r\n22\r\n38\r\n7\r\n32\r\n35\r\n12\r\n41\r\n43\r\n97\r\n3\r\n37\r\n29\r\n27\r\n36\r\n17\r\n2\r\n27\r\n35\r\n16\r\n10\r\n3\r\n19\r\n12\r\n20\r\n29\r\n7\r\n14\r\n5\r\n31\r\n26\r\n10\r\n4\r\n3\r\n15\r\n32\r\n42\r\n24\r\n36\r\n41\r\n43\r\n36\r\n23\r\n14\r\n32\r\n3\r\n32\r\n21\r\n30\r\n32\r\n25\r\n32\r\n8\r\n27\r\n11\r\n19\r\n15\r\n34\r\n12\r\n41\r\n11\r\n39\r\n20\r\n14\r\n23\r\n7\r\n43\r\n', 'output': ['97 2441']}, {'input': '100\r\n3000\r\n2\r\n4\r\n4\r\n5\r\n3\r\n3\r\n5\r\n5\r\n2\r\n4\r\n4\r\n2\r\n3\r\n1\r\n5\r\n5\r\n5\r\n3\r\n3\r\n1\r\n2\r\n2\r\n3\r\n3\r\n5\r\n5\r\n3\r\n5\r\n2\r\n1\r\n4\r\n4\r\n5\r\n3\r\n4\r\n3\r\n1\r\n3\r\n5\r\n1\r\n3\r\n3\r\n3\r\n5\r\n3\r\n4\r\n1\r\n3\r\n1\r\n5\r\n5\r\n5\r\n5\r\n3\r\n5\r\n5\r\n2\r\n1\r\n4\r\n2\r\n5\r\n1\r\n1\r\n5\r\n1\r\n3\r\n3\r\n1\r\n4\r\n2\r\n4\r\n3\r\n4\r\n4\r\n5\r\n2\r\n5\r\n95\r\n1\r\n2\r\n1\r\n2\r\n5\r\n3\r\n3\r\n2\r\n3\r\n4\r\n2\r\n3\r\n3\r\n2\r\n3\r\n4\r\n4\r\n4\r\n4\r\n3\r\n3\r\n2\r\n', 'output': ['95 3095']}, {'input': '10\r\n1\r\n5\r\n5\r\n5\r\n5\r\n4\r\n5\r\n5\r\n5\r\n5\r\n5\r\n', 'output': ['5 6']}, {'input': '10\r\n20\r\n80\r\n41\r\n15\r\n77\r\n91\r\n82\r\n15\r\n83\r\n36\r\n3\r\n', 'output': ['91 111']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
274
100
100
100
["AS\n2H 4C TH JH AD", "2H\n3D 4C AC KD AS", "4D\nAS AC AD AH 5H"]
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand. Each string is two characters long. The first character denotes the rank and belongs to the set $$$\{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}$$$. The second character denotes the suit and belongs to the set $$$\{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}$$$. All the cards in the input are different.
699444eb6366ad12bc77e7ac2602d74b
import java.util.Scanner; public class Solution{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=5; String[] arr=new String[t]; String my=sc.next(); for(int i=0;i<t;i++){ arr[i]=sc.next(); } String ans="NO"; for(int i=0;i<t;i++){ char f=my.charAt(0),s=my.charAt(1); if(f==arr[i].charAt(0) || s == arr[i].charAt(1)) { ans="YES"; break; } } System.out.println(""+ans); } }
["YES", "NO", "YES"]
Java
NoteIn the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.In the second example, you cannot play any card.In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table.
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO". You can print each letter in any case (upper or lower).
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".To play Mau-Mau, you need a pack of $$$52$$$ cards. Each card has a suit (Diamonds β€” D, Clubs β€” C, Spades β€” S, or Hearts β€” H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
[{"input": "AS\r\n2H 4C TH JH AD\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "2H\r\n3D 4C AC KD AS\r\n", "output": ["No", "NO", "no"]}, {"input": "4D\r\nAS AC AD AH 5H\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "3D\r\n8S 4S 2C AS 6H\r\n", "output": ["No", "NO", "no"]}, {"input": "7H\r\nTC 4C KC AD 9S\r\n", "output": ["No", "NO", "no"]}, {"input": "KH\r\n3C QD 9S KS 8D\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "4H\r\nJH QC 5H 9H KD\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "9H\r\nKC 6D KD 4C 2S\r\n", "output": ["No", "NO", "no"]}, {"input": "AD\r\nQC 5S 4H JH 2S\r\n", "output": ["No", "NO", "no"]}, {"input": "QC\r\nQD KS AH 7S 2S\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "7H\r\n4H 6D AC KH 8H\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "4S\r\n9D 4D 5S 7D 5D\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "AS\r\n2H 4C TH JH TS\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "AS\r\n2S 3S 4S 5S 6S\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "KS\r\nAD 2D 3D 4D 5D\r\n", "output": ["No", "NO", "no"]}, {"input": "7S\r\n7H 2H 3H 4H 5H\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "AS\r\n4H 4C TH JH TS\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "7S\r\n2H 4H 5H 6H 2S\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "AS\r\n2H 4C TH JH KS\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "AS\r\n2S 2H 3H 4H 5H\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "AC\r\n2D 3D 4D 5C 6D\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "2S\r\n2D 3D 4D 5D 6D\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "AS\r\n2H 4C TH JH 3S\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "2S\r\n2H 3H 4H 5H 6H\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "AS\r\n2S 3D 4D 5D 6D\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "AS\r\n2C 3C 4C 5C 5S\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "2D\r\n2H 3H 4H 5H 6H\r\n", "output": ["YES", "yes", "Yes"]}, {"input": "9D\r\n2D 3D 4D 5D 6D\r\n", "output": ["YES", "yes", "Yes"]}]
100
100
100
[{'input': '2D\r\n2H 3H 4H 5H 6H\r\n', 'output': ['YES', 'yes', 'Yes']}, {'input': 'AS\r\n2H 4C TH JH KS\r\n', 'output': ['YES', 'yes', 'Yes']}, {'input': '2S\r\n2D 3D 4D 5D 6D\r\n', 'output': ['YES', 'yes', 'Yes']}, {'input': 'AC\r\n2D 3D 4D 5C 6D\r\n', 'output': ['YES', 'yes', 'Yes']}, {'input': '4H\r\nJH QC 5H 9H KD\r\n', 'output': ['YES', 'yes', 'Yes']}]
[{'input': 'AS\r\n4H 4C TH JH TS\r\n', 'output': ['YES', 'yes', 'Yes']}, {'input': '4S\r\n9D 4D 5S 7D 5D\r\n', 'output': ['YES', 'yes', 'Yes']}, {'input': '7H\r\nTC 4C KC AD 9S\r\n', 'output': ['No', 'NO', 'no']}, {'input': 'QC\r\nQD KS AH 7S 2S\r\n', 'output': ['YES', 'yes', 'Yes']}, {'input': 'AS\r\n2S 3D 4D 5D 6D\r\n', 'output': ['YES', 'yes', 'Yes']}]
[{'input': '2H\r\n3D 4C AC KD AS\r\n', 'output': ['No', 'NO', 'no']}, {'input': 'KH\r\n3C QD 9S KS 8D\r\n', 'output': ['YES', 'yes', 'Yes']}, {'input': 'KS\r\nAD 2D 3D 4D 5D\r\n', 'output': ['No', 'NO', 'no']}, {'input': '4H\r\nJH QC 5H 9H KD\r\n', 'output': ['YES', 'yes', 'Yes']}, {'input': 'AS\r\n2H 4C TH JH 3S\r\n', 'output': ['YES', 'yes', 'Yes']}]
[{'input': '9H\r\nKC 6D KD 4C 2S\r\n', 'output': ['No', 'NO', 'no']}, {'input': 'AS\r\n2H 4C TH JH KS\r\n', 'output': ['YES', 'yes', 'Yes']}, {'input': '7H\r\nTC 4C KC AD 9S\r\n', 'output': ['No', 'NO', 'no']}, {'input': 'AS\r\n2H 4C TH JH AD\r\n', 'output': ['YES', 'yes', 'Yes']}, {'input': 'KH\r\n3C QD 9S KS 8D\r\n', 'output': ['YES', 'yes', 'Yes']}]
[{'input': '4H\r\nJH QC 5H 9H KD\r\n', 'output': ['YES', 'yes', 'Yes']}, {'input': '2S\r\n2D 3D 4D 5D 6D\r\n', 'output': ['YES', 'yes', 'Yes']}, {'input': 'AS\r\n4H 4C TH JH TS\r\n', 'output': ['YES', 'yes', 'Yes']}, {'input': 'AS\r\n2S 3D 4D 5D 6D\r\n', 'output': ['YES', 'yes', 'Yes']}, {'input': 'QC\r\nQD KS AH 7S 2S\r\n', 'output': ['YES', 'yes', 'Yes']}]
100
100
100
100
100
100
100
100
100
100
87.5
100
100
100
87.5
275
100
100
95
["3\n1 4 6", "5\n1 2 3 4 5", "5\n1 2 3 7 8"]
The first line contains a single integer n (3 ≀ n ≀ 100)Β β€” the number of holds. The next line contains n space-separated integers ai (1 ≀ ai ≀ 1000), where ai is the height where the hold number i hangs. The sequence ai is increasing (i.e. each element except for the first one is strictly larger than the previous one).
8a8013f960814040ac4bf229a0bd5437
import java.io.*; import java.util.*; public class Minimum{ public static void main(String[] args) throws IOException{ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[]tab = new int [n]; /* BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); //int a=Integer.parseInt(br.readLine()) ; StringTokenizer st = new StringTokenizer(br.readLine()); */ for (int i = 0; i<n;i++){ tab[i] = sc.nextInt(); } int x; int max = Math.abs(tab[0]-tab[n-1]); for (int j = 1;j<n-1;j++){ int tre = 0; for (int l =0;l<n-1;l++){ x = tab[l+1]-tab[l]; if (l+1==j){ x=tab[l+2]-tab[l]; } else if (l==j){ x = tab[l+1]-tab[l-1]; } tre = Math.max(x,tre); /* if(l!=j&&l+1!=j&&tab[l+1]-tab[l]>tre){ tre= tab[l+1]-tab[l]; } else if (l==j&&tab[l+1]-tab[l-1]>tre){ tre= tab[l+1]-tab[l-1]; } else if (l+1==j&&tab[l+2]-tal[l]>tre){ tre = tab[l+2]-tab[l]; } */ } if (tre<max){ max= tre; } } System.out.print(max); } }
["5", "2", "4"]
Java
NoteIn the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.In the second test after removing every hold the difficulty equals 2.In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer β€” 4.
Print a single number β€” the minimum difficulty of the track after removing a single hold.
Mike is trying rock climbing but he is awful at it. There are n holds on the wall, i-th hold is at height ai off the ground. Besides, let the sequence ai increase, that is, ai &lt; ai + 1 for all i from 1 to n - 1; we will call such sequence a track. Mike thinks that the track a1, ..., an has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.Today Mike decided to cover the track with holds hanging on heights a1, ..., an. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1, 2, 3, 4, 5) and remove the third element from it, we obtain the sequence (1, 2, 4, 5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.Help Mike determine the minimum difficulty of the track after removing one hold.
[{"input": "3\r\n1 4 6\r\n", "output": ["5"]}, {"input": "5\r\n1 2 3 4 5\r\n", "output": ["2"]}, {"input": "5\r\n1 2 3 7 8\r\n", "output": ["4"]}, {"input": "3\r\n1 500 1000\r\n", "output": ["999"]}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": ["2"]}, {"input": "10\r\n1 4 9 16 25 36 49 64 81 100\r\n", "output": ["19"]}, {"input": "10\r\n300 315 325 338 350 365 379 391 404 416\r\n", "output": ["23"]}, {"input": "15\r\n87 89 91 92 93 95 97 99 101 103 105 107 109 111 112\r\n", "output": ["2"]}, {"input": "60\r\n3 5 7 8 15 16 18 21 24 26 40 41 43 47 48 49 50 51 52 54 55 60 62 71 74 84 85 89 91 96 406 407 409 412 417 420 423 424 428 431 432 433 436 441 445 446 447 455 458 467 469 471 472 475 480 485 492 493 497 500\r\n", "output": ["310"]}, {"input": "3\r\n159 282 405\r\n", "output": ["246"]}, {"input": "81\r\n6 7 22 23 27 38 40 56 59 71 72 78 80 83 86 92 95 96 101 122 125 127 130 134 154 169 170 171 172 174 177 182 184 187 195 197 210 211 217 223 241 249 252 253 256 261 265 269 274 277 291 292 297 298 299 300 302 318 338 348 351 353 381 386 387 397 409 410 419 420 428 430 453 460 461 473 478 493 494 500 741\r\n", "output": ["241"]}, {"input": "10\r\n218 300 388 448 535 629 680 740 836 925\r\n", "output": ["111"]}, {"input": "100\r\n6 16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 206 216 226 236 246 256 266 276 286 296 306 316 326 336 346 356 366 376 386 396 406 416 426 436 446 456 466 476 486 496 506 516 526 536 546 556 566 576 586 596 606 616 626 636 646 656 666 676 686 696 706 716 726 736 746 756 766 776 786 796 806 816 826 836 846 856 866 876 886 896 906 916 926 936 946 956 966 976 986 996\r\n", "output": ["20"]}, {"input": "100\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000\r\n", "output": ["901"]}, {"input": "100\r\n1 9 15 17 28 29 30 31 32 46 48 49 52 56 62 77 82 85 90 91 94 101 102 109 111 113 116 118 124 125 131 132 136 138 139 143 145 158 161 162 165 167 171 173 175 177 179 183 189 196 801 802 804 806 817 819 827 830 837 840 842 846 850 855 858 862 863 866 869 870 878 881 883 884 896 898 899 901 904 906 908 909 910 911 912 917 923 924 925 935 939 943 945 956 963 964 965 972 976 978\r\n", "output": ["605"]}, {"input": "100\r\n2 43 47 49 50 57 59 67 74 98 901 903 904 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 938 939 940 942 943 944 945 946 947 948 949 950 952 953 954 956 957 958 959 960 961 962 963 965 966 967 968 969 970 971 972 973 974 975 976 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 998 999\r\n", "output": ["803"]}, {"input": "72\r\n178 186 196 209 217 226 236 248 260 273 281 291 300 309 322 331 343 357 366 377 389 399 409 419 429 442 450 459 469 477 491 501 512 524 534 548 557 568 582 593 602 616 630 643 652 660 670 679 693 707 715 728 737 750 759 768 776 789 797 807 815 827 837 849 863 873 881 890 901 910 920 932\r\n", "output": ["17"]}, {"input": "38\r\n1 28 55 82 109 136 163 190 217 244 271 298 325 352 379 406 433 460 487 514 541 568 595 622 649 676 703 730 757 784 811 838 865 892 919 946 973 1000\r\n", "output": ["54"]}, {"input": "28\r\n1 38 75 112 149 186 223 260 297 334 371 408 445 482 519 556 593 630 667 704 741 778 815 852 889 926 963 1000\r\n", "output": ["74"]}]
100
100
100
[{'input': '38\r\n1 28 55 82 109 136 163 190 217 244 271 298 325 352 379 406 433 460 487 514 541 568 595 622 649 676 703 730 757 784 811 838 865 892 919 946 973 1000\r\n', 'output': ['54']}, {'input': '28\r\n1 38 75 112 149 186 223 260 297 334 371 408 445 482 519 556 593 630 667 704 741 778 815 852 889 926 963 1000\r\n', 'output': ['74']}, {'input': '15\r\n87 89 91 92 93 95 97 99 101 103 105 107 109 111 112\r\n', 'output': ['2']}, {'input': '100\r\n6 16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 206 216 226 236 246 256 266 276 286 296 306 316 326 336 346 356 366 376 386 396 406 416 426 436 446 456 466 476 486 496 506 516 526 536 546 556 566 576 586 596 606 616 626 636 646 656 666 676 686 696 706 716 726 736 746 756 766 776 786 796 806 816 826 836 846 856 866 876 886 896 906 916 926 936 946 956 966 976 986 996\r\n', 'output': ['20']}, {'input': '100\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000\r\n', 'output': ['901']}]
[{'input': '3\r\n1 4 6\r\n', 'output': ['5']}, {'input': '81\r\n6 7 22 23 27 38 40 56 59 71 72 78 80 83 86 92 95 96 101 122 125 127 130 134 154 169 170 171 172 174 177 182 184 187 195 197 210 211 217 223 241 249 252 253 256 261 265 269 274 277 291 292 297 298 299 300 302 318 338 348 351 353 381 386 387 397 409 410 419 420 428 430 453 460 461 473 478 493 494 500 741\r\n', 'output': ['241']}, {'input': '10\r\n218 300 388 448 535 629 680 740 836 925\r\n', 'output': ['111']}, {'input': '15\r\n87 89 91 92 93 95 97 99 101 103 105 107 109 111 112\r\n', 'output': ['2']}, {'input': '100\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000\r\n', 'output': ['901']}]
[{'input': '5\r\n1 2 3 7 8\r\n', 'output': ['4']}, {'input': '3\r\n1 500 1000\r\n', 'output': ['999']}, {'input': '100\r\n6 16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 206 216 226 236 246 256 266 276 286 296 306 316 326 336 346 356 366 376 386 396 406 416 426 436 446 456 466 476 486 496 506 516 526 536 546 556 566 576 586 596 606 616 626 636 646 656 666 676 686 696 706 716 726 736 746 756 766 776 786 796 806 816 826 836 846 856 866 876 886 896 906 916 926 936 946 956 966 976 986 996\r\n', 'output': ['20']}, {'input': '15\r\n87 89 91 92 93 95 97 99 101 103 105 107 109 111 112\r\n', 'output': ['2']}, {'input': '60\r\n3 5 7 8 15 16 18 21 24 26 40 41 43 47 48 49 50 51 52 54 55 60 62 71 74 84 85 89 91 96 406 407 409 412 417 420 423 424 428 431 432 433 436 441 445 446 447 455 458 467 469 471 472 475 480 485 492 493 497 500\r\n', 'output': ['310']}]
[{'input': '100\r\n6 16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 206 216 226 236 246 256 266 276 286 296 306 316 326 336 346 356 366 376 386 396 406 416 426 436 446 456 466 476 486 496 506 516 526 536 546 556 566 576 586 596 606 616 626 636 646 656 666 676 686 696 706 716 726 736 746 756 766 776 786 796 806 816 826 836 846 856 866 876 886 896 906 916 926 936 946 956 966 976 986 996\r\n', 'output': ['20']}, {'input': '100\r\n2 43 47 49 50 57 59 67 74 98 901 903 904 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 938 939 940 942 943 944 945 946 947 948 949 950 952 953 954 956 957 958 959 960 961 962 963 965 966 967 968 969 970 971 972 973 974 975 976 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 998 999\r\n', 'output': ['803']}, {'input': '10\r\n1 2 3 4 5 6 7 8 9 10\r\n', 'output': ['2']}, {'input': '28\r\n1 38 75 112 149 186 223 260 297 334 371 408 445 482 519 556 593 630 667 704 741 778 815 852 889 926 963 1000\r\n', 'output': ['74']}, {'input': '3\r\n1 4 6\r\n', 'output': ['5']}]
[{'input': '100\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000\r\n', 'output': ['901']}, {'input': '3\r\n159 282 405\r\n', 'output': ['246']}, {'input': '38\r\n1 28 55 82 109 136 163 190 217 244 271 298 325 352 379 406 433 460 487 514 541 568 595 622 649 676 703 730 757 784 811 838 865 892 919 946 973 1000\r\n', 'output': ['54']}, {'input': '15\r\n87 89 91 92 93 95 97 99 101 103 105 107 109 111 112\r\n', 'output': ['2']}, {'input': '100\r\n6 16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 206 216 226 236 246 256 266 276 286 296 306 316 326 336 346 356 366 376 386 396 406 416 426 436 446 456 466 476 486 496 506 516 526 536 546 556 566 576 586 596 606 616 626 636 646 656 666 676 686 696 706 716 726 736 746 756 766 776 786 796 806 816 826 836 846 856 866 876 886 896 906 916 926 936 946 956 966 976 986 996\r\n', 'output': ['20']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
276
100
100
100
["3 5", "7 11", "7 9"]
The first and only input line contains two positive integers β€” n and m (2 ≀ n &lt; m ≀ 50). It is guaranteed that n is prime. Pretests contain all the cases with restrictions 2 ≀ n &lt; m ≀ 4.
9d52ff51d747bb59aa463b6358258865
import java.util.Arrays; import java.util.List; import java.util.Scanner; public class PanoramixsPrediction { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); Integer[] a = new Integer[] {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; List<Integer> primes = Arrays.asList(a); if (primes.indexOf(n) + 1 < primes.size() && primes.get(primes.indexOf(n) + 1) == m) { System.out.println("YES"); } else { System.out.println("NO"); } sc.close(); } }
["YES", "YES", "NO"]
Java
null
Print YES, if m is the next prime number after n, or NO otherwise.
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.The next prime number after x is the smallest prime number greater than x. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 isΒ not the next prime number for 2.One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly x Roman soldiers, where x is a prime number, and next day they beat exactly y Roman soldiers, where y is the next prime number after x, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.Yesterday the Gauls beat n Roman soldiers and it turned out that the number n was prime! Today their victims were a troop of m Romans (m &gt; n). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
[{"input": "3 5\r\n", "output": ["YES"]}, {"input": "7 11\r\n", "output": ["YES"]}, {"input": "7 9\r\n", "output": ["NO"]}, {"input": "2 3\r\n", "output": ["YES"]}, {"input": "2 4\r\n", "output": ["NO"]}, {"input": "3 4\r\n", "output": ["NO"]}, {"input": "5 7\r\n", "output": ["YES"]}, {"input": "11 13\r\n", "output": ["YES"]}, {"input": "13 17\r\n", "output": ["YES"]}, {"input": "17 19\r\n", "output": ["YES"]}, {"input": "19 23\r\n", "output": ["YES"]}, {"input": "23 29\r\n", "output": ["YES"]}, {"input": "29 31\r\n", "output": ["YES"]}, {"input": "31 37\r\n", "output": ["YES"]}, {"input": "37 41\r\n", "output": ["YES"]}, {"input": "41 43\r\n", "output": ["YES"]}, {"input": "43 47\r\n", "output": ["YES"]}, {"input": "2 5\r\n", "output": ["NO"]}, {"input": "2 7\r\n", "output": ["NO"]}, {"input": "2 6\r\n", "output": ["NO"]}, {"input": "2 11\r\n", "output": ["NO"]}, {"input": "3 6\r\n", "output": ["NO"]}, {"input": "3 7\r\n", "output": ["NO"]}, {"input": "3 9\r\n", "output": ["NO"]}, {"input": "5 6\r\n", "output": ["NO"]}, {"input": "5 9\r\n", "output": ["NO"]}, {"input": "5 11\r\n", "output": ["NO"]}, {"input": "5 13\r\n", "output": ["NO"]}, {"input": "5 15\r\n", "output": ["NO"]}, {"input": "7 8\r\n", "output": ["NO"]}, {"input": "7 13\r\n", "output": ["NO"]}, {"input": "13 15\r\n", "output": ["NO"]}, {"input": "19 21\r\n", "output": ["NO"]}, {"input": "13 20\r\n", "output": ["NO"]}, {"input": "41 49\r\n", "output": ["NO"]}, {"input": "43 49\r\n", "output": ["NO"]}, {"input": "47 50\r\n", "output": ["NO"]}, {"input": "47 49\r\n", "output": ["NO"]}, {"input": "47 48\r\n", "output": ["NO"]}, {"input": "23 25\r\n", "output": ["NO"]}, {"input": "2 50\r\n", "output": ["NO"]}, {"input": "31 33\r\n", "output": ["NO"]}]
100
100
100
[{'input': '47 48\r\n', 'output': ['NO']}, {'input': '5 15\r\n', 'output': ['NO']}, {'input': '17 19\r\n', 'output': ['YES']}, {'input': '3 4\r\n', 'output': ['NO']}, {'input': '19 23\r\n', 'output': ['YES']}]
[{'input': '41 43\r\n', 'output': ['YES']}, {'input': '41 49\r\n', 'output': ['NO']}, {'input': '3 7\r\n', 'output': ['NO']}, {'input': '23 25\r\n', 'output': ['NO']}, {'input': '7 11\r\n', 'output': ['YES']}]
[{'input': '2 11\r\n', 'output': ['NO']}, {'input': '5 7\r\n', 'output': ['YES']}, {'input': '47 50\r\n', 'output': ['NO']}, {'input': '31 33\r\n', 'output': ['NO']}, {'input': '5 11\r\n', 'output': ['NO']}]
[{'input': '41 43\r\n', 'output': ['YES']}, {'input': '19 23\r\n', 'output': ['YES']}, {'input': '7 8\r\n', 'output': ['NO']}, {'input': '31 33\r\n', 'output': ['NO']}, {'input': '3 7\r\n', 'output': ['NO']}]
[{'input': '7 8\r\n', 'output': ['NO']}, {'input': '3 9\r\n', 'output': ['NO']}, {'input': '3 4\r\n', 'output': ['NO']}, {'input': '3 6\r\n', 'output': ['NO']}, {'input': '37 41\r\n', 'output': ['YES']}]
100
100
100
100
100
100
100
100
100
100
100
75
100
75
75
277
100
100
85
["3 5", "4 8"]
The only line of the input contains two integers n and t (1 ≀ n ≀ 10, 0 ≀ t ≀ 10 000)Β β€” the height of the pyramid and the number of seconds Vlad will be pouring champagne from the bottle.
b2b49b7f6e3279d435766085958fb69d
import java.io.*; import java.util.StringTokenizer; /** * Created by sachin.goyal on 16/05/16. */ public class MainB { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(1, in, out); out.close(); } static class Task { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int t = in.nextInt(); if(t == 0){ out.print(0); return; } double[][] ans = new double[11][11]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++) { ans[i][j] = 0d; }} ans[0][0] = t; int finalAns = 1; for(int i=1;i<n;i++){ for(int j=0;j<=i;j++){ int left = j-1; int right = left+1; ans[i][j] += left >=0 && ans[i-1][left] > 1? (ans[i-1][left] -1)/2 : 0; ans[i][j] += right<=i-1 && ans[i-1][right] > 1 ? (ans[i-1][right] -1)/2 : 0; if(ans[i][j] >= 1d) finalAns++; } } out.print(finalAns); } } 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()); } } }
["4", "6"]
Java
NoteIn the first sample, the glasses full after 5 seconds are: the top glass, both glasses on the second level and the middle glass at the bottom level. Left and right glasses of the bottom level will be half-empty.
Print the single integerΒ β€” the number of completely full glasses after t seconds.
Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyramid is n. The top level consists of only 1 glass, that stands on 2 glasses on the second level (counting from the top), then 3 glasses on the third level and so on.The bottom level consists of n glasses.Vlad has seen in the movies many times how the champagne beautifully flows from top levels to bottom ones, filling all the glasses simultaneously. So he took a bottle and started to pour it in the glass located at the top of the pyramid.Each second, Vlad pours to the top glass the amount of champagne equal to the size of exactly one glass. If the glass is already full, but there is some champagne flowing in it, then it pours over the edge of the glass and is equally distributed over two glasses standing under. If the overflowed glass is at the bottom level, then the champagne pours on the table. For the purpose of this problem we consider that champagne is distributed among pyramid glasses immediately. Vlad is interested in the number of completely full glasses if he stops pouring champagne in t seconds.Pictures below illustrate the pyramid consisting of three levels.
[{"input": "3 5\r\n", "output": ["4"]}, {"input": "4 8\r\n", "output": ["6"]}, {"input": "1 1\r\n", "output": ["1"]}, {"input": "10 10000\r\n", "output": ["55"]}, {"input": "1 10000\r\n", "output": ["1"]}, {"input": "10 1\r\n", "output": ["1"]}, {"input": "1 0\r\n", "output": ["0"]}, {"input": "10 0\r\n", "output": ["0"]}, {"input": "10 1022\r\n", "output": ["53"]}, {"input": "10 1023\r\n", "output": ["55"]}, {"input": "10 1024\r\n", "output": ["55"]}, {"input": "1 2\r\n", "output": ["1"]}, {"input": "1 200\r\n", "output": ["1"]}, {"input": "7 128\r\n", "output": ["28"]}, {"input": "8 198\r\n", "output": ["34"]}, {"input": "2 2\r\n", "output": ["1"]}, {"input": "2 3\r\n", "output": ["3"]}, {"input": "2 4\r\n", "output": ["3"]}, {"input": "2 100\r\n", "output": ["3"]}, {"input": "2 10000\r\n", "output": ["3"]}, {"input": "3 7\r\n", "output": ["6"]}, {"input": "3 6\r\n", "output": ["4"]}, {"input": "3 8\r\n", "output": ["6"]}, {"input": "3 12\r\n", "output": ["6"]}, {"input": "3 1\r\n", "output": ["1"]}, {"input": "4 15\r\n", "output": ["10"]}, {"input": "4 14\r\n", "output": ["8"]}, {"input": "4 10\r\n", "output": ["8"]}, {"input": "4 16\r\n", "output": ["10"]}, {"input": "4 999\r\n", "output": ["10"]}, {"input": "4 9\r\n", "output": ["8"]}, {"input": "5 31\r\n", "output": ["15"]}, {"input": "5 30\r\n", "output": ["13"]}, {"input": "5 28\r\n", "output": ["13"]}, {"input": "5 25\r\n", "output": ["13"]}, {"input": "5 15\r\n", "output": ["13"]}, {"input": "5 32\r\n", "output": ["15"]}, {"input": "5 9999\r\n", "output": ["15"]}, {"input": "5 4\r\n", "output": ["3"]}, {"input": "5 9\r\n", "output": ["8"]}, {"input": "5 14\r\n", "output": ["11"]}, {"input": "6 63\r\n", "output": ["21"]}, {"input": "6 62\r\n", "output": ["19"]}, {"input": "6 61\r\n", "output": ["19"]}, {"input": "6 52\r\n", "output": ["19"]}, {"input": "6 31\r\n", "output": ["19"]}, {"input": "6 32\r\n", "output": ["19"]}, {"input": "6 39\r\n", "output": ["19"]}, {"input": "6 15\r\n", "output": ["13"]}, {"input": "6 14\r\n", "output": ["11"]}, {"input": "6 10\r\n", "output": ["8"]}, {"input": "6 4\r\n", "output": ["3"]}, {"input": "6 7653\r\n", "output": ["21"]}, {"input": "7 127\r\n", "output": ["28"]}, {"input": "6 64\r\n", "output": ["21"]}, {"input": "7 126\r\n", "output": ["26"]}, {"input": "7 125\r\n", "output": ["26"]}, {"input": "7 120\r\n", "output": ["26"]}, {"input": "7 98\r\n", "output": ["26"]}, {"input": "7 110\r\n", "output": ["26"]}, {"input": "7 65\r\n", "output": ["26"]}, {"input": "7 63\r\n", "output": ["26"]}, {"input": "7 15\r\n", "output": ["13"]}, {"input": "7 3\r\n", "output": ["3"]}, {"input": "7 1\r\n", "output": ["1"]}, {"input": "7 83\r\n", "output": ["26"]}, {"input": "7 214\r\n", "output": ["28"]}, {"input": "8 2555\r\n", "output": ["36"]}, {"input": "8 257\r\n", "output": ["36"]}, {"input": "8 256\r\n", "output": ["36"]}, {"input": "8 255\r\n", "output": ["36"]}, {"input": "8 254\r\n", "output": ["34"]}, {"input": "8 253\r\n", "output": ["34"]}, {"input": "8 251\r\n", "output": ["34"]}, {"input": "8 240\r\n", "output": ["34"]}, {"input": "8 128\r\n", "output": ["34"]}, {"input": "8 127\r\n", "output": ["34"]}, {"input": "8 100\r\n", "output": ["32"]}, {"input": "8 1\r\n", "output": ["1"]}, {"input": "8 0\r\n", "output": ["0"]}, {"input": "8 10000\r\n", "output": ["36"]}, {"input": "8 94\r\n", "output": ["32"]}, {"input": "8 33\r\n", "output": ["26"]}, {"input": "9 10000\r\n", "output": ["45"]}, {"input": "9 513\r\n", "output": ["45"]}, {"input": "9 512\r\n", "output": ["45"]}, {"input": "9 511\r\n", "output": ["45"]}, {"input": "9 510\r\n", "output": ["43"]}, {"input": "9 255\r\n", "output": ["43"]}, {"input": "9 256\r\n", "output": ["43"]}, {"input": "9 254\r\n", "output": ["41"]}, {"input": "9 253\r\n", "output": ["41"]}, {"input": "9 200\r\n", "output": ["41"]}, {"input": "9 100\r\n", "output": ["37"]}, {"input": "9 150\r\n", "output": ["41"]}, {"input": "10 9999\r\n", "output": ["55"]}, {"input": "10 1025\r\n", "output": ["55"]}, {"input": "10 1021\r\n", "output": ["53"]}, {"input": "10 512\r\n", "output": ["53"]}, {"input": "10 689\r\n", "output": ["53"]}, {"input": "10 754\r\n", "output": ["53"]}, {"input": "10 985\r\n", "output": ["53"]}, {"input": "10 255\r\n", "output": ["51"]}, {"input": "10 256\r\n", "output": ["51"]}, {"input": "10 254\r\n", "output": ["49"]}, {"input": "10 153\r\n", "output": ["47"]}, {"input": "10 2\r\n", "output": ["1"]}, {"input": "10 3\r\n", "output": ["3"]}, {"input": "10 5\r\n", "output": ["4"]}, {"input": "10 63\r\n", "output": ["41"]}, {"input": "10 64\r\n", "output": ["41"]}, {"input": "10 126\r\n", "output": ["45"]}, {"input": "10 127\r\n", "output": ["47"]}, {"input": "10 128\r\n", "output": ["47"]}, {"input": "10 55\r\n", "output": ["37"]}, {"input": "10 9\r\n", "output": ["8"]}, {"input": "10 37\r\n", "output": ["33"]}, {"input": "10 68\r\n", "output": ["41"]}, {"input": "3 4\r\n", "output": ["3"]}, {"input": "7 23\r\n", "output": ["20"]}, {"input": "1 3\r\n", "output": ["1"]}]
100
100
100
[{'input': '2 2\r\n', 'output': ['1']}, {'input': '9 256\r\n', 'output': ['43']}, {'input': '7 214\r\n', 'output': ['28']}, {'input': '10 153\r\n', 'output': ['47']}, {'input': '9 511\r\n', 'output': ['45']}]
[{'input': '10 1023\r\n', 'output': ['55']}, {'input': '7 120\r\n', 'output': ['26']}, {'input': '10 512\r\n', 'output': ['53']}, {'input': '5 9999\r\n', 'output': ['15']}, {'input': '9 254\r\n', 'output': ['41']}]
[{'input': '9 253\r\n', 'output': ['41']}, {'input': '5 30\r\n', 'output': ['13']}, {'input': '10 5\r\n', 'output': ['4']}, {'input': '10 127\r\n', 'output': ['47']}, {'input': '6 52\r\n', 'output': ['19']}]
[{'input': '6 32\r\n', 'output': ['19']}, {'input': '10 153\r\n', 'output': ['47']}, {'input': '9 512\r\n', 'output': ['45']}, {'input': '5 31\r\n', 'output': ['15']}, {'input': '7 128\r\n', 'output': ['28']}]
[{'input': '8 254\r\n', 'output': ['34']}, {'input': '5 30\r\n', 'output': ['13']}, {'input': '3 6\r\n', 'output': ['4']}, {'input': '7 127\r\n', 'output': ['28']}, {'input': '10 68\r\n', 'output': ['41']}]
100
100
100
100
100
90.48
90.48
90.48
90.48
90.48
95
95
95
95
95
278
100
90.48
95
["3\n0 2 1", "2\n1 1"]
The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 100$$$)Β β€” the number of floors. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$)Β β€” the number of people on each floor.
a5002ddf9e792cb4b4685e630f1e1b8f
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Ideone { public static void main (String[] args) throws java.lang.Exception { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int arr[] = new int[n]; for(int i = 0 ; i < n ;++i) { arr[i] = scanner.nextInt(); } int finalCount = Integer.MAX_VALUE; for(int maxPos = 0; maxPos < n ;++maxPos) { int totalCount = 0; for (int i = 0; i < n; ++i) { int singleVal = 2 * Math.abs(maxPos - i) + 2 * i + 2 * maxPos; totalCount += (arr[i] * singleVal); } if(finalCount > totalCount) { finalCount = totalCount; } } System.out.println(finalCount); } }
["16", "4"]
Java
NoteIn the first example, the answer can be achieved by choosing the second floor as the $$$x$$$-th floor. Each person from the second floor (there are two of them) would spend $$$4$$$ units of electricity per day ($$$2$$$ to get down and $$$2$$$ to get up), and one person from the third would spend $$$8$$$ units of electricity per day ($$$4$$$ to get down and $$$4$$$ to get up). $$$4 \cdot 2 + 8 \cdot 1 = 16$$$.In the second example, the answer can be achieved by choosing the first floor as the $$$x$$$-th floor.
In a single line, print the answer to the problemΒ β€” the minimum number of electricity units.
The Fair Nut lives in $$$n$$$ story house. $$$a_i$$$ people live on the $$$i$$$-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening. It was decided that elevator, when it is not used, will stay on the $$$x$$$-th floor, but $$$x$$$ hasn't been chosen yet. When a person needs to get from floor $$$a$$$ to floor $$$b$$$, elevator follows the simple algorithm: Moves from the $$$x$$$-th floor (initially it stays on the $$$x$$$-th floor) to the $$$a$$$-th and takes the passenger. Moves from the $$$a$$$-th floor to the $$$b$$$-th floor and lets out the passenger (if $$$a$$$ equals $$$b$$$, elevator just opens and closes the doors, but still comes to the floor from the $$$x$$$-th floor). Moves from the $$$b$$$-th floor back to the $$$x$$$-th. The elevator never transposes more than one person and always goes back to the floor $$$x$$$ before transposing a next passenger. The elevator spends one unit of electricity to move between neighboring floors. So moving from the $$$a$$$-th floor to the $$$b$$$-th floor requires $$$|a - b|$$$ units of electricity.Your task is to help Nut to find the minimum number of electricity units, that it would be enough for one day, by choosing an optimal the $$$x$$$-th floor. Don't forget than elevator initially stays on the $$$x$$$-th floor.
[{"input": "3\r\n0 2 1\r\n", "output": ["16"]}, {"input": "2\r\n1 1\r\n", "output": ["4"]}, {"input": "1\r\n1\r\n", "output": ["0"]}, {"input": "3\r\n1 3 3\r\n", "output": ["36"]}, {"input": "3\r\n3 2 3\r\n", "output": ["32"]}, {"input": "5\r\n2 10 6 3 1\r\n", "output": ["140"]}, {"input": "5\r\n6 4 10 5 10\r\n", "output": ["316"]}, {"input": "100\r\n23 39 85 46 97 72 41 70 37 18 8 40 33 61 12 79 51 78 61 66 85 97 78 14 70 47 100 40 15 40 61 52 19 30 14 91 82 56 10 6 68 24 97 61 31 78 18 45 88 6 37 38 51 86 37 42 58 30 79 56 50 14 61 18 13 20 57 3 93 15 24 74 32 21 71 93 2 66 25 75 75 10 86 82 30 31 6 49 15 33 100 35 1 96 87 83 29 21 41 22\r\n", "output": ["921748"]}, {"input": "100\r\n47 79 39 24 51 37 29 54 96 100 48 80 32 98 27 88 73 36 79 11 33 78 87 94 27 55 21 1 24 6 83 27 7 66 27 91 12 35 43 17 57 46 78 19 20 61 29 89 6 73 51 82 48 14 33 81 37 51 34 64 57 19 1 96 49 81 34 27 84 49 72 56 47 37 50 23 58 53 78 82 25 66 13 10 61 3 73 96 64 59 38 48 12 61 96 81 37 80 83 39\r\n", "output": ["1005500"]}, {"input": "3\r\n2 1 3\r\n", "output": ["28"]}, {"input": "3\r\n1 1 2\r\n", "output": ["20"]}, {"input": "3\r\n3 1 1\r\n", "output": ["12"]}, {"input": "3\r\n4 5 5\r\n", "output": ["60"]}, {"input": "3\r\n2 1 4\r\n", "output": ["36"]}, {"input": "3\r\n1 2 2\r\n", "output": ["24"]}, {"input": "3\r\n5 2 2\r\n", "output": ["24"]}, {"input": "3\r\n3 2 5\r\n", "output": ["48"]}, {"input": "3\r\n10 1 8\r\n", "output": ["68"]}, {"input": "3\r\n4 2 5\r\n", "output": ["48"]}, {"input": "3\r\n8 6 1\r\n", "output": ["32"]}, {"input": "3\r\n2 7 4\r\n", "output": ["60"]}, {"input": "3\r\n10 5 8\r\n", "output": ["84"]}, {"input": "5\r\n4 9 4 2 6\r\n", "output": ["188"]}, {"input": "5\r\n8 1 3 4 9\r\n", "output": ["220"]}, {"input": "5\r\n6 1 1 8 3\r\n", "output": ["156"]}, {"input": "100\r\n71 23 84 98 8 14 4 42 56 83 87 28 22 32 50 5 96 90 1 59 74 56 96 77 88 71 38 62 36 85 1 97 98 98 32 99 42 6 81 20 49 57 71 66 9 45 41 29 28 32 68 38 29 35 29 19 27 76 85 68 68 41 32 78 72 38 19 55 83 83 25 46 62 48 26 53 14 39 31 94 84 22 39 34 96 63 37 42 6 78 76 64 16 26 6 79 53 24 29 63\r\n", "output": ["971496"]}, {"input": "100\r\n95 72 38 75 62 87 87 30 11 65 35 75 16 73 65 23 18 48 19 4 22 42 14 60 49 83 59 15 60 51 27 80 97 35 37 100 64 81 22 38 54 71 52 20 5 20 52 73 42 98 78 86 26 55 25 57 14 97 36 81 71 54 71 51 3 4 8 74 82 21 74 29 81 52 1 87 75 22 76 2 27 79 73 61 39 39 9 89 60 1 14 77 27 87 11 70 61 75 63 75\r\n", "output": ["997408"]}, {"input": "100\r\n23 20 87 49 15 59 70 18 67 47 79 19 7 6 88 40 33 7 37 45 75 16 19 43 6 96 77 79 69 21 54 46 84 67 49 4 97 52 60 45 47 90 33 79 94 4 64 13 56 57 96 33 7 83 17 92 5 18 83 93 87 63 10 33 38 65 85 98 73 47 19 15 92 64 72 18 23 9 33 18 81 35 100 85 70 7 85 35 9 19 44 89 34 48 20 64 70 26 5 95\r\n", "output": ["991208"]}, {"input": "100\r\n47 64 41 30 77 36 50 10 22 29 18 59 93 35 3 61 55 57 63 94 15 97 28 14 63 12 2 36 89 91 72 24 75 3 54 8 23 27 94 56 48 4 26 33 91 92 75 53 74 24 18 85 97 8 9 26 96 39 39 97 90 80 45 11 69 30 70 22 76 81 76 1 8 75 48 48 83 92 86 26 32 83 34 9 4 71 45 78 59 34 82 2 45 13 37 54 86 74 39 12\r\n", "output": ["981464"]}, {"input": "100\r\n71 5 95 8 30 9 29 94 82 12 62 2 87 76 22 70 82 19 82 38 64 83 38 98 24 20 23 89 97 62 98 95 70 32 63 16 57 1 35 70 40 15 11 88 79 75 83 97 100 78 27 37 90 32 13 64 83 64 94 9 93 89 84 89 92 88 58 53 67 15 21 96 35 87 23 78 39 75 31 30 86 43 60 29 47 42 16 28 9 57 19 14 49 74 46 52 94 21 81 36\r\n", "output": ["1066920"]}, {"input": "100\r\n95 49 40 82 80 78 4 86 37 94 1 46 85 6 41 87 100 69 100 87 12 61 55 81 81 32 40 54 22 32 24 73 61 68 76 16 83 76 73 77 41 37 88 46 72 63 2 37 14 49 45 81 75 56 10 99 73 85 41 17 5 2 16 75 28 53 35 77 66 53 69 82 50 95 2 12 95 62 84 46 29 95 91 49 78 14 88 75 58 83 49 31 56 43 55 39 10 72 23 60\r\n", "output": ["1063232"]}, {"input": "100\r\n23 94 2 59 41 51 92 74 92 76 37 98 76 47 60 4 22 32 22 32 57 39 68 60 38 41 61 7 34 98 42 44 52 100 81 24 16 51 10 84 34 52 73 100 69 38 14 77 32 4 59 37 68 81 6 37 52 6 96 22 12 23 63 57 59 18 20 1 57 87 22 68 65 7 70 39 55 49 41 54 84 51 17 73 13 78 52 10 4 6 87 47 67 8 65 41 19 24 65 76\r\n", "output": ["902296"]}, {"input": "100\r\n94 69 43 36 54 93 30 74 56 95 70 49 11 36 57 30 59 3 52 59 90 82 39 67 32 8 80 64 8 65 51 48 89 90 35 4 54 66 96 68 90 30 4 13 97 41 90 85 17 45 94 31 58 4 39 76 95 92 59 67 46 96 55 82 64 20 20 83 46 37 15 60 37 79 45 47 63 73 76 31 52 36 32 49 26 61 91 31 25 62 90 65 65 5 94 7 15 97 88 68\r\n", "output": ["1077508"]}]
100
100
100
[{'input': '3\r\n4 2 5\r\n', 'output': ['48']}, {'input': '100\r\n95 49 40 82 80 78 4 86 37 94 1 46 85 6 41 87 100 69 100 87 12 61 55 81 81 32 40 54 22 32 24 73 61 68 76 16 83 76 73 77 41 37 88 46 72 63 2 37 14 49 45 81 75 56 10 99 73 85 41 17 5 2 16 75 28 53 35 77 66 53 69 82 50 95 2 12 95 62 84 46 29 95 91 49 78 14 88 75 58 83 49 31 56 43 55 39 10 72 23 60\r\n', 'output': ['1063232']}, {'input': '5\r\n6 4 10 5 10\r\n', 'output': ['316']}, {'input': '3\r\n8 6 1\r\n', 'output': ['32']}, {'input': '3\r\n1 1 2\r\n', 'output': ['20']}]
[{'input': '100\r\n23 39 85 46 97 72 41 70 37 18 8 40 33 61 12 79 51 78 61 66 85 97 78 14 70 47 100 40 15 40 61 52 19 30 14 91 82 56 10 6 68 24 97 61 31 78 18 45 88 6 37 38 51 86 37 42 58 30 79 56 50 14 61 18 13 20 57 3 93 15 24 74 32 21 71 93 2 66 25 75 75 10 86 82 30 31 6 49 15 33 100 35 1 96 87 83 29 21 41 22\r\n', 'output': ['921748']}, {'input': '3\r\n8 6 1\r\n', 'output': ['32']}, {'input': '3\r\n2 1 4\r\n', 'output': ['36']}, {'input': '100\r\n23 20 87 49 15 59 70 18 67 47 79 19 7 6 88 40 33 7 37 45 75 16 19 43 6 96 77 79 69 21 54 46 84 67 49 4 97 52 60 45 47 90 33 79 94 4 64 13 56 57 96 33 7 83 17 92 5 18 83 93 87 63 10 33 38 65 85 98 73 47 19 15 92 64 72 18 23 9 33 18 81 35 100 85 70 7 85 35 9 19 44 89 34 48 20 64 70 26 5 95\r\n', 'output': ['991208']}, {'input': '100\r\n47 79 39 24 51 37 29 54 96 100 48 80 32 98 27 88 73 36 79 11 33 78 87 94 27 55 21 1 24 6 83 27 7 66 27 91 12 35 43 17 57 46 78 19 20 61 29 89 6 73 51 82 48 14 33 81 37 51 34 64 57 19 1 96 49 81 34 27 84 49 72 56 47 37 50 23 58 53 78 82 25 66 13 10 61 3 73 96 64 59 38 48 12 61 96 81 37 80 83 39\r\n', 'output': ['1005500']}]
[{'input': '3\r\n1 2 2\r\n', 'output': ['24']}, {'input': '3\r\n4 5 5\r\n', 'output': ['60']}, {'input': '3\r\n10 5 8\r\n', 'output': ['84']}, {'input': '3\r\n0 2 1\r\n', 'output': ['16']}, {'input': '5\r\n8 1 3 4 9\r\n', 'output': ['220']}]
[{'input': '3\r\n2 1 3\r\n', 'output': ['28']}, {'input': '5\r\n8 1 3 4 9\r\n', 'output': ['220']}, {'input': '100\r\n95 72 38 75 62 87 87 30 11 65 35 75 16 73 65 23 18 48 19 4 22 42 14 60 49 83 59 15 60 51 27 80 97 35 37 100 64 81 22 38 54 71 52 20 5 20 52 73 42 98 78 86 26 55 25 57 14 97 36 81 71 54 71 51 3 4 8 74 82 21 74 29 81 52 1 87 75 22 76 2 27 79 73 61 39 39 9 89 60 1 14 77 27 87 11 70 61 75 63 75\r\n', 'output': ['997408']}, {'input': '5\r\n4 9 4 2 6\r\n', 'output': ['188']}, {'input': '3\r\n3 2 5\r\n', 'output': ['48']}]
[{'input': '3\r\n5 2 2\r\n', 'output': ['24']}, {'input': '3\r\n8 6 1\r\n', 'output': ['32']}, {'input': '100\r\n95 72 38 75 62 87 87 30 11 65 35 75 16 73 65 23 18 48 19 4 22 42 14 60 49 83 59 15 60 51 27 80 97 35 37 100 64 81 22 38 54 71 52 20 5 20 52 73 42 98 78 86 26 55 25 57 14 97 36 81 71 54 71 51 3 4 8 74 82 21 74 29 81 52 1 87 75 22 76 2 27 79 73 61 39 39 9 89 60 1 14 77 27 87 11 70 61 75 63 75\r\n', 'output': ['997408']}, {'input': '3\r\n3 2 3\r\n', 'output': ['32']}, {'input': '5\r\n8 1 3 4 9\r\n', 'output': ['220']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
279
100
100
100
["3\n1 -2 0", "6\n16 23 16 15 42 8"]
The first line contains one integer n (1 ≀ n ≀ 100) β€” the number of elements in a. The second line contains n integers a1, a2, ..., an ( - 100 ≀ ai ≀ 100) β€” the elements of sequence a.
4b5d14833f9b51bfd336cc0e661243a5
import java.util.Scanner; public class a { public static void main(String[]args) { Scanner input=new Scanner (System.in); int n=input.nextInt(); int b=0; int c=0; int []x=new int [101]; int k=0; while (k<n) { x[k]=input.nextInt(); k=k+1; } int y=x[0]; for (int t=1;t<n;t++) { if(x[t]<y) y=x[t]; } if (y>=0) { for (int q=0;q<n;q++) { b=b+x[q]; } c=0; } else { for (int w=0;w<n;w++) { if (x[w]>=0) b=b+x[w]; else c=c+x[w]; } } System.out.print(b-c); } }
["3", "120"]
Java
NoteIn the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C =  - 2, B - C = 3.In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120.
Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences. Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?
[{"input": "3\r\n1 -2 0\r\n", "output": ["3"]}, {"input": "6\r\n16 23 16 15 42 8\r\n", "output": ["120"]}, {"input": "1\r\n-1\r\n", "output": ["1"]}, {"input": "100\r\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100\r\n", "output": ["10000"]}, {"input": "2\r\n-1 5\r\n", "output": ["6"]}, {"input": "3\r\n-2 0 1\r\n", "output": ["3"]}, {"input": "12\r\n-1 -2 -3 4 4 -6 -6 56 3 3 -3 3\r\n", "output": ["94"]}, {"input": "4\r\n1 -1 1 -1\r\n", "output": ["4"]}, {"input": "4\r\n100 -100 100 -100\r\n", "output": ["400"]}, {"input": "3\r\n-2 -5 10\r\n", "output": ["17"]}, {"input": "5\r\n1 -2 3 -4 5\r\n", "output": ["15"]}, {"input": "3\r\n-100 100 -100\r\n", "output": ["300"]}, {"input": "6\r\n1 -1 1 -1 1 -1\r\n", "output": ["6"]}, {"input": "6\r\n2 -2 2 -2 2 -2\r\n", "output": ["12"]}, {"input": "9\r\n12 93 -2 0 0 0 3 -3 -9\r\n", "output": ["122"]}, {"input": "6\r\n-1 2 4 -5 -3 55\r\n", "output": ["70"]}, {"input": "6\r\n-12 8 68 -53 1 -15\r\n", "output": ["157"]}, {"input": "2\r\n-2 1\r\n", "output": ["3"]}, {"input": "3\r\n100 -100 100\r\n", "output": ["300"]}, {"input": "5\r\n100 100 -1 -100 2\r\n", "output": ["303"]}, {"input": "6\r\n-5 -4 -3 -2 -1 0\r\n", "output": ["15"]}, {"input": "6\r\n4 4 4 -3 -3 2\r\n", "output": ["20"]}, {"input": "2\r\n-1 2\r\n", "output": ["3"]}, {"input": "1\r\n100\r\n", "output": ["100"]}, {"input": "5\r\n-1 -2 3 1 2\r\n", "output": ["9"]}, {"input": "5\r\n100 -100 100 -100 100\r\n", "output": ["500"]}, {"input": "5\r\n1 -1 1 -1 1\r\n", "output": ["5"]}, {"input": "4\r\n0 0 0 -1\r\n", "output": ["1"]}, {"input": "5\r\n100 -100 -1 2 100\r\n", "output": ["303"]}, {"input": "2\r\n75 0\r\n", "output": ["75"]}, {"input": "4\r\n55 56 -59 -58\r\n", "output": ["228"]}, {"input": "2\r\n9 71\r\n", "output": ["80"]}, {"input": "2\r\n9 70\r\n", "output": ["79"]}, {"input": "2\r\n9 69\r\n", "output": ["78"]}, {"input": "2\r\n100 -100\r\n", "output": ["200"]}, {"input": "4\r\n-9 4 -9 5\r\n", "output": ["27"]}, {"input": "42\r\n91 -27 -79 -56 80 -93 -23 10 80 94 61 -89 -64 81 34 99 31 -32 -69 92 79 -9 73 66 -8 64 99 99 58 -19 -40 21 1 -33 93 -23 -62 27 55 41 57 36\r\n", "output": ["2348"]}, {"input": "7\r\n-1 2 2 2 -1 2 -1\r\n", "output": ["11"]}, {"input": "6\r\n-12 8 17 -69 7 -88\r\n", "output": ["201"]}, {"input": "3\r\n1 -2 5\r\n", "output": ["8"]}, {"input": "6\r\n-2 3 -4 5 6 -1\r\n", "output": ["21"]}, {"input": "2\r\n-5 1\r\n", "output": ["6"]}, {"input": "4\r\n2 2 -2 4\r\n", "output": ["10"]}, {"input": "68\r\n21 47 -75 -25 64 83 83 -21 89 24 43 44 -35 34 -42 92 -96 -52 -66 64 14 -87 25 -61 -78 83 -96 -18 95 83 -93 -28 75 49 87 65 -93 -69 -2 95 -24 -36 -61 -71 88 -53 -93 -51 -81 -65 -53 -46 -56 6 65 58 19 100 57 61 -53 44 -58 48 -8 80 -88 72\r\n", "output": ["3991"]}, {"input": "5\r\n5 5 -10 -1 1\r\n", "output": ["22"]}, {"input": "3\r\n-1 2 3\r\n", "output": ["6"]}, {"input": "76\r\n57 -38 -48 -81 93 -32 96 55 -44 2 38 -46 42 64 71 -73 95 31 -39 -62 -1 75 -17 57 28 52 12 -11 82 -84 59 -86 73 -97 34 97 -57 -85 -6 39 -5 -54 95 24 -44 35 -18 9 91 7 -22 -61 -80 54 -40 74 -90 15 -97 66 -52 -49 -24 65 21 -93 -29 -24 -4 -1 76 -93 7 -55 -53 1\r\n", "output": ["3787"]}, {"input": "5\r\n-1 -2 1 2 3\r\n", "output": ["9"]}, {"input": "4\r\n2 2 -2 -2\r\n", "output": ["8"]}, {"input": "6\r\n100 -100 100 -100 100 -100\r\n", "output": ["600"]}, {"input": "100\r\n-59 -33 34 0 69 24 -22 58 62 -36 5 45 -19 -73 61 -9 95 42 -73 -64 91 -96 2 53 -8 82 -79 16 18 -5 -53 26 71 38 -31 12 -33 -1 -65 -6 3 -89 22 33 -27 -36 41 11 -47 -32 47 -56 -38 57 -63 -41 23 41 29 78 16 -65 90 -58 -12 6 -60 42 -36 -52 -54 -95 -10 29 70 50 -94 1 93 48 -71 -77 -16 54 56 -60 66 76 31 8 44 -61 -74 23 37 38 18 -18 29 41\r\n", "output": ["4362"]}, {"input": "2\r\n-1 1\r\n", "output": ["2"]}, {"input": "3\r\n1 -2 100\r\n", "output": ["103"]}, {"input": "5\r\n1 -2 3 1 2\r\n", "output": ["9"]}, {"input": "10\r\n100 -10 -100 10 10 10 10 10 10 10\r\n", "output": ["280"]}, {"input": "4\r\n2 0 -2 4\r\n", "output": ["8"]}, {"input": "4\r\n3 -3 1 -1\r\n", "output": ["8"]}, {"input": "3\r\n1 -1 1\r\n", "output": ["3"]}, {"input": "4\r\n2 5 -2 4\r\n", "output": ["13"]}, {"input": "2\r\n-2 2\r\n", "output": ["4"]}, {"input": "3\r\n1 -2 1\r\n", "output": ["4"]}, {"input": "5\r\n-1 -2 1 1 -1\r\n", "output": ["6"]}, {"input": "4\r\n-2 0 2 4\r\n", "output": ["8"]}, {"input": "8\r\n-42 7 87 -16 -5 65 -88 1\r\n", "output": ["311"]}, {"input": "3\r\n1 -3 4\r\n", "output": ["8"]}, {"input": "1\r\n1\r\n", "output": ["1"]}, {"input": "2\r\n0 1\r\n", "output": ["1"]}, {"input": "3\r\n-1 2 -1\r\n", "output": ["4"]}, {"input": "18\r\n-21 12 65 66 -24 62 82 35 -45 -47 28 37 5 -32 22 -14 -69 -95\r\n", "output": ["761"]}, {"input": "4\r\n-1 1 -1 1\r\n", "output": ["4"]}, {"input": "5\r\n-1 2 1 1 1\r\n", "output": ["6"]}, {"input": "3\r\n1 1 1\r\n", "output": ["3"]}]
100
100
100
[{'input': '4\r\n1 -1 1 -1\r\n', 'output': ['4']}, {'input': '5\r\n100 -100 -1 2 100\r\n', 'output': ['303']}, {'input': '2\r\n9 69\r\n', 'output': ['78']}, {'input': '4\r\n2 5 -2 4\r\n', 'output': ['13']}, {'input': '1\r\n-1\r\n', 'output': ['1']}]
[{'input': '6\r\n4 4 4 -3 -3 2\r\n', 'output': ['20']}, {'input': '1\r\n-1\r\n', 'output': ['1']}, {'input': '2\r\n9 71\r\n', 'output': ['80']}, {'input': '5\r\n5 5 -10 -1 1\r\n', 'output': ['22']}, {'input': '6\r\n-1 2 4 -5 -3 55\r\n', 'output': ['70']}]
[{'input': '3\r\n1 1 1\r\n', 'output': ['3']}, {'input': '4\r\n0 0 0 -1\r\n', 'output': ['1']}, {'input': '6\r\n-5 -4 -3 -2 -1 0\r\n', 'output': ['15']}, {'input': '3\r\n-2 -5 10\r\n', 'output': ['17']}, {'input': '5\r\n-1 -2 3 1 2\r\n', 'output': ['9']}]
[{'input': '6\r\n-2 3 -4 5 6 -1\r\n', 'output': ['21']}, {'input': '3\r\n1 1 1\r\n', 'output': ['3']}, {'input': '2\r\n-5 1\r\n', 'output': ['6']}, {'input': '4\r\n1 -1 1 -1\r\n', 'output': ['4']}, {'input': '6\r\n4 4 4 -3 -3 2\r\n', 'output': ['20']}]
[{'input': '18\r\n-21 12 65 66 -24 62 82 35 -45 -47 28 37 5 -32 22 -14 -69 -95\r\n', 'output': ['761']}, {'input': '5\r\n1 -2 3 1 2\r\n', 'output': ['9']}, {'input': '3\r\n-1 2 3\r\n', 'output': ['6']}, {'input': '4\r\n2 2 -2 4\r\n', 'output': ['10']}, {'input': '100\r\n-59 -33 34 0 69 24 -22 58 62 -36 5 45 -19 -73 61 -9 95 42 -73 -64 91 -96 2 53 -8 82 -79 16 18 -5 -53 26 71 38 -31 12 -33 -1 -65 -6 3 -89 22 33 -27 -36 41 11 -47 -32 47 -56 -38 57 -63 -41 23 41 29 78 16 -65 90 -58 -12 6 -60 42 -36 -52 -54 -95 -10 29 70 50 -94 1 93 48 -71 -77 -16 54 56 -60 66 76 31 8 44 -61 -74 23 37 38 18 -18 29 41\r\n', 'output': ['4362']}]
100
100
100
100
100
100
100
100
100
86.96
100
100
100
100
78.57
280
100
97.392
95.714
["12345"]
The only line of the input contains a positive integer five digit number for which the activation code should be found.
51b1c216948663fff721c28d131bf18f
import java.util.Scanner; public class Problem_11 { static long p = 100000; public static void main(String[] args) { Scanner input = new Scanner(System.in); String s = input.nextLine(); //13542 long n = Long.valueOf(s.substring(0, 1) + s.substring(2, 3) + s.substring(4, 5) + s.substring(3, 4) + s.substring (1,2)); System.out.printf("%05d", (((((n * n * n) % p) * n) % p) * n) % p); } }
["71232"]
Java
null
Output exactly 5 digits without spaces between them β€” the found activation code of the program.
The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation code arrives.A young hacker Vasya disassembled the program and found the algorithm that transforms the shown number into the activation code. Note: it is clear that Vasya is a law-abiding hacker, and made it for a noble purpose β€” to show the developer the imperfection of their protection.The found algorithm looks the following way. At first the digits of the number are shuffled in the following order &lt;first digit&gt;&lt;third digit&gt;&lt;fifth digit&gt;&lt;fourth digit&gt;&lt;second digit&gt;. For example the shuffle of 12345 should lead to 13542. On the second stage the number is raised to the fifth power. The result of the shuffle and exponentiation of the number 12345 is 455Β 422Β 043Β 125Β 550Β 171Β 232. The answer is the 5 last digits of this result. For the number 12345 the answer should be 71232.Vasya is going to write a keygen program implementing this algorithm. Can you do the same?
[{"input": "12345\r\n", "output": ["71232"]}, {"input": "13542\r\n", "output": ["84443"]}, {"input": "71232\r\n", "output": ["10151"]}, {"input": "11111\r\n", "output": ["36551"]}, {"input": "10000\r\n", "output": ["00000"]}, {"input": "99999\r\n", "output": ["99999"]}, {"input": "91537\r\n", "output": ["27651"]}, {"input": "70809\r\n", "output": ["00000"]}, {"input": "41675\r\n", "output": ["61851"]}, {"input": "32036\r\n", "output": ["82432"]}]
100
100
100
[{'input': '13542\r\n', 'output': ['84443']}, {'input': '10000\r\n', 'output': ['00000']}, {'input': '12345\r\n', 'output': ['71232']}, {'input': '41675\r\n', 'output': ['61851']}, {'input': '11111\r\n', 'output': ['36551']}]
[{'input': '71232\r\n', 'output': ['10151']}, {'input': '32036\r\n', 'output': ['82432']}, {'input': '91537\r\n', 'output': ['27651']}, {'input': '12345\r\n', 'output': ['71232']}, {'input': '70809\r\n', 'output': ['00000']}]
[{'input': '71232\r\n', 'output': ['10151']}, {'input': '70809\r\n', 'output': ['00000']}, {'input': '10000\r\n', 'output': ['00000']}, {'input': '41675\r\n', 'output': ['61851']}, {'input': '12345\r\n', 'output': ['71232']}]
[{'input': '70809\r\n', 'output': ['00000']}, {'input': '13542\r\n', 'output': ['84443']}, {'input': '91537\r\n', 'output': ['27651']}, {'input': '32036\r\n', 'output': ['82432']}, {'input': '99999\r\n', 'output': ['99999']}]
[{'input': '71232\r\n', 'output': ['10151']}, {'input': '41675\r\n', 'output': ['61851']}, {'input': '32036\r\n', 'output': ['82432']}, {'input': '70809\r\n', 'output': ['00000']}, {'input': '91537\r\n', 'output': ['27651']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
281
100
100
100
["3\n11 23", "5\n01 07"]
The first line contains a single integer x (1 ≀ x ≀ 60). The second line contains two two-digit integers, hh and mm (00 ≀ hh ≀ 23, 00 ≀ mm ≀ 59).
5ecd569e02e0164a5da9ff549fca3ceb
import java.util.*; public class JamieAndAlarmSnooze { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int h=sc.nextInt(); int m=sc.nextInt(); int c=0; while (h%10!=7 && m%10!=7) { m-=x; c++; if (m<0) { h--; m+=60; } if (h<0) h+=24; } System.out.println(c); sc.close(); } }
["2", "0"]
Java
NoteIn the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20.In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky.
Print the minimum number of times he needs to press the button.
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every x minutes until hh: mm is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button.A time is considered lucky if it contains a digit '7'. For example, 13: 07 and 17: 27 are lucky, while 00: 48 and 21: 34 are not lucky.Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at hh: mm.Formally, find the smallest possible non-negative integer y such that the time representation of the time xΒ·y minutes before hh: mm contains the digit '7'.Jamie uses 24-hours clock, so after 23: 59 comes 00: 00.
[{"input": "3\r\n11 23\r\n", "output": ["2"]}, {"input": "5\r\n01 07\r\n", "output": ["0"]}, {"input": "34\r\n09 24\r\n", "output": ["3"]}, {"input": "2\r\n14 37\r\n", "output": ["0"]}, {"input": "14\r\n19 54\r\n", "output": ["9"]}, {"input": "42\r\n15 44\r\n", "output": ["12"]}, {"input": "46\r\n02 43\r\n", "output": ["1"]}, {"input": "14\r\n06 41\r\n", "output": ["1"]}, {"input": "26\r\n04 58\r\n", "output": ["26"]}, {"input": "54\r\n16 47\r\n", "output": ["0"]}, {"input": "38\r\n20 01\r\n", "output": ["3"]}, {"input": "11\r\n02 05\r\n", "output": ["8"]}, {"input": "55\r\n22 10\r\n", "output": ["5"]}, {"input": "23\r\n10 08\r\n", "output": ["6"]}, {"input": "23\r\n23 14\r\n", "output": ["9"]}, {"input": "51\r\n03 27\r\n", "output": ["0"]}, {"input": "35\r\n15 25\r\n", "output": ["13"]}, {"input": "3\r\n12 15\r\n", "output": ["6"]}, {"input": "47\r\n00 28\r\n", "output": ["3"]}, {"input": "31\r\n13 34\r\n", "output": ["7"]}, {"input": "59\r\n17 32\r\n", "output": ["0"]}, {"input": "25\r\n11 03\r\n", "output": ["8"]}, {"input": "9\r\n16 53\r\n", "output": ["4"]}, {"input": "53\r\n04 06\r\n", "output": ["3"]}, {"input": "37\r\n00 12\r\n", "output": ["5"]}, {"input": "5\r\n13 10\r\n", "output": ["63"]}, {"input": "50\r\n01 59\r\n", "output": ["10"]}, {"input": "34\r\n06 13\r\n", "output": ["4"]}, {"input": "2\r\n18 19\r\n", "output": ["1"]}, {"input": "46\r\n06 16\r\n", "output": ["17"]}, {"input": "14\r\n03 30\r\n", "output": ["41"]}, {"input": "40\r\n13 37\r\n", "output": ["0"]}, {"input": "24\r\n17 51\r\n", "output": ["0"]}, {"input": "8\r\n14 57\r\n", "output": ["0"]}, {"input": "52\r\n18 54\r\n", "output": ["2"]}, {"input": "20\r\n15 52\r\n", "output": ["24"]}, {"input": "20\r\n03 58\r\n", "output": ["30"]}, {"input": "48\r\n07 11\r\n", "output": ["0"]}, {"input": "32\r\n04 01\r\n", "output": ["2"]}, {"input": "60\r\n08 15\r\n", "output": ["1"]}, {"input": "44\r\n20 20\r\n", "output": ["4"]}, {"input": "55\r\n15 35\r\n", "output": ["9"]}, {"input": "55\r\n03 49\r\n", "output": ["11"]}, {"input": "23\r\n16 39\r\n", "output": ["4"]}, {"input": "7\r\n20 36\r\n", "output": ["7"]}, {"input": "35\r\n16 42\r\n", "output": ["1"]}, {"input": "35\r\n05 56\r\n", "output": ["21"]}, {"input": "3\r\n17 45\r\n", "output": ["0"]}, {"input": "47\r\n05 59\r\n", "output": ["6"]}, {"input": "15\r\n10 13\r\n", "output": ["9"]}, {"input": "59\r\n06 18\r\n", "output": ["9"]}, {"input": "34\r\n17 18\r\n", "output": ["0"]}, {"input": "18\r\n05 23\r\n", "output": ["2"]}, {"input": "46\r\n17 21\r\n", "output": ["0"]}, {"input": "30\r\n06 27\r\n", "output": ["0"]}, {"input": "14\r\n18 40\r\n", "output": ["3"]}, {"input": "58\r\n22 54\r\n", "output": ["6"]}, {"input": "26\r\n19 44\r\n", "output": ["5"]}, {"input": "10\r\n15 57\r\n", "output": ["0"]}, {"input": "54\r\n20 47\r\n", "output": ["0"]}, {"input": "22\r\n08 45\r\n", "output": ["3"]}, {"input": "48\r\n18 08\r\n", "output": ["1"]}, {"input": "32\r\n07 06\r\n", "output": ["0"]}, {"input": "60\r\n19 19\r\n", "output": ["2"]}, {"input": "45\r\n07 25\r\n", "output": ["0"]}, {"input": "29\r\n12 39\r\n", "output": ["8"]}, {"input": "13\r\n08 28\r\n", "output": ["3"]}, {"input": "41\r\n21 42\r\n", "output": ["5"]}, {"input": "41\r\n09 32\r\n", "output": ["3"]}, {"input": "9\r\n21 45\r\n", "output": ["2"]}, {"input": "37\r\n10 43\r\n", "output": ["5"]}, {"input": "3\r\n20 50\r\n", "output": ["1"]}, {"input": "47\r\n00 04\r\n", "output": ["1"]}, {"input": "15\r\n13 10\r\n", "output": ["21"]}, {"input": "15\r\n17 23\r\n", "output": ["0"]}, {"input": "43\r\n22 13\r\n", "output": ["2"]}, {"input": "27\r\n10 26\r\n", "output": ["6"]}, {"input": "55\r\n22 24\r\n", "output": ["5"]}, {"input": "55\r\n03 30\r\n", "output": ["11"]}, {"input": "24\r\n23 27\r\n", "output": ["0"]}, {"input": "52\r\n11 33\r\n", "output": ["3"]}, {"input": "18\r\n22 48\r\n", "output": ["17"]}, {"input": "1\r\n12 55\r\n", "output": ["8"]}, {"input": "1\r\n04 27\r\n", "output": ["0"]}, {"input": "1\r\n12 52\r\n", "output": ["5"]}, {"input": "1\r\n20 16\r\n", "output": ["9"]}, {"input": "1\r\n04 41\r\n", "output": ["4"]}, {"input": "1\r\n20 21\r\n", "output": ["4"]}, {"input": "1\r\n04 45\r\n", "output": ["8"]}, {"input": "1\r\n12 18\r\n", "output": ["1"]}, {"input": "1\r\n04 42\r\n", "output": ["5"]}, {"input": "1\r\n02 59\r\n", "output": ["2"]}, {"input": "1\r\n18 24\r\n", "output": ["7"]}, {"input": "1\r\n02 04\r\n", "output": ["7"]}, {"input": "1\r\n18 28\r\n", "output": ["1"]}, {"input": "1\r\n18 01\r\n", "output": ["2"]}, {"input": "1\r\n10 25\r\n", "output": ["8"]}, {"input": "1\r\n02 49\r\n", "output": ["2"]}, {"input": "1\r\n02 30\r\n", "output": ["3"]}, {"input": "1\r\n18 54\r\n", "output": ["7"]}, {"input": "1\r\n02 19\r\n", "output": ["2"]}, {"input": "1\r\n05 25\r\n", "output": ["8"]}, {"input": "60\r\n23 55\r\n", "output": ["6"]}, {"input": "60\r\n08 19\r\n", "output": ["1"]}, {"input": "60\r\n00 00\r\n", "output": ["7"]}, {"input": "60\r\n08 24\r\n", "output": ["1"]}, {"input": "60\r\n16 13\r\n", "output": ["9"]}, {"input": "60\r\n08 21\r\n", "output": ["1"]}, {"input": "60\r\n16 45\r\n", "output": ["9"]}, {"input": "60\r\n08 26\r\n", "output": ["1"]}, {"input": "60\r\n08 50\r\n", "output": ["1"]}, {"input": "60\r\n05 21\r\n", "output": ["12"]}, {"input": "60\r\n13 29\r\n", "output": ["6"]}, {"input": "60\r\n05 18\r\n", "output": ["12"]}, {"input": "60\r\n13 42\r\n", "output": ["6"]}, {"input": "60\r\n05 07\r\n", "output": ["0"]}, {"input": "60\r\n05 47\r\n", "output": ["0"]}, {"input": "60\r\n21 55\r\n", "output": ["4"]}, {"input": "60\r\n05 36\r\n", "output": ["12"]}, {"input": "60\r\n21 08\r\n", "output": ["4"]}, {"input": "60\r\n21 32\r\n", "output": ["4"]}, {"input": "60\r\n16 31\r\n", "output": ["9"]}, {"input": "5\r\n00 00\r\n", "output": ["73"]}, {"input": "2\r\n06 58\r\n", "output": ["390"]}, {"input": "2\r\n00 00\r\n", "output": ["181"]}, {"input": "10\r\n00 00\r\n", "output": ["37"]}, {"input": "60\r\n01 00\r\n", "output": ["8"]}, {"input": "12\r\n00 06\r\n", "output": ["31"]}, {"input": "1\r\n00 01\r\n", "output": ["4"]}, {"input": "5\r\n00 05\r\n", "output": ["74"]}, {"input": "60\r\n01 01\r\n", "output": ["8"]}, {"input": "11\r\n18 11\r\n", "output": ["2"]}, {"input": "60\r\n01 15\r\n", "output": ["8"]}, {"input": "10\r\n00 16\r\n", "output": ["38"]}, {"input": "60\r\n00 59\r\n", "output": ["7"]}, {"input": "30\r\n00 00\r\n", "output": ["13"]}, {"input": "60\r\n01 05\r\n", "output": ["8"]}, {"input": "4\r\n00 03\r\n", "output": ["4"]}, {"input": "4\r\n00 00\r\n", "output": ["91"]}, {"input": "60\r\n00 01\r\n", "output": ["7"]}, {"input": "6\r\n00 03\r\n", "output": ["1"]}, {"input": "13\r\n00 00\r\n", "output": ["1"]}, {"input": "5\r\n06 00\r\n", "output": ["145"]}, {"input": "60\r\n04 08\r\n", "output": ["11"]}, {"input": "5\r\n01 55\r\n", "output": ["96"]}, {"input": "8\r\n00 08\r\n", "output": ["47"]}, {"input": "23\r\n18 23\r\n", "output": ["2"]}, {"input": "6\r\n00 06\r\n", "output": ["62"]}, {"input": "59\r\n18 59\r\n", "output": ["2"]}, {"input": "11\r\n00 10\r\n", "output": ["3"]}, {"input": "10\r\n00 01\r\n", "output": ["37"]}, {"input": "59\r\n00 00\r\n", "output": ["7"]}, {"input": "10\r\n18 10\r\n", "output": ["2"]}, {"input": "5\r\n00 01\r\n", "output": ["73"]}, {"input": "1\r\n00 00\r\n", "output": ["3"]}, {"input": "8\r\n00 14\r\n", "output": ["47"]}, {"input": "60\r\n03 00\r\n", "output": ["10"]}, {"input": "60\r\n00 10\r\n", "output": ["7"]}, {"input": "5\r\n01 13\r\n", "output": ["87"]}, {"input": "30\r\n02 43\r\n", "output": ["18"]}, {"input": "17\r\n00 08\r\n", "output": ["3"]}, {"input": "3\r\n00 00\r\n", "output": ["1"]}, {"input": "60\r\n00 05\r\n", "output": ["7"]}, {"input": "5\r\n18 05\r\n", "output": ["2"]}, {"input": "30\r\n00 30\r\n", "output": ["14"]}, {"input": "1\r\n00 06\r\n", "output": ["9"]}, {"input": "55\r\n00 00\r\n", "output": ["7"]}, {"input": "8\r\n02 08\r\n", "output": ["62"]}, {"input": "7\r\n00 00\r\n", "output": ["9"]}, {"input": "6\r\n08 06\r\n", "output": ["2"]}, {"input": "48\r\n06 24\r\n", "output": ["16"]}, {"input": "8\r\n06 58\r\n", "output": ["98"]}, {"input": "3\r\n12 00\r\n", "output": ["1"]}, {"input": "5\r\n01 06\r\n", "output": ["86"]}, {"input": "2\r\n00 08\r\n", "output": ["185"]}, {"input": "3\r\n18 03\r\n", "output": ["2"]}, {"input": "1\r\n17 00\r\n", "output": ["0"]}, {"input": "59\r\n00 48\r\n", "output": ["7"]}, {"input": "5\r\n12 01\r\n", "output": ["49"]}, {"input": "55\r\n01 25\r\n", "output": ["9"]}, {"input": "2\r\n07 23\r\n", "output": ["0"]}, {"input": "10\r\n01 10\r\n", "output": ["44"]}, {"input": "2\r\n00 01\r\n", "output": ["2"]}, {"input": "59\r\n00 01\r\n", "output": ["6"]}, {"input": "5\r\n00 02\r\n", "output": ["1"]}, {"input": "4\r\n01 02\r\n", "output": ["106"]}, {"input": "5\r\n00 06\r\n", "output": ["74"]}, {"input": "42\r\n00 08\r\n", "output": ["9"]}, {"input": "60\r\n01 20\r\n", "output": ["8"]}, {"input": "3\r\n06 00\r\n", "output": ["1"]}, {"input": "4\r\n00 01\r\n", "output": ["1"]}, {"input": "2\r\n00 06\r\n", "output": ["184"]}, {"input": "1\r\n00 57\r\n", "output": ["0"]}, {"input": "6\r\n00 00\r\n", "output": ["61"]}, {"input": "5\r\n08 40\r\n", "output": ["9"]}, {"input": "58\r\n00 55\r\n", "output": ["1"]}, {"input": "2\r\n00 02\r\n", "output": ["182"]}, {"input": "1\r\n08 01\r\n", "output": ["2"]}, {"input": "10\r\n10 10\r\n", "output": ["14"]}, {"input": "60\r\n01 11\r\n", "output": ["8"]}, {"input": "2\r\n07 00\r\n", "output": ["0"]}, {"input": "15\r\n00 03\r\n", "output": ["25"]}, {"input": "6\r\n04 34\r\n", "output": ["106"]}, {"input": "16\r\n00 16\r\n", "output": ["24"]}, {"input": "2\r\n00 59\r\n", "output": ["1"]}, {"input": "59\r\n00 08\r\n", "output": ["7"]}, {"input": "10\r\n03 10\r\n", "output": ["56"]}, {"input": "3\r\n08 03\r\n", "output": ["2"]}, {"input": "20\r\n06 11\r\n", "output": ["37"]}, {"input": "4\r\n01 00\r\n", "output": ["106"]}, {"input": "38\r\n01 08\r\n", "output": ["12"]}, {"input": "60\r\n00 06\r\n", "output": ["7"]}, {"input": "5\r\n12 00\r\n", "output": ["49"]}, {"input": "6\r\n01 42\r\n", "output": ["78"]}, {"input": "4\r\n00 04\r\n", "output": ["92"]}, {"input": "60\r\n04 05\r\n", "output": ["11"]}, {"input": "1\r\n00 53\r\n", "output": ["6"]}, {"input": "5\r\n08 05\r\n", "output": ["2"]}, {"input": "60\r\n18 45\r\n", "output": ["1"]}, {"input": "60\r\n06 23\r\n", "output": ["13"]}, {"input": "6\r\n00 15\r\n", "output": ["3"]}, {"input": "58\r\n00 06\r\n", "output": ["7"]}, {"input": "2\r\n06 44\r\n", "output": ["383"]}, {"input": "1\r\n08 00\r\n", "output": ["1"]}, {"input": "10\r\n06 58\r\n", "output": ["78"]}, {"input": "59\r\n00 58\r\n", "output": ["8"]}, {"input": "1\r\n18 00\r\n", "output": ["1"]}, {"input": "50\r\n00 42\r\n", "output": ["9"]}, {"input": "30\r\n18 30\r\n", "output": ["2"]}, {"input": "60\r\n21 59\r\n", "output": ["4"]}, {"input": "2\r\n10 52\r\n", "output": ["87"]}, {"input": "56\r\n00 00\r\n", "output": ["7"]}, {"input": "16\r\n18 16\r\n", "output": ["2"]}, {"input": "5\r\n01 05\r\n", "output": ["86"]}, {"input": "5\r\n05 00\r\n", "output": ["133"]}, {"input": "5\r\n23 59\r\n", "output": ["72"]}, {"input": "7\r\n17 13\r\n", "output": ["0"]}, {"input": "58\r\n00 00\r\n", "output": ["7"]}, {"input": "15\r\n00 07\r\n", "output": ["0"]}, {"input": "59\r\n08 00\r\n", "output": ["1"]}, {"input": "46\r\n00 00\r\n", "output": ["8"]}, {"input": "59\r\n01 05\r\n", "output": ["2"]}, {"input": "2\r\n01 00\r\n", "output": ["211"]}, {"input": "60\r\n00 24\r\n", "output": ["7"]}, {"input": "10\r\n00 08\r\n", "output": ["37"]}, {"input": "10\r\n00 06\r\n", "output": ["37"]}, {"input": "60\r\n01 24\r\n", "output": ["8"]}, {"input": "50\r\n00 10\r\n", "output": ["8"]}, {"input": "2\r\n03 00\r\n", "output": ["271"]}, {"input": "4\r\n19 04\r\n", "output": ["17"]}, {"input": "25\r\n00 23\r\n", "output": ["16"]}, {"input": "10\r\n01 01\r\n", "output": ["43"]}]
100
100
100
[{'input': '16\r\n00 16\r\n', 'output': ['24']}, {'input': '58\r\n22 54\r\n', 'output': ['6']}, {'input': '1\r\n00 53\r\n', 'output': ['6']}, {'input': '59\r\n08 00\r\n', 'output': ['1']}, {'input': '60\r\n05 47\r\n', 'output': ['0']}]
[{'input': '13\r\n08 28\r\n', 'output': ['3']}, {'input': '20\r\n03 58\r\n', 'output': ['30']}, {'input': '60\r\n16 13\r\n', 'output': ['9']}, {'input': '11\r\n00 10\r\n', 'output': ['3']}, {'input': '60\r\n05 36\r\n', 'output': ['12']}]
[{'input': '60\r\n01 05\r\n', 'output': ['8']}, {'input': '40\r\n13 37\r\n', 'output': ['0']}, {'input': '58\r\n22 54\r\n', 'output': ['6']}, {'input': '31\r\n13 34\r\n', 'output': ['7']}, {'input': '29\r\n12 39\r\n', 'output': ['8']}]
[{'input': '1\r\n00 01\r\n', 'output': ['4']}, {'input': '60\r\n01 20\r\n', 'output': ['8']}, {'input': '1\r\n05 25\r\n', 'output': ['8']}, {'input': '40\r\n13 37\r\n', 'output': ['0']}, {'input': '44\r\n20 20\r\n', 'output': ['4']}]
[{'input': '60\r\n05 07\r\n', 'output': ['0']}, {'input': '1\r\n20 21\r\n', 'output': ['4']}, {'input': '59\r\n06 18\r\n', 'output': ['9']}, {'input': '2\r\n00 02\r\n', 'output': ['182']}, {'input': '35\r\n15 25\r\n', 'output': ['13']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
282
100
100
100
["047", "16", "472747"]
The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
639b8b8d0dc42df46b139f0aeb3a7a0a
import java.lang.*; import java.util.*; public class Luckysubstring { public static void main(String[] args) { Scanner in = new Scanner(System.in); String input = in.nextLine(); int count4 = 0; int count7 = 0; in.close(); if (input.contains("4") || input.contains("7")) { for (int i = 0; i < input.length(); i++) { if (input.charAt(i) == '4') { count4++; } else if (input.charAt(i) == '7') { count7++; } } if (count4 >= count7) { System.out.println(4); } else { System.out.println(7); } } else { System.out.println(-1); } } }
["4", "-1", "7"]
Java
NoteThe lexicographical comparison of strings is performed by the &lt; operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≀ i ≀ min(|x|, |y|)), that xi &lt; yi and for any j (1 ≀ j &lt; i) xj = yj. Here |a| denotes the length of string a.In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".In the second sample s has no substrings which are lucky numbers.In the third sample the three conditions are only fulfilled for string "7".
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.One day Petya was delivered a string s, containing only digits. He needs to find a string that represents a lucky number without leading zeroes, is not empty, is contained in s as a substring the maximum number of times.Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
[{"input": "047\r\n", "output": ["4"]}, {"input": "16\r\n", "output": ["-1"]}, {"input": "472747\r\n", "output": ["7"]}, {"input": "1925\r\n", "output": ["-1"]}, {"input": "5486846414848445484\r\n", "output": ["4"]}, {"input": "516160414\r\n", "output": ["4"]}, {"input": "9458569865994896\r\n", "output": ["4"]}, {"input": "94894948577777777884888\r\n", "output": ["7"]}, {"input": "00000\r\n", "output": ["-1"]}, {"input": "9589\r\n", "output": ["-1"]}, {"input": "7665711\r\n", "output": ["7"]}, {"input": "538772857\r\n", "output": ["7"]}, {"input": "8679647744\r\n", "output": ["4"]}, {"input": "23607019991994\r\n", "output": ["4"]}, {"input": "86145305734278927901987281894864719533015270066521\r\n", "output": ["7"]}, {"input": "22438808523154336905543301642540261833729318191\r\n", "output": ["4"]}, {"input": "290732082244359495795943967215788554387079\r\n", "output": ["7"]}, {"input": "6363333480463521971676988087733137609715\r\n", "output": ["7"]}, {"input": "637789221789855555993957058\r\n", "output": ["7"]}, {"input": "11536708648794535307468278326553811\r\n", "output": ["7"]}, {"input": "619433861636130069773\r\n", "output": ["7"]}, {"input": "7\r\n", "output": ["7"]}, {"input": "00000000000000000000000000000000000000000000000000\r\n", "output": ["-1"]}, {"input": "0000000000000000000000000000000000000047\r\n", "output": ["4"]}, {"input": "8175012266795100056032281135654854227489558885698\r\n", "output": ["4"]}, {"input": "8862708665262955384044574268728167940741129\r\n", "output": ["4"]}, {"input": "538772857\r\n", "output": ["7"]}, {"input": "94872076199824813574576121510803\r\n", "output": ["7"]}, {"input": "44101164480392494025995467\r\n", "output": ["4"]}, {"input": "0445460407410702955646485\r\n", "output": ["4"]}, {"input": "91076008557028243309\r\n", "output": ["7"]}, {"input": "33120039\r\n", "output": ["-1"]}, {"input": "4\r\n", "output": ["4"]}, {"input": "74747474747474747474747474747474747474747474747474\r\n", "output": ["4"]}, {"input": "74747474747474747474747774747474747474747474747474\r\n", "output": ["7"]}, {"input": "74747474747474747474747474747474744474747474747474\r\n", "output": ["4"]}, {"input": "47474747474747474747474747474747474747474747474747\r\n", "output": ["4"]}, {"input": "40\r\n", "output": ["4"]}, {"input": "07\r\n", "output": ["7"]}, {"input": "007\r\n", "output": ["7"]}, {"input": "44\r\n", "output": ["4"]}, {"input": "74\r\n", "output": ["4"]}]
100
100
100
[{'input': '4\r\n', 'output': ['4']}, {'input': '74747474747474747474747774747474747474747474747474\r\n', 'output': ['7']}, {'input': '44101164480392494025995467\r\n', 'output': ['4']}, {'input': '16\r\n', 'output': ['-1']}, {'input': '74747474747474747474747474747474744474747474747474\r\n', 'output': ['4']}]
[{'input': '11536708648794535307468278326553811\r\n', 'output': ['7']}, {'input': '472747\r\n', 'output': ['7']}, {'input': '8679647744\r\n', 'output': ['4']}, {'input': '538772857\r\n', 'output': ['7']}, {'input': '7665711\r\n', 'output': ['7']}]
[{'input': '16\r\n', 'output': ['-1']}, {'input': '44\r\n', 'output': ['4']}, {'input': '74747474747474747474747474747474747474747474747474\r\n', 'output': ['4']}, {'input': '9589\r\n', 'output': ['-1']}, {'input': '8175012266795100056032281135654854227489558885698\r\n', 'output': ['4']}]
[{'input': '23607019991994\r\n', 'output': ['4']}, {'input': '8175012266795100056032281135654854227489558885698\r\n', 'output': ['4']}, {'input': '007\r\n', 'output': ['7']}, {'input': '22438808523154336905543301642540261833729318191\r\n', 'output': ['4']}, {'input': '637789221789855555993957058\r\n', 'output': ['7']}]
[{'input': '74\r\n', 'output': ['4']}, {'input': '047\r\n', 'output': ['4']}, {'input': '07\r\n', 'output': ['7']}, {'input': '4\r\n', 'output': ['4']}, {'input': '91076008557028243309\r\n', 'output': ['7']}]
100
100
100
100
100
100
93.75
93.75
93.75
93.75
91.67
91.67
83.33
91.67
91.67
283
100
95
90.002
["2\n2 8", "3\n5 1 10", "7\n3 3 2 7 9 6 8"]
The first line contains integer n (1 ≀ n ≀ 20). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 25) β€” the number of times Greg repeats the exercises.
579021de624c072f5e0393aae762117e
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main{ public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); int n=Integer.parseInt(st.nextToken()); st=new StringTokenizer(br.readLine()); int Nchest=0; int Nbiceps=0; int Nback=0; int w=2; for (int i =1; i <=n; i++) { if(i % 3==0) Nback+=Integer.parseInt(st.nextToken()); else if(i==w){ w=w+3; Nbiceps+=Integer.parseInt(st.nextToken()); } else Nchest+=Integer.parseInt(st.nextToken()); } if(Nchest > Nbiceps && Nchest > Nback) System.out.println("chest"); else if( Nbiceps> Nchest && Nbiceps > Nback) System.out.println("biceps"); else System.out.println("back"); } }
["biceps", "back", "chest"]
Java
NoteIn the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous.
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a1, a2, ..., an. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exercise ai times.Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the n-th exercise.Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.
[{"input": "2\r\n2 8\r\n", "output": ["biceps"]}, {"input": "3\r\n5 1 10\r\n", "output": ["back"]}, {"input": "7\r\n3 3 2 7 9 6 8\r\n", "output": ["chest"]}, {"input": "4\r\n5 6 6 2\r\n", "output": ["chest"]}, {"input": "5\r\n8 2 2 6 3\r\n", "output": ["chest"]}, {"input": "6\r\n8 7 2 5 3 4\r\n", "output": ["chest"]}, {"input": "8\r\n7 2 9 10 3 8 10 6\r\n", "output": ["chest"]}, {"input": "9\r\n5 4 2 3 4 4 5 2 2\r\n", "output": ["chest"]}, {"input": "10\r\n4 9 8 5 3 8 8 10 4 2\r\n", "output": ["biceps"]}, {"input": "11\r\n10 9 7 6 1 3 9 7 1 3 5\r\n", "output": ["chest"]}, {"input": "12\r\n24 22 6 16 5 21 1 7 2 19 24 5\r\n", "output": ["chest"]}, {"input": "13\r\n24 10 5 7 16 17 2 7 9 20 15 2 24\r\n", "output": ["chest"]}, {"input": "14\r\n13 14 19 8 5 17 9 16 15 9 5 6 3 7\r\n", "output": ["back"]}, {"input": "15\r\n24 12 22 21 25 23 21 5 3 24 23 13 12 16 12\r\n", "output": ["chest"]}, {"input": "16\r\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8\r\n", "output": ["biceps"]}, {"input": "17\r\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19\r\n", "output": ["chest"]}, {"input": "18\r\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21\r\n", "output": ["back"]}, {"input": "19\r\n22 22 24 25 19 10 7 10 4 25 19 14 1 14 3 18 4 19 24\r\n", "output": ["chest"]}, {"input": "20\r\n9 8 22 11 18 14 15 10 17 11 2 1 25 20 7 24 4 25 9 20\r\n", "output": ["chest"]}, {"input": "1\r\n10\r\n", "output": ["chest"]}, {"input": "2\r\n15 3\r\n", "output": ["chest"]}, {"input": "3\r\n21 11 19\r\n", "output": ["chest"]}, {"input": "4\r\n19 24 13 15\r\n", "output": ["chest"]}, {"input": "5\r\n4 24 1 9 19\r\n", "output": ["biceps"]}, {"input": "6\r\n6 22 24 7 15 24\r\n", "output": ["back"]}, {"input": "7\r\n10 8 23 23 14 18 14\r\n", "output": ["chest"]}, {"input": "8\r\n5 16 8 9 17 16 14 7\r\n", "output": ["biceps"]}, {"input": "9\r\n12 3 10 23 6 4 22 13 12\r\n", "output": ["chest"]}, {"input": "10\r\n1 9 20 18 20 17 7 24 23 2\r\n", "output": ["back"]}, {"input": "11\r\n22 25 8 2 18 15 1 13 1 11 4\r\n", "output": ["biceps"]}, {"input": "12\r\n20 12 14 2 15 6 24 3 11 8 11 14\r\n", "output": ["chest"]}, {"input": "13\r\n2 18 8 8 8 20 5 22 15 2 5 19 18\r\n", "output": ["back"]}, {"input": "14\r\n1 6 10 25 17 13 21 11 19 4 15 24 5 22\r\n", "output": ["biceps"]}, {"input": "15\r\n13 5 25 13 17 25 19 21 23 17 12 6 14 8 6\r\n", "output": ["back"]}, {"input": "16\r\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14\r\n", "output": ["chest"]}, {"input": "17\r\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10\r\n", "output": ["biceps"]}, {"input": "18\r\n18 15 4 25 5 11 21 25 12 14 25 23 19 19 13 6 9 17\r\n", "output": ["chest"]}, {"input": "19\r\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14\r\n", "output": ["back"]}, {"input": "20\r\n19 18 11 3 6 14 3 3 25 3 1 19 25 24 23 12 7 4 8 6\r\n", "output": ["back"]}, {"input": "1\r\n19\r\n", "output": ["chest"]}, {"input": "2\r\n1 7\r\n", "output": ["biceps"]}, {"input": "3\r\n18 18 23\r\n", "output": ["back"]}, {"input": "4\r\n12 15 1 13\r\n", "output": ["chest"]}, {"input": "5\r\n11 14 25 21 21\r\n", "output": ["biceps"]}, {"input": "6\r\n11 9 12 11 22 18\r\n", "output": ["biceps"]}, {"input": "7\r\n11 1 16 20 21 25 20\r\n", "output": ["chest"]}, {"input": "8\r\n1 2 20 9 3 22 17 4\r\n", "output": ["back"]}, {"input": "9\r\n19 2 10 19 15 20 3 1 13\r\n", "output": ["back"]}, {"input": "10\r\n11 2 11 8 21 16 2 3 19 9\r\n", "output": ["back"]}, {"input": "20\r\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 24\r\n", "output": ["chest"]}, {"input": "12\r\n4 24 21 3 13 24 22 13 12 21 1 15\r\n", "output": ["back"]}, {"input": "13\r\n14 14 16 2 13 5 1 14 9 4 16 8 3\r\n", "output": ["biceps"]}, {"input": "14\r\n1 9 15 4 11 8 25 3 9 14 13 2 1 11\r\n", "output": ["biceps"]}, {"input": "15\r\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17\r\n", "output": ["back"]}, {"input": "16\r\n2 8 2 8 13 22 20 12 22 23 18 13 18 22 11 17\r\n", "output": ["chest"]}, {"input": "17\r\n24 5 5 16 10 8 22 6 4 13 10 10 5 23 8 20 8\r\n", "output": ["chest"]}, {"input": "18\r\n14 8 9 12 11 18 24 1 14 24 18 5 12 17 1 10 1 22\r\n", "output": ["chest"]}, {"input": "19\r\n21 2 10 6 9 1 24 5 2 19 10 13 10 7 19 2 6 13 24\r\n", "output": ["chest"]}, {"input": "20\r\n7 1 14 17 6 6 18 13 12 3 25 4 3 19 22 24 16 14 1 23\r\n", "output": ["biceps"]}, {"input": "20\r\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22\r\n", "output": ["biceps"]}]
100
100
100
[{'input': '3\r\n21 11 19\r\n', 'output': ['chest']}, {'input': '18\r\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21\r\n', 'output': ['back']}, {'input': '19\r\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14\r\n', 'output': ['back']}, {'input': '10\r\n4 9 8 5 3 8 8 10 4 2\r\n', 'output': ['biceps']}, {'input': '2\r\n2 8\r\n', 'output': ['biceps']}]
[{'input': '11\r\n10 9 7 6 1 3 9 7 1 3 5\r\n', 'output': ['chest']}, {'input': '16\r\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14\r\n', 'output': ['chest']}, {'input': '7\r\n3 3 2 7 9 6 8\r\n', 'output': ['chest']}, {'input': '6\r\n8 7 2 5 3 4\r\n', 'output': ['chest']}, {'input': '8\r\n5 16 8 9 17 16 14 7\r\n', 'output': ['biceps']}]
[{'input': '17\r\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10\r\n', 'output': ['biceps']}, {'input': '4\r\n12 15 1 13\r\n', 'output': ['chest']}, {'input': '3\r\n21 11 19\r\n', 'output': ['chest']}, {'input': '7\r\n11 1 16 20 21 25 20\r\n', 'output': ['chest']}, {'input': '20\r\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22\r\n', 'output': ['biceps']}]
[{'input': '6\r\n8 7 2 5 3 4\r\n', 'output': ['chest']}, {'input': '1\r\n10\r\n', 'output': ['chest']}, {'input': '8\r\n7 2 9 10 3 8 10 6\r\n', 'output': ['chest']}, {'input': '16\r\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8\r\n', 'output': ['biceps']}, {'input': '16\r\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14\r\n', 'output': ['chest']}]
[{'input': '9\r\n5 4 2 3 4 4 5 2 2\r\n', 'output': ['chest']}, {'input': '15\r\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17\r\n', 'output': ['back']}, {'input': '7\r\n3 3 2 7 9 6 8\r\n', 'output': ['chest']}, {'input': '17\r\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19\r\n', 'output': ['chest']}, {'input': '10\r\n1 9 20 18 20 17 7 24 23 2\r\n', 'output': ['back']}]
100
100
100
100
100
100
95.24
95.24
95.24
95.24
85.71
78.57
78.57
78.57
78.57
284
100
96.192
79.998
["6 3"]
The only line of the input contains two integers: n and k (1 ≀ n ≀ 109, 0 ≀ k ≀ n).
bdccf34b5a5ae13238c89a60814b9f86
import java.util.*; import java.io.*; import java.math.*; public class scorify{ public static void main(String[] args){ Scanner in=new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); System.out.print((n>k && k>0) ? 1 : 0 ); if(k!=n){ if(k>1) System.out.print(" " + ( ( (k>=(n/2)) ? n-k : ( (n>=k*3) ? k*2 : n-k ) ) ) ); if(k==1) System.out.print( ( n-k==1 ? (" " + 1) : (" "+2) ) ); if(k==0) System.out.print(" " + 0); }else{System.out.print(" " + 0);} } }
["1 3"]
Java
NoteIn the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3 and 5 were inhabited. In this case all other apartments: 2, 4 and 6 are good.
Print the minimum possible and the maximum possible number of apartments good for Maxim.
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.Maxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly k already inhabited apartments, but he doesn't know their indices yet.Find out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim.
[{"input": "6 3\r\n", "output": ["1 3"]}, {"input": "10 1\r\n", "output": ["1 2"]}, {"input": "10 9\r\n", "output": ["1 1"]}, {"input": "8 0\r\n", "output": ["0 0"]}, {"input": "8 8\r\n", "output": ["0 0"]}, {"input": "966871928 890926970\r\n", "output": ["1 75944958"]}, {"input": "20 2\r\n", "output": ["1 4"]}, {"input": "1 0\r\n", "output": ["0 0"]}, {"input": "1 1\r\n", "output": ["0 0"]}, {"input": "2 0\r\n", "output": ["0 0"]}, {"input": "2 1\r\n", "output": ["1 1"]}, {"input": "2 2\r\n", "output": ["0 0"]}, {"input": "7 2\r\n", "output": ["1 4"]}, {"input": "8 3\r\n", "output": ["1 5"]}, {"input": "9 4\r\n", "output": ["1 5"]}, {"input": "10 3\r\n", "output": ["1 6"]}, {"input": "10 4\r\n", "output": ["1 6"]}, {"input": "10 5\r\n", "output": ["1 5"]}, {"input": "1000 1000\r\n", "output": ["0 0"]}, {"input": "1000 333\r\n", "output": ["1 666"]}, {"input": "1000 334\r\n", "output": ["1 666"]}, {"input": "999 333\r\n", "output": ["1 666"]}, {"input": "999 334\r\n", "output": ["1 665"]}, {"input": "998 332\r\n", "output": ["1 664"]}, {"input": "998 333\r\n", "output": ["1 665"]}, {"input": "89 4\r\n", "output": ["1 8"]}, {"input": "66 50\r\n", "output": ["1 16"]}, {"input": "88 15\r\n", "output": ["1 30"]}, {"input": "95 43\r\n", "output": ["1 52"]}, {"input": "900 344\r\n", "output": ["1 556"]}, {"input": "777 113\r\n", "output": ["1 226"]}, {"input": "964 42\r\n", "output": ["1 84"]}, {"input": "982 867\r\n", "output": ["1 115"]}, {"input": "1000000000 0\r\n", "output": ["0 0"]}, {"input": "1000000000 1000000000\r\n", "output": ["0 0"]}, {"input": "1000000000 333333333\r\n", "output": ["1 666666666"]}, {"input": "1000000000 333333334\r\n", "output": ["1 666666666"]}, {"input": "999999999 333333333\r\n", "output": ["1 666666666"]}, {"input": "999999999 333333334\r\n", "output": ["1 666666665"]}, {"input": "999999998 333333332\r\n", "output": ["1 666666664"]}, {"input": "999999998 333333333\r\n", "output": ["1 666666665"]}, {"input": "78602604 42160832\r\n", "output": ["1 36441772"]}, {"input": "35679021 9137902\r\n", "output": ["1 18275804"]}, {"input": "41949373 13173511\r\n", "output": ["1 26347022"]}, {"input": "77855558 49163875\r\n", "output": ["1 28691683"]}, {"input": "87187123 2851901\r\n", "output": ["1 5703802"]}, {"input": "66849627 25004217\r\n", "output": ["1 41845410"]}, {"input": "873046672 517064947\r\n", "output": ["1 355981725"]}, {"input": "639857373 1393427\r\n", "output": ["1 2786854"]}, {"input": "637563683 69636269\r\n", "output": ["1 139272538"]}, {"input": "911669737 141068293\r\n", "output": ["1 282136586"]}, {"input": "547575919 313272818\r\n", "output": ["1 234303101"]}, {"input": "955020006 297895809\r\n", "output": ["1 595791618"]}, {"input": "11 3\r\n", "output": ["1 6"]}, {"input": "4 1\r\n", "output": ["1 2"]}, {"input": "9 3\r\n", "output": ["1 6"]}, {"input": "7 3\r\n", "output": ["1 4"]}, {"input": "12 5\r\n", "output": ["1 7"]}, {"input": "1000 8\r\n", "output": ["1 16"]}]
100
100
100
[{'input': '1000000000 1000000000\r\n', 'output': ['0 0']}, {'input': '982 867\r\n', 'output': ['1 115']}, {'input': '1000000000 0\r\n', 'output': ['0 0']}, {'input': '998 333\r\n', 'output': ['1 665']}, {'input': '8 0\r\n', 'output': ['0 0']}]
[{'input': '9 4\r\n', 'output': ['1 5']}, {'input': '1000000000 1000000000\r\n', 'output': ['0 0']}, {'input': '2 1\r\n', 'output': ['1 1']}, {'input': '4 1\r\n', 'output': ['1 2']}, {'input': '10 3\r\n', 'output': ['1 6']}]
[{'input': '35679021 9137902\r\n', 'output': ['1 18275804']}, {'input': '2 0\r\n', 'output': ['0 0']}, {'input': '2 2\r\n', 'output': ['0 0']}, {'input': '89 4\r\n', 'output': ['1 8']}, {'input': '8 0\r\n', 'output': ['0 0']}]
[{'input': '777 113\r\n', 'output': ['1 226']}, {'input': '1000000000 1000000000\r\n', 'output': ['0 0']}, {'input': '12 5\r\n', 'output': ['1 7']}, {'input': '999 333\r\n', 'output': ['1 666']}, {'input': '10 9\r\n', 'output': ['1 1']}]
[{'input': '6 3\r\n', 'output': ['1 3']}, {'input': '2 0\r\n', 'output': ['0 0']}, {'input': '966871928 890926970\r\n', 'output': ['1 75944958']}, {'input': '1000 333\r\n', 'output': ['1 666']}, {'input': '1000000000 0\r\n', 'output': ['0 0']}]
100
100
100
100
100
100
100
100
100
90
77.78
83.33
72.22
66.67
66.67
285
100
98
73.334
["5 3\nxyabd", "7 4\nproblem", "2 2\nab", "12 1\nabaabbaaabbb"]
The first line of input contains two integersΒ β€” $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 50$$$) – the number of available stages and the number of stages to use in the rocket. The second line contains string $$$s$$$, which consists of exactly $$$n$$$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once.
56b13d313afef9dc6c6ba2758b5ea313
import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); String s[] = br.readLine().split(" "); int n = Integer.parseInt(s[0]); int k = Integer.parseInt(s[1]); char d[] = br.readLine().toCharArray(); Arrays.sort(d); int ans = Integer.MAX_VALUE; for(int i = 0; i<n;i++){ int c = d[i]-'a'+1, p = 1; char ul = d[i]; for(int j = i+1; j<n && p<k;j++){ if(d[j]-ul>=2){ ul = d[j]; p++; c+=d[j]-'a'+1; } if(p==k){ break; } } if(p==k){ ans = Math.min(ans,c); } } out.println(ans==Integer.MAX_VALUE?-1:ans); out.close(); } }
["29", "34", "-1", "1"]
Java
NoteIn the first example, the following rockets satisfy the condition: "adx" (weight is $$$1+4+24=29$$$); "ady" (weight is $$$1+4+25=30$$$); "bdx" (weight is $$$2+4+24=30$$$); "bdy" (weight is $$$2+4+25=31$$$).Rocket "adx" has the minimal weight, so the answer is $$$29$$$.In the second example, target rocket is "belo". Its weight is $$$2+5+12+15=34$$$.In the third example, $$$n=k=2$$$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1.
Print a single integerΒ β€” the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the stringΒ β€” concatenation of letters, which correspond to the stages.There are $$$n$$$ stages available. The rocket must contain exactly $$$k$$$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z'Β β€” $$$26$$$ tons.Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once.
[{"input": "5 3\r\nxyabd\r\n", "output": ["29"]}, {"input": "7 4\r\nproblem\r\n", "output": ["34"]}, {"input": "2 2\r\nab\r\n", "output": ["-1"]}, {"input": "12 1\r\nabaabbaaabbb\r\n", "output": ["1"]}, {"input": "50 13\r\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": ["169"]}, {"input": "50 14\r\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": ["-1"]}, {"input": "1 1\r\na\r\n", "output": ["1"]}, {"input": "50 1\r\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": ["1"]}, {"input": "50 2\r\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": ["-1"]}, {"input": "13 13\r\nuwgmkyqeiaocs\r\n", "output": ["169"]}, {"input": "13 13\r\nhzdxpbfvrltnj\r\n", "output": ["182"]}, {"input": "1 1\r\nn\r\n", "output": ["14"]}, {"input": "10 8\r\nsmzeblyjqw\r\n", "output": ["113"]}, {"input": "20 20\r\ntzmvhskkyugkuuxpvtbh\r\n", "output": ["-1"]}, {"input": "30 15\r\nwjzolzzkfulwgioksfxmcxmnnjtoav\r\n", "output": ["-1"]}, {"input": "40 30\r\nxumfrflllrrgswehqtsskefixhcxjrxbjmrpsshv\r\n", "output": ["-1"]}, {"input": "50 31\r\nahbyyoxltryqdmvenemaqnbakglgqolxnaifnqtoclnnqiabpz\r\n", "output": ["-1"]}, {"input": "10 7\r\niuiukrxcml\r\n", "output": ["99"]}, {"input": "38 2\r\nvjzarfykmrsrvwbwfwldsulhxtykmjbnwmdufa\r\n", "output": ["5"]}, {"input": "12 6\r\nfwseyrarkwcd\r\n", "output": ["61"]}, {"input": "2 2\r\nac\r\n", "output": ["4"]}, {"input": "1 1\r\nc\r\n", "output": ["3"]}, {"input": "2 2\r\nad\r\n", "output": ["5"]}, {"input": "2 1\r\nac\r\n", "output": ["1"]}, {"input": "4 3\r\nadjz\r\n", "output": ["15"]}, {"input": "3 3\r\naoz\r\n", "output": ["42"]}, {"input": "3 1\r\nzzz\r\n", "output": ["26"]}, {"input": "2 1\r\nxz\r\n", "output": ["24"]}, {"input": "5 1\r\naaddd\r\n", "output": ["1"]}]
100
100
100
[{'input': '2 2\r\nab\r\n', 'output': ['-1']}, {'input': '7 4\r\nproblem\r\n', 'output': ['34']}, {'input': '3 1\r\nzzz\r\n', 'output': ['26']}, {'input': '2 2\r\nad\r\n', 'output': ['5']}, {'input': '13 13\r\nuwgmkyqeiaocs\r\n', 'output': ['169']}]
[{'input': '50 13\r\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\r\n', 'output': ['169']}, {'input': '13 13\r\nhzdxpbfvrltnj\r\n', 'output': ['182']}, {'input': '2 2\r\nad\r\n', 'output': ['5']}, {'input': '10 8\r\nsmzeblyjqw\r\n', 'output': ['113']}, {'input': '50 1\r\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n', 'output': ['1']}]
[{'input': '10 8\r\nsmzeblyjqw\r\n', 'output': ['113']}, {'input': '38 2\r\nvjzarfykmrsrvwbwfwldsulhxtykmjbnwmdufa\r\n', 'output': ['5']}, {'input': '5 3\r\nxyabd\r\n', 'output': ['29']}, {'input': '2 1\r\nac\r\n', 'output': ['1']}, {'input': '40 30\r\nxumfrflllrrgswehqtsskefixhcxjrxbjmrpsshv\r\n', 'output': ['-1']}]
[{'input': '3 3\r\naoz\r\n', 'output': ['42']}, {'input': '50 31\r\nahbyyoxltryqdmvenemaqnbakglgqolxnaifnqtoclnnqiabpz\r\n', 'output': ['-1']}, {'input': '3 1\r\nzzz\r\n', 'output': ['26']}, {'input': '4 3\r\nadjz\r\n', 'output': ['15']}, {'input': '50 13\r\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\r\n', 'output': ['169']}]
[{'input': '2 2\r\nab\r\n', 'output': ['-1']}, {'input': '50 13\r\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\r\n', 'output': ['169']}, {'input': '1 1\r\nc\r\n', 'output': ['3']}, {'input': '50 14\r\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\r\n', 'output': ['-1']}, {'input': '50 1\r\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n', 'output': ['1']}]
100
100
100
100
100
100
100
100
100
100
100
92.86
100
100
100
286
100
100
98.572
["...QK...\n........\n........\n........\n........\n........\n........\n...rk...", "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR", "rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........"]
The input contains eight lines, eight characters each β€” the board's description. The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters. The white pieces are denoted as follows: the queen is represented is 'Q', the rook β€” as 'R', the bishop β€” as'B', the knight β€” as 'N', the pawn β€” as 'P', the king β€” as 'K'. The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively. An empty square of the board is marked as '.' (a dot). It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.
44bed0ca7a8fb42fb72c1584d39a4442
import java.io.*; import java.util.Scanner; public class codeforce519A { static PrintWriter out; static StreamTokenizer sin; static BufferedReader bin; static void setupOut() { out = new PrintWriter(System.out); } static void setupString() { bin = new BufferedReader(new InputStreamReader(System.in)); } public static void main(String[] args) throws IOException { setupOut(); setupString(); Scanner in = new Scanner(System.in); int x = 0; int y = 0; for (int i = 0; i < 8; i++) { String s = in.next(); for (int j = 0; j < 8; j++) { char c = s.charAt(j); if (c=='Q') x+=9; if (c=='R') x+=5; if (c=='B') x+=3; if (c=='N') x+=3; if (c=='P') x+=1; if (c=='q') y+=9; if (c=='r') y+=5; if (c=='n') y+=3; if (c=='p') y+=1; if (c=='b'){ y+=3; } } } if (x==y) out.print("Draw"); if (x>y) out.print("White"); if (x<y) out.print("Black"); out.flush(); } }
["White", "Draw", "Black"]
Java
NoteIn the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.In the second test sample the weights of the positions of the black and the white pieces are equal to 39.In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16.
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
A and B are preparing themselves for programming contests.To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.For each chess piece we know its weight: the queen's weight is 9, the rook's weight is 5, the bishop's weight is 3, the knight's weight is 3, the pawn's weight is 1, the king's weight isn't considered in evaluating position. The player's weight equals to the sum of weights of all his pieces on the board.As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
[{"input": "...QK...\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n...rk...\r\n", "output": ["White"]}, {"input": "rnbqkbnr\r\npppppppp\r\n........\r\n........\r\n........\r\n........\r\nPPPPPPPP\r\nRNBQKBNR\r\n", "output": ["Draw"]}, {"input": "rppppppr\r\n...k....\r\n........\r\n........\r\n........\r\n........\r\nK...Q...\r\n........\r\n", "output": ["Black"]}, {"input": "....bQ.K\r\n.B......\r\n.....P..\r\n........\r\n........\r\n........\r\n...N.P..\r\n.....R..\r\n", "output": ["White"]}, {"input": "b....p..\r\nR.......\r\n.pP...b.\r\npp......\r\nq.PPNpPR\r\n..K..rNn\r\nP.....p.\r\n...Q..B.\r\n", "output": ["White"]}, {"input": "...Nn...\r\n........\r\n........\r\n........\r\n.R....b.\r\n........\r\n........\r\n......p.\r\n", "output": ["White"]}, {"input": "...p..Kn\r\n.....Pq.\r\n.R.rN...\r\n...b.PPr\r\np....p.P\r\n...B....\r\np.b.....\r\n..N.....\r\n", "output": ["Black"]}, {"input": "q.......\r\nPPPPPPPP\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Black"]}, {"input": "q.......\r\nPPPPPPPP\r\nP.......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Draw"]}, {"input": "q.......\r\nPPPPPPPP\r\nPP......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["White"]}, {"input": "r.......\r\nPPPP....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Black"]}, {"input": "r.......\r\nPPPPP...\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Draw"]}, {"input": "r.......\r\nPPPPPP..\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["White"]}, {"input": "b.......\r\nPP......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Black"]}, {"input": "b.......\r\nPPP.....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Draw"]}, {"input": "b.......\r\nPPPP....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["White"]}, {"input": "n.......\r\nPP......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Black"]}, {"input": "n.......\r\nPPP.....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Draw"]}, {"input": "n.......\r\nPPPP....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["White"]}, {"input": "Q.......\r\npppppppp\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["White"]}, {"input": "Q.......\r\npppppppp\r\np.......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Draw"]}, {"input": "Q.......\r\npppppppp\r\npp......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Black"]}, {"input": "R.......\r\npppp....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["White"]}, {"input": "R.......\r\nppppp...\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Draw"]}, {"input": "R.......\r\npppppp..\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Black"]}, {"input": "B.......\r\npp......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["White"]}, {"input": "B.......\r\nppp.....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Draw"]}, {"input": "B.......\r\npppp....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Black"]}, {"input": "N.......\r\npp......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["White"]}, {"input": "N.......\r\nppp.....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Draw"]}, {"input": "N.......\r\npppp....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Black"]}, {"input": "qqqqqqqq\r\nqqqqqqqq\r\nqqqqqqqq\r\nqqqqqqqq\r\nqqqqqqqq\r\nqqqqqqqq\r\nqqqqqqqq\r\nqqqqqqqq\r\n", "output": ["Black"]}, {"input": "QQQQQQQQ\r\nQQQQQQQQ\r\nQQQQQQQQ\r\nQQQQQQQQ\r\nQQQQQQQQ\r\nQQQQQQQQ\r\nQQQQQQQQ\r\nQQQQQQQQ\r\n", "output": ["White"]}, {"input": "qqqqqqqq\r\nqqqqqqqq\r\nqqqqqqqq\r\nqqqqqqqq\r\nQQQQQQQQ\r\nQQQQQQQQ\r\nQQQQQQQQ\r\nQQQQQQQQ\r\n", "output": ["Draw"]}, {"input": "..KQBN..\r\n........\r\n........\r\n....q...\r\n..p.....\r\n....k...\r\n........\r\n........\r\n", "output": ["White"]}, {"input": "..K....Q\r\n........\r\n....q...\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Draw"]}, {"input": "KKKKKKK.\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\nq.......\r\n", "output": ["Black"]}, {"input": "QQQQQQQQ\r\nQQQQQQQQ\r\n........\r\n........\r\n........\r\n........\r\nrrrrrr..\r\nrrrrrrrr\r\n", "output": ["White"]}, {"input": "........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Draw"]}, {"input": "P.......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["White"]}, {"input": "...b....\r\n...np...\r\n........\r\n........\r\n........\r\n...N....\r\n...B....\r\n...R....\r\n", "output": ["White"]}, {"input": "........\r\n........\r\n........\r\n........\r\n........\r\n........\r\nNN......\r\n........\r\n", "output": ["White"]}, {"input": "........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n.......n\r\n", "output": ["Black"]}, {"input": "n.......\r\nn.......\r\nn.......\r\nn.......\r\nn.......\r\nn.......\r\nn.......\r\nn.......\r\n", "output": ["Black"]}, {"input": "NNNNNNNN\r\nNNNNNNNN\r\nNNNNNNNN\r\nNNNNNNNN\r\nNNNNNNNN\r\nNNNNNNNN\r\nKk......\r\nq.......\r\n", "output": ["White"]}, {"input": "........\r\nNN......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["White"]}, {"input": "K.......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Draw"]}, {"input": "Q.......\r\nkkk.....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["White"]}, {"input": "Kn......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Black"]}, {"input": "........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\nn.......\r\n", "output": ["Black"]}, {"input": "KKKKKKKK\r\npppppppp\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Black"]}, {"input": "........\r\n...b....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n.......K\r\n", "output": ["Black"]}, {"input": "........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n......Kp\r\n", "output": ["Black"]}, {"input": "........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n.......Q\r\n", "output": ["White"]}, {"input": "........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n......Bp\r\n", "output": ["White"]}, {"input": "...k....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n...P....\r\n", "output": ["White"]}, {"input": "........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\nkkkkkB..\r\n", "output": ["White"]}, {"input": "....K...\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n...p....\r\n", "output": ["Black"]}, {"input": "PPPPPPP.\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\nq.......\r\n", "output": ["Black"]}, {"input": "Kb......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["Black"]}, {"input": "N.......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n", "output": ["White"]}, {"input": "QqPQNN.Q\r\n.qBbr.qB\r\np.RKBpNK\r\nPknBr.nq\r\nKqKRNKKk\r\n.BqPqkb.\r\nPBNPr.rk\r\nBpBKrPRR\r\n", "output": ["Black"]}, {"input": "....K...\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n...Kk...\r\n", "output": ["Draw"]}, {"input": "........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n.......K\r\n", "output": ["Draw"]}, {"input": "...Rp...\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n...r....\r\n", "output": ["Black"]}]
100
100
100
[{'input': '........\r\n........\r\n........\r\n........\r\n........\r\n........\r\nNN......\r\n........\r\n', 'output': ['White']}, {'input': 'b.......\r\nPP......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n', 'output': ['Black']}, {'input': '...QK...\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n...rk...\r\n', 'output': ['White']}, {'input': 'KKKKKKKK\r\npppppppp\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n', 'output': ['Black']}, {'input': '....K...\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n...p....\r\n', 'output': ['Black']}]
[{'input': 'Q.......\r\nkkk.....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n', 'output': ['White']}, {'input': 'rppppppr\r\n...k....\r\n........\r\n........\r\n........\r\n........\r\nK...Q...\r\n........\r\n', 'output': ['Black']}, {'input': 'b.......\r\nPP......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n', 'output': ['Black']}, {'input': 'q.......\r\nPPPPPPPP\r\nPP......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n', 'output': ['White']}, {'input': '........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n.......n\r\n', 'output': ['Black']}]
[{'input': '........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\nkkkkkB..\r\n', 'output': ['White']}, {'input': 'b.......\r\nPPPP....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n', 'output': ['White']}, {'input': '........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n.......n\r\n', 'output': ['Black']}, {'input': 'QQQQQQQQ\r\nQQQQQQQQ\r\n........\r\n........\r\n........\r\n........\r\nrrrrrr..\r\nrrrrrrrr\r\n', 'output': ['White']}, {'input': 'Q.......\r\npppppppp\r\npp......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n', 'output': ['Black']}]
[{'input': 'q.......\r\nPPPPPPPP\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n', 'output': ['Black']}, {'input': '........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n.......K\r\n', 'output': ['Draw']}, {'input': 'N.......\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n', 'output': ['White']}, {'input': 'QQQQQQQQ\r\nQQQQQQQQ\r\n........\r\n........\r\n........\r\n........\r\nrrrrrr..\r\nrrrrrrrr\r\n', 'output': ['White']}, {'input': '..K....Q\r\n........\r\n....q...\r\n........\r\n........\r\n........\r\n........\r\n........\r\n', 'output': ['Draw']}]
[{'input': 'n.......\r\nPPPP....\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n', 'output': ['White']}, {'input': '........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n......Bp\r\n', 'output': ['White']}, {'input': 'r.......\r\nPPPPP...\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n', 'output': ['Draw']}, {'input': '........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n......Kp\r\n', 'output': ['Black']}, {'input': 'KKKKKKKK\r\npppppppp\r\n........\r\n........\r\n........\r\n........\r\n........\r\n........\r\n', 'output': ['Black']}]
100
100
100
100
100
87.8
90.24
90.24
87.8
87.8
83.33
86.67
86.67
83.33
83.33
287
100
88.776
84.666
["9", "7"]
The first line contains an integer n (1 ≀ n ≀ 106) β€” the n mentioned in the statement.
25e5afcdf246ee35c9cef2fcbdd4566e
import java.io.*; import java.util.*; public class A { public static void solution(BufferedReader reader, PrintWriter out) throws IOException { In in = new In(reader); int n = in.nextInt(); long max = 1; for (int a = Math.max(1, n - 100); a <= n; a++) for (int b = Math.max(1, n - 100); b <= n; b++) for (int c = Math.max(1, n - 100); c <= n; c++) max = Math.max(max, lcm(a, lcm(b, c))); out.println(max); } private static long lcm(long a, long b) { long gcd = gcd(a, b); return a / gcd * b; } private static long gcd(long a, long b) { while (b != 0) { long t = b; b = a % b; a = t; } return a; } public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader( new InputStreamReader(System.in)); PrintWriter out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out))); solution(reader, out); out.close(); } protected static class In { private BufferedReader reader; private StringTokenizer tokenizer = new StringTokenizer(""); public In(BufferedReader reader) { this.reader = reader; } public String next() throws IOException { while (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine()); return tokenizer.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } } }
["504", "210"]
Java
NoteThe least common multiple of some positive integers is the least positive integer which is multiple for each of them.The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7Β·6Β·5 = 210. It is the maximum value we can get.
Print a single integer β€” the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?
[{"input": "9\r\n", "output": ["504"]}, {"input": "7\r\n", "output": ["210"]}, {"input": "1\r\n", "output": ["1"]}, {"input": "5\r\n", "output": ["60"]}, {"input": "6\r\n", "output": ["60"]}, {"input": "33\r\n", "output": ["32736"]}, {"input": "21\r\n", "output": ["7980"]}, {"input": "2\r\n", "output": ["2"]}, {"input": "41\r\n", "output": ["63960"]}, {"input": "29\r\n", "output": ["21924"]}, {"input": "117\r\n", "output": ["1560780"]}, {"input": "149\r\n", "output": ["3241644"]}, {"input": "733\r\n", "output": ["392222436"]}, {"input": "925\r\n", "output": ["788888100"]}, {"input": "509\r\n", "output": ["131096004"]}, {"input": "829\r\n", "output": ["567662724"]}, {"input": "605\r\n", "output": ["220348260"]}, {"input": "245\r\n", "output": ["14526540"]}, {"input": "213\r\n", "output": ["9527916"]}, {"input": "53\r\n", "output": ["140556"]}, {"input": "341\r\n", "output": ["39303660"]}, {"input": "924\r\n", "output": ["783776526"]}, {"input": "508\r\n", "output": ["130065780"]}, {"input": "700\r\n", "output": ["341042100"]}, {"input": "636\r\n", "output": ["254839470"]}, {"input": "20\r\n", "output": ["6460"]}, {"input": "604\r\n", "output": ["218891412"]}, {"input": "796\r\n", "output": ["501826260"]}, {"input": "732\r\n", "output": ["389016270"]}, {"input": "412\r\n", "output": ["69256788"]}, {"input": "244\r\n", "output": ["14289372"]}, {"input": "828\r\n", "output": ["563559150"]}, {"input": "116\r\n", "output": ["1507420"]}, {"input": "148\r\n", "output": ["3154620"]}, {"input": "763116\r\n", "output": ["444394078546562430"]}, {"input": "756604\r\n", "output": ["433115377058855412"]}, {"input": "447244\r\n", "output": ["89460162932862372"]}, {"input": "372636\r\n", "output": ["51742503205363470"]}, {"input": "546924\r\n", "output": ["163597318076822526"]}, {"input": "540412\r\n", "output": ["157823524476316788"]}, {"input": "714700\r\n", "output": ["365063922340784100"]}, {"input": "520731\r\n", "output": ["141201007712496270"]}, {"input": "695019\r\n", "output": ["335728459024850814"]}, {"input": "688507\r\n", "output": ["326379736779169710"]}, {"input": "862795\r\n", "output": ["642275489615199390"]}, {"input": "668827\r\n", "output": ["299184742915995150"]}, {"input": "810411\r\n", "output": ["532248411551110590"]}, {"input": "836603\r\n", "output": ["585540171302562606"]}, {"input": "978187\r\n", "output": ["935975171582120670"]}, {"input": "816923\r\n", "output": ["545182335484592526"]}, {"input": "958507\r\n", "output": ["880611813728059710"]}, {"input": "984699\r\n", "output": ["954792870629291694"]}, {"input": "642635\r\n", "output": ["265393998349453470"]}, {"input": "296604\r\n", "output": ["26092892528622606"]}, {"input": "1000000\r\n", "output": ["999996000003000000"]}, {"input": "8\r\n", "output": ["280"]}, {"input": "3\r\n", "output": ["6"]}, {"input": "4\r\n", "output": ["12"]}, {"input": "30\r\n", "output": ["21924"]}, {"input": "18\r\n", "output": ["4080"]}, {"input": "12\r\n", "output": ["990"]}]
100
100
100
[{'input': '29\r\n', 'output': ['21924']}, {'input': '816923\r\n', 'output': ['545182335484592526']}, {'input': '20\r\n', 'output': ['6460']}, {'input': '520731\r\n', 'output': ['141201007712496270']}, {'input': '636\r\n', 'output': ['254839470']}]
[{'input': '341\r\n', 'output': ['39303660']}, {'input': '30\r\n', 'output': ['21924']}, {'input': '688507\r\n', 'output': ['326379736779169710']}, {'input': '829\r\n', 'output': ['567662724']}, {'input': '12\r\n', 'output': ['990']}]
[{'input': '7\r\n', 'output': ['210']}, {'input': '829\r\n', 'output': ['567662724']}, {'input': '796\r\n', 'output': ['501826260']}, {'input': '12\r\n', 'output': ['990']}, {'input': '836603\r\n', 'output': ['585540171302562606']}]
[{'input': '3\r\n', 'output': ['6']}, {'input': '816923\r\n', 'output': ['545182335484592526']}, {'input': '605\r\n', 'output': ['220348260']}, {'input': '245\r\n', 'output': ['14526540']}, {'input': '732\r\n', 'output': ['389016270']}]
[{'input': '816923\r\n', 'output': ['545182335484592526']}, {'input': '9\r\n', 'output': ['504']}, {'input': '30\r\n', 'output': ['21924']}, {'input': '642635\r\n', 'output': ['265393998349453470']}, {'input': '763116\r\n', 'output': ['444394078546562430']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
288
100
100
100
["3 4 11\n1 2 3 4", "5 5 10\n1 2 4 8 16"]
The first line contains three integer numbers n, k and M (1 ≀ n ≀ 45, 1 ≀ k ≀ 45, 0 ≀ M ≀ 2Β·109). The second line contains k integer numbers, values tj (1 ≀ tj ≀ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
d659e92a410c1bc836be64fc1c0db160
import java.util.Arrays; import java.util.Scanner; public class Mathshow1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); int n = input.nextInt(); int k = input.nextInt(); int m = input.nextInt(); int[] arr = new int[k]; int total=0; for(int i=0; i<k;i++){ arr[i] = input.nextInt(); total+=arr[i]; } int max=-1; Arrays.sort(arr); for(int i=0; i<=n;i++){ int points = i*(k+1); long rem = m-i*total; if(rem <0 )continue; for(int j=0; j<k;j++){ int picks = Math.min(n-i,(int)rem/arr[j]); if(picks==0){ break; } points+=picks; rem-=picks*arr[j]; } max = Math.max(points,max); } System.out.println(max); } }
["6", "7"]
Java
NoteIn the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.In the second example Polycarp can solve the first subtask of all five tasks and spend 5Β·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2Β·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.
Print the maximum amount of points Polycarp can earn in M minutes.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.Polycarp has M minutes of time. What is the maximum number of points he can earn?
[{"input": "3 4 11\r\n1 2 3 4\r\n", "output": ["6"]}, {"input": "5 5 10\r\n1 2 4 8 16\r\n", "output": ["7"]}, {"input": "1 1 0\r\n2\r\n", "output": ["0"]}, {"input": "1 1 1\r\n1\r\n", "output": ["2"]}, {"input": "2 1 0\r\n2\r\n", "output": ["0"]}, {"input": "2 2 2\r\n2 3\r\n", "output": ["1"]}, {"input": "4 2 15\r\n1 4\r\n", "output": ["9"]}, {"input": "24 42 126319796\r\n318996 157487 174813 189765 259136 406743 138997 377982 244813 16862 95438 346702 454882 274633 67361 387756 61951 448901 427272 288847 316578 416035 56608 211390 187241 191538 299856 294995 442139 95784 410894 439744 455044 301002 196932 352004 343622 73438 325186 295727 21130 32856\r\n", "output": ["677"]}, {"input": "5 3 10\r\n1 3 6\r\n", "output": ["6"]}, {"input": "5 3 50\r\n1 3 6\r\n", "output": ["20"]}, {"input": "5 3 2000000000\r\n1 3 6\r\n", "output": ["20"]}, {"input": "5 3 49\r\n1 3 6\r\n", "output": ["18"]}, {"input": "3 4 16\r\n1 2 3 4\r\n", "output": ["9"]}, {"input": "11 2 20\r\n1 9\r\n", "output": ["13"]}, {"input": "11 3 38\r\n1 9 9\r\n", "output": ["15"]}, {"input": "5 3 11\r\n1 1 2\r\n", "output": ["11"]}, {"input": "5 4 36\r\n1 3 7 7\r\n", "output": ["13"]}, {"input": "1 13 878179\r\n103865 43598 180009 528483 409585 449955 368163 381135 713512 645876 241515 20336 572091\r\n", "output": ["5"]}, {"input": "1 9 262522\r\n500878 36121 420012 341288 139726 362770 462113 261122 394426\r\n", "output": ["2"]}, {"input": "45 32 252252766\r\n282963 74899 446159 159106 469932 288063 297289 501442 241341 240108 470371 316076 159136 72720 37365 108455 82789 529789 303825 392553 153053 389577 327929 277446 505280 494678 159006 505007 328366 460640 18354 313300\r\n", "output": ["1094"]}, {"input": "44 41 93891122\r\n447 314862 48587 198466 73450 166523 247421 50078 14115 229926 11070 53089 73041 156924 200782 53225 290967 219349 119034 88726 255048 59778 287298 152539 55104 170525 135722 111341 279873 168400 267489 157697 188015 94306 231121 304553 27684 46144 127122 166022 150941\r\n", "output": ["1084"]}, {"input": "12 45 2290987\r\n50912 189025 5162 252398 298767 154151 164139 185891 121047 227693 93549 284244 312843 313833 285436 131672 135248 324541 194905 205729 241315 32044 131902 305884 263 27717 173077 81428 285684 66470 220938 282471 234921 316283 30485 244283 170631 224579 72899 87066 6727 161661 40556 89162 314616\r\n", "output": ["95"]}, {"input": "42 9 4354122\r\n47443 52983 104606 84278 5720 55971 100555 90845 91972\r\n", "output": ["124"]}, {"input": "45 28 33631968\r\n5905 17124 64898 40912 75855 53868 27056 18284 63975 51975 27182 94373 52477 260 87551 50223 73798 77430 17510 15226 6269 43301 39592 27043 15546 60047 83400 63983\r\n", "output": ["979"]}, {"input": "18 3 36895\r\n877 2054 4051\r\n", "output": ["28"]}, {"input": "13 30 357\r\n427 117 52 140 162 58 5 149 438 327 103 357 202 1 148 238 442 200 438 97 414 301 224 166 254 322 378 422 90 312\r\n", "output": ["31"]}, {"input": "44 11 136\r\n77 38 12 71 81 15 66 47 29 22 71\r\n", "output": ["11"]}, {"input": "32 6 635\r\n3 4 2 1 7 7\r\n", "output": ["195"]}, {"input": "30 19 420\r\n2 2 1 2 2 1 1 2 1 2 2 2 1 2 2 2 2 1 2\r\n", "output": ["309"]}, {"input": "37 40 116\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["118"]}, {"input": "7 37 133\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["136"]}, {"input": "40 1 8\r\n3\r\n", "output": ["4"]}, {"input": "1 28 1\r\n3 3 2 2 1 1 3 1 1 2 2 1 1 3 3 1 1 1 1 1 3 1 3 3 3 2 2 3\r\n", "output": ["1"]}, {"input": "12 1 710092\r\n145588\r\n", "output": ["8"]}, {"input": "1 7 47793\r\n72277 45271 85507 39251 45440 101022 105165\r\n", "output": ["1"]}, {"input": "1 1 0\r\n4\r\n", "output": ["0"]}, {"input": "1 2 3\r\n2 2\r\n", "output": ["1"]}, {"input": "1 1 0\r\n5\r\n", "output": ["0"]}, {"input": "1 1 3\r\n5\r\n", "output": ["0"]}, {"input": "1 3 0\r\n6 3 4\r\n", "output": ["0"]}, {"input": "1 2 0\r\n1 2\r\n", "output": ["0"]}, {"input": "2 2 3\r\n7 2\r\n", "output": ["1"]}, {"input": "2 4 5\r\n1 2 8 6\r\n", "output": ["3"]}, {"input": "2 1 0\r\n3\r\n", "output": ["0"]}, {"input": "1 3 3\r\n16 4 5\r\n", "output": ["0"]}, {"input": "2 1 0\r\n1\r\n", "output": ["0"]}, {"input": "3 2 2\r\n6 1\r\n", "output": ["2"]}, {"input": "3 2 1\r\n1 1\r\n", "output": ["1"]}, {"input": "1 3 19\r\n12 15 6\r\n", "output": ["2"]}, {"input": "2 2 8\r\n12 1\r\n", "output": ["2"]}, {"input": "1 6 14\r\n15 2 6 13 14 4\r\n", "output": ["3"]}, {"input": "4 1 0\r\n1\r\n", "output": ["0"]}, {"input": "2 2 5\r\n5 6\r\n", "output": ["1"]}, {"input": "1 3 8\r\n5 4 4\r\n", "output": ["2"]}, {"input": "1 5 44\r\n2 19 18 6 8\r\n", "output": ["4"]}, {"input": "3 2 7\r\n5 1\r\n", "output": ["4"]}, {"input": "4 2 9\r\n8 6\r\n", "output": ["1"]}, {"input": "4 3 3\r\n6 12 7\r\n", "output": ["0"]}, {"input": "4 1 2\r\n1\r\n", "output": ["4"]}, {"input": "2 4 15\r\n8 3 7 8\r\n", "output": ["3"]}, {"input": "6 1 2\r\n4\r\n", "output": ["0"]}, {"input": "2 1 1\r\n1\r\n", "output": ["2"]}, {"input": "1 1 2\r\n3\r\n", "output": ["0"]}, {"input": "2 2 2\r\n1 4\r\n", "output": ["2"]}, {"input": "6 2 78\r\n12 10\r\n", "output": ["10"]}, {"input": "1 3 10\r\n17 22 15\r\n", "output": ["0"]}, {"input": "6 3 13\r\n1 2 3\r\n", "output": ["10"]}, {"input": "21 3 26\r\n1 2 3\r\n", "output": ["24"]}, {"input": "3 7 20012\r\n1 1 1 1 1 1 10000\r\n", "output": ["20"]}, {"input": "5 4 40\r\n4 2 3 3\r\n", "output": ["17"]}, {"input": "4 5 40\r\n4 1 3 2 4\r\n", "output": ["18"]}, {"input": "3 5 22\r\n1 1 4 1 1\r\n", "output": ["16"]}, {"input": "5 2 17\r\n3 4\r\n", "output": ["7"]}, {"input": "5 4 32\r\n4 2 1 1\r\n", "output": ["21"]}, {"input": "5 5 34\r\n4 1 1 2 4\r\n", "output": ["20"]}, {"input": "3 3 15\r\n1 2 1\r\n", "output": ["12"]}, {"input": "3 2 11\r\n1 2\r\n", "output": ["9"]}, {"input": "5 4 11\r\n2 1 3 4\r\n", "output": ["8"]}, {"input": "45 45 2000000000\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["2070"]}]
100
100
100
[{'input': '5 4 11\r\n2 1 3 4\r\n', 'output': ['8']}, {'input': '6 1 2\r\n4\r\n', 'output': ['0']}, {'input': '18 3 36895\r\n877 2054 4051\r\n', 'output': ['28']}, {'input': '4 2 15\r\n1 4\r\n', 'output': ['9']}, {'input': '1 5 44\r\n2 19 18 6 8\r\n', 'output': ['4']}]
[{'input': '1 1 1\r\n1\r\n', 'output': ['2']}, {'input': '2 2 8\r\n12 1\r\n', 'output': ['2']}, {'input': '5 3 2000000000\r\n1 3 6\r\n', 'output': ['20']}, {'input': '11 2 20\r\n1 9\r\n', 'output': ['13']}, {'input': '5 3 49\r\n1 3 6\r\n', 'output': ['18']}]
[{'input': '2 1 0\r\n1\r\n', 'output': ['0']}, {'input': '3 4 11\r\n1 2 3 4\r\n', 'output': ['6']}, {'input': '45 28 33631968\r\n5905 17124 64898 40912 75855 53868 27056 18284 63975 51975 27182 94373 52477 260 87551 50223 73798 77430 17510 15226 6269 43301 39592 27043 15546 60047 83400 63983\r\n', 'output': ['979']}, {'input': '1 5 44\r\n2 19 18 6 8\r\n', 'output': ['4']}, {'input': '3 4 16\r\n1 2 3 4\r\n', 'output': ['9']}]
[{'input': '1 13 878179\r\n103865 43598 180009 528483 409585 449955 368163 381135 713512 645876 241515 20336 572091\r\n', 'output': ['5']}, {'input': '11 3 38\r\n1 9 9\r\n', 'output': ['15']}, {'input': '1 1 0\r\n2\r\n', 'output': ['0']}, {'input': '3 2 1\r\n1 1\r\n', 'output': ['1']}, {'input': '1 1 2\r\n3\r\n', 'output': ['0']}]
[{'input': '2 4 15\r\n8 3 7 8\r\n', 'output': ['3']}, {'input': '5 4 11\r\n2 1 3 4\r\n', 'output': ['8']}, {'input': '40 1 8\r\n3\r\n', 'output': ['4']}, {'input': '5 3 11\r\n1 1 2\r\n', 'output': ['11']}, {'input': '2 1 1\r\n1\r\n', 'output': ['2']}]
100
100
100
100
100
100
100
100
100
100
100
100
90
90
100
289
100
100
96
["1 3 8 1 1", "4 2 9 4 2", "5 5 25 4 3", "100 100 1000000000000000000 100 100"]
The first and the only line contains five integers n, m, k, x and y (1 ≀ n, m ≀ 100, 1 ≀ k ≀ 1018, 1 ≀ x ≀ n, 1 ≀ y ≀ m).
e61debcad37eaa9a6e21d7a2122b8b21
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); long k = in.nextLong(); int x = in.nextInt(); int y = in.nextInt(); long grid[][] = new long[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (k > 0) { grid[i][j] = 1; k--; } } } if (k > 0 && n != 1) { long mid = (k / (m * n - m)); boolean isUp = (k / (m * n - m)) % 2 == 0; long topRow = (k / (m * n - m)) / 2 + (!isUp ? 1 : 0); long bottomRow = ((k / (m * n - m)) / 2); long remK = (k % (m * n - m)); for (int i = 0; i < grid.length; i++) { for (int j = 0; j < grid[0].length; j++) { if (i == 0) { grid[i][j] += topRow; } else if (i == n - 1) { grid[i][j] += bottomRow; } else { grid[i][j] += mid; } } } for (int i = isUp ? n - 2 : 1; i >= 0 && i < n; i += isUp ? -1 : 1) { for (int j = 0; j < m; j++) { if (remK > 0) { grid[i][j] += 1; remK--; } else { break; } } } } else if (n == 1) { for (int i = 0; i < m; i++) { grid[0][i] += k / m; } k = k % m; for (int i = 0; i < m; i++) { if (k > 0) { grid[0][i] += 1; k--; } } } long max = Long.MIN_VALUE; long min = Long.MAX_VALUE; for (long column[] : grid) { for (long cell : column) { max = Math.max(max, cell); min = Math.min(min, cell); } } out.println(max + " " + min + " " + grid[x - 1][y - 1]); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int 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 long readLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int nextInt() { return readInt(); } public long nextLong() { return readLong(); } } }
["3 2 3", "2 1 1", "1 1 1", "101010101010101 50505050505051 50505050505051"]
Java
NoteThe order of asking pupils in the first test: the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; The order of asking pupils in the second test: the pupil from the first row who seats at the first table; the pupil from the first row who seats at the second table; the pupil from the second row who seats at the first table; the pupil from the second row who seats at the second table; the pupil from the third row who seats at the first table; the pupil from the third row who seats at the second table; the pupil from the fourth row who seats at the first table; the pupil from the fourth row who seats at the second table, it means it is Sergei; the pupil from the third row who seats at the first table;
Print three integers: the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei.
On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.Seating in the class looks like a rectangle, where n rows with m pupils in each. The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil.During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values: the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei. If there is only one row in the class, then the teacher always asks children from this row.
[{"input": "1 3 8 1 1\r\n", "output": ["3 2 3", "3 2 3"]}, {"input": "4 2 9 4 2\r\n", "output": ["2 1 1"]}, {"input": "5 5 25 4 3\r\n", "output": ["1 1 1"]}, {"input": "100 100 1000000000000000000 100 100\r\n", "output": ["101010101010101 50505050505051 50505050505051"]}, {"input": "3 2 15 2 2\r\n", "output": ["4 2 3"]}, {"input": "4 1 8 3 1\r\n", "output": ["3 1 2"]}, {"input": "3 2 8 2 1\r\n", "output": ["2 1 2"]}, {"input": "4 2 9 4 1\r\n", "output": ["2 1 1"]}, {"input": "1 3 7 1 1\r\n", "output": ["3 2 3", "3 2 3"]}, {"input": "2 2 8 2 1\r\n", "output": ["2 2 2"]}, {"input": "3 1 6 2 1\r\n", "output": ["3 1 3"]}, {"input": "5 6 30 5 4\r\n", "output": ["1 1 1"]}, {"input": "3 8 134010 3 4\r\n", "output": ["8376 4188 4188"]}, {"input": "10 10 25 5 1\r\n", "output": ["1 0 0"]}, {"input": "100 100 1000000000 16 32\r\n", "output": ["101011 50505 101010"]}, {"input": "100 100 1 23 39\r\n", "output": ["1 0 0"]}, {"input": "1 1 1000000000 1 1\r\n", "output": ["1000000000 1000000000 1000000000", "1000000000 1000000000 1000000000"]}, {"input": "1 1 1 1 1\r\n", "output": ["1 1 1", "1 1 1"]}, {"input": "47 39 1772512 1 37\r\n", "output": ["989 494 495"]}, {"input": "37 61 421692 24 49\r\n", "output": ["192 96 192"]}, {"input": "89 97 875341288 89 96\r\n", "output": ["102547 51273 51274"]}, {"input": "100 1 1000000000000 100 1\r\n", "output": ["10101010101 5050505051 5050505051"]}, {"input": "1 100 1000000000000 1 100\r\n", "output": ["10000000000 10000000000 10000000000", "10000000000 10000000000 10000000000"]}, {"input": "2 4 6 1 4\r\n", "output": ["1 0 1"]}, {"input": "2 4 6 1 3\r\n", "output": ["1 0 1"]}, {"input": "2 4 49 1 1\r\n", "output": ["7 6 7"]}, {"input": "3 3 26 1 1\r\n", "output": ["4 2 3"]}, {"input": "5 2 77 4 2\r\n", "output": ["10 5 10"]}, {"input": "2 5 73 2 3\r\n", "output": ["8 7 7"]}, {"input": "5 2 81 5 1\r\n", "output": ["10 5 5"]}, {"input": "4 5 93 1 2\r\n", "output": ["6 3 4"]}, {"input": "4 4 74 4 1\r\n", "output": ["6 3 3"]}, {"input": "5 3 47 2 1\r\n", "output": ["4 2 4"]}, {"input": "5 4 61 1 1\r\n", "output": ["4 2 2"]}, {"input": "4 4 95 1 1\r\n", "output": ["8 4 4"]}, {"input": "2 5 36 1 3\r\n", "output": ["4 3 4"]}, {"input": "5 2 9 5 1\r\n", "output": ["1 0 1"]}, {"input": "4 1 50 1 1\r\n", "output": ["17 8 9"]}, {"input": "3 2 83 1 2\r\n", "output": ["21 10 11"]}, {"input": "3 5 88 1 5\r\n", "output": ["9 4 5"]}, {"input": "4 2 89 1 2\r\n", "output": ["15 7 8"]}, {"input": "2 1 1 1 1\r\n", "output": ["1 0 1"]}, {"input": "5 3 100 2 1\r\n", "output": ["9 4 9"]}, {"input": "4 4 53 3 1\r\n", "output": ["5 2 4"]}, {"input": "4 3 1 3 3\r\n", "output": ["1 0 0"]}, {"input": "3 5 1 2 1\r\n", "output": ["1 0 0"]}, {"input": "5 2 2 4 1\r\n", "output": ["1 0 0"]}, {"input": "3 3 1 3 2\r\n", "output": ["1 0 0"]}, {"input": "1 1 100 1 1\r\n", "output": ["100 100 100", "100 100 100"]}, {"input": "4 30 766048376 1 23\r\n", "output": ["8511649 4255824 4255825"]}, {"input": "3 90 675733187 1 33\r\n", "output": ["3754073 1877036 1877037"]}, {"input": "11 82 414861345 1 24\r\n", "output": ["505929 252964 252965"]}, {"input": "92 10 551902461 1 6\r\n", "output": ["606487 303243 303244"]}, {"input": "18 83 706805205 1 17\r\n", "output": ["500925 250462 250463"]}, {"input": "1 12 943872212 1 1\r\n", "output": ["78656018 78656017 78656018", "78656018 78656017 78656018"]}, {"input": "91 15 237966754 78 6\r\n", "output": ["176272 88136 176272"]}, {"input": "58 66 199707458 15 9\r\n", "output": ["53086 26543 53085"]}, {"input": "27 34 77794947 24 4\r\n", "output": ["88004 44002 88004"]}, {"input": "22 89 981099971 16 48\r\n", "output": ["524934 262467 524933"]}, {"input": "10 44 222787770 9 25\r\n", "output": ["562596 281298 562596"]}, {"input": "9 64 756016805 7 55\r\n", "output": ["1476596 738298 1476595"]}, {"input": "91 86 96470485 12 43\r\n", "output": ["12464 6232 12464"]}, {"input": "85 53 576663715 13 1\r\n", "output": ["129530 64765 129529"]}, {"input": "2 21 196681588 2 18\r\n", "output": ["4682895 4682894 4682895"]}, {"input": "8 29 388254841 6 29\r\n", "output": ["1912586 956293 1912585"]}, {"input": "2 59 400923999 2 43\r\n", "output": ["3397662 3397661 3397661"]}, {"input": "3 71 124911502 1 67\r\n", "output": ["879658 439829 439829"]}, {"input": "1 17 523664480 1 4\r\n", "output": ["30803793 30803792 30803793", "30803793 30803792 30803793"]}, {"input": "11 27 151005021 3 15\r\n", "output": ["559278 279639 559278"]}, {"input": "7 32 461672865 4 11\r\n", "output": ["2404547 1202273 2404546"]}, {"input": "2 90 829288586 1 57\r\n", "output": ["4607159 4607158 4607159"]}, {"input": "17 5 370710486 2 1\r\n", "output": ["4633882 2316941 4633881"]}, {"input": "88 91 6317 70 16\r\n", "output": ["1 0 1"]}, {"input": "19 73 1193 12 46\r\n", "output": ["1 0 1"]}, {"input": "84 10 405 68 8\r\n", "output": ["1 0 0"]}, {"input": "92 80 20 9 69\r\n", "output": ["1 0 0"]}, {"input": "69 21 203 13 16\r\n", "output": ["1 0 0"]}, {"input": "63 22 1321 61 15\r\n", "output": ["1 0 0"]}, {"input": "56 83 4572 35 22\r\n", "output": ["1 0 1"]}, {"input": "36 19 684 20 15\r\n", "output": ["1 1 1"]}, {"input": "33 2 1 8 2\r\n", "output": ["1 0 0"]}, {"input": "76 74 1 38 39\r\n", "output": ["1 0 0"]}, {"input": "1 71 1000000000000000000 1 5\r\n", "output": ["14084507042253522 14084507042253521 14084507042253522", "14084507042253522 14084507042253521 14084507042253522"]}, {"input": "13 89 1000000000000000000 10 14\r\n", "output": ["936329588014982 468164794007491 936329588014982"]}, {"input": "1 35 1000000000000000000 1 25\r\n", "output": ["28571428571428572 28571428571428571 28571428571428571", "28571428571428572 28571428571428571 28571428571428571"]}, {"input": "81 41 1000000000000000000 56 30\r\n", "output": ["304878048780488 152439024390244 304878048780488"]}, {"input": "4 39 1000000000000000000 3 32\r\n", "output": ["8547008547008547 4273504273504273 8547008547008547"]}, {"input": "21 49 1000000000000000000 18 11\r\n", "output": ["1020408163265307 510204081632653 1020408163265306"]}, {"input": "91 31 1000000000000000000 32 7\r\n", "output": ["358422939068101 179211469534050 358422939068101"]}, {"input": "51 99 1000000000000000000 48 79\r\n", "output": ["202020202020203 101010101010101 202020202020202"]}, {"input": "5 99 1000000000000000000 4 12\r\n", "output": ["2525252525252526 1262626262626263 2525252525252525"]}, {"input": "100 100 1000000000000000000 1 1\r\n", "output": ["101010101010101 50505050505051 50505050505051"]}, {"input": "100 100 1000000000000000000 31 31\r\n", "output": ["101010101010101 50505050505051 101010101010101"]}, {"input": "1 100 1000000000000000000 1 1\r\n", "output": ["10000000000000000 10000000000000000 10000000000000000", "10000000000000000 10000000000000000 10000000000000000"]}, {"input": "1 100 1000000000000000000 1 35\r\n", "output": ["10000000000000000 10000000000000000 10000000000000000", "10000000000000000 10000000000000000 10000000000000000"]}, {"input": "100 1 1000000000000000000 1 1\r\n", "output": ["10101010101010101 5050505050505051 5050505050505051"]}, {"input": "100 1 1000000000000000000 35 1\r\n", "output": ["10101010101010101 5050505050505051 10101010101010101"]}, {"input": "1 1 1000000000000000000 1 1\r\n", "output": ["1000000000000000000 1000000000000000000 1000000000000000000", "1000000000000000000 1000000000000000000 1000000000000000000"]}, {"input": "3 2 5 1 1\r\n", "output": ["1 0 1"]}, {"input": "100 100 10001 1 1\r\n", "output": ["2 1 1"]}, {"input": "1 5 7 1 3\r\n", "output": ["2 1 1", "2 1 1"]}, {"input": "2 2 7 1 1\r\n", "output": ["2 1 2"]}, {"input": "4 1 5 3 1\r\n", "output": ["2 1 2"]}, {"input": "2 3 4 2 3\r\n", "output": ["1 0 0"]}, {"input": "3 5 21 1 2\r\n", "output": ["2 1 1"]}, {"input": "2 4 14 1 1\r\n", "output": ["2 1 2"]}, {"input": "5 9 8 5 4\r\n", "output": ["1 0 0"]}, {"input": "2 6 4 1 3\r\n", "output": ["1 0 1"]}, {"input": "1 5 9 1 1\r\n", "output": ["2 1 2", "2 1 2"]}, {"input": "1 5 3 1 2\r\n", "output": ["1 0 1", "1 0 1"]}]
100
100
100
[{'input': '4 30 766048376 1 23\r\n', 'output': ['8511649 4255824 4255825']}, {'input': '4 1 5 3 1\r\n', 'output': ['2 1 2']}, {'input': '1 100 1000000000000000000 1 35\r\n', 'output': ['10000000000000000 10000000000000000 10000000000000000', '10000000000000000 10000000000000000 10000000000000000']}, {'input': '100 100 1 23 39\r\n', 'output': ['1 0 0']}, {'input': '3 3 26 1 1\r\n', 'output': ['4 2 3']}]
[{'input': '4 5 93 1 2\r\n', 'output': ['6 3 4']}, {'input': '2 6 4 1 3\r\n', 'output': ['1 0 1']}, {'input': '3 1 6 2 1\r\n', 'output': ['3 1 3']}, {'input': '5 99 1000000000000000000 4 12\r\n', 'output': ['2525252525252526 1262626262626263 2525252525252525']}, {'input': '3 5 21 1 2\r\n', 'output': ['2 1 1']}]
[{'input': '7 32 461672865 4 11\r\n', 'output': ['2404547 1202273 2404546']}, {'input': '2 3 4 2 3\r\n', 'output': ['1 0 0']}, {'input': '56 83 4572 35 22\r\n', 'output': ['1 0 1']}, {'input': '19 73 1193 12 46\r\n', 'output': ['1 0 1']}, {'input': '4 2 9 4 2\r\n', 'output': ['2 1 1']}]
[{'input': '91 15 237966754 78 6\r\n', 'output': ['176272 88136 176272']}, {'input': '27 34 77794947 24 4\r\n', 'output': ['88004 44002 88004']}, {'input': '4 1 8 3 1\r\n', 'output': ['3 1 2']}, {'input': '100 100 1000000000000000000 1 1\r\n', 'output': ['101010101010101 50505050505051 50505050505051']}, {'input': '92 10 551902461 1 6\r\n', 'output': ['606487 303243 303244']}]
[{'input': '4 5 93 1 2\r\n', 'output': ['6 3 4']}, {'input': '5 3 100 2 1\r\n', 'output': ['9 4 9']}, {'input': '10 44 222787770 9 25\r\n', 'output': ['562596 281298 562596']}, {'input': '56 83 4572 35 22\r\n', 'output': ['1 0 1']}, {'input': '2 6 4 1 3\r\n', 'output': ['1 0 1']}]
100
100
100
100
100
95.65
84.78
84.78
84.78
84.78
97.83
82.61
80.43
76.09
82.61
290
100
86.954
83.914
["5 2 3", "8 2 4"]
The only line contains three integers n, b, p (1 ≀ n, b, p ≀ 500) β€” the number of participants and the parameters described in the problem statement.
eb815f35e9f29793a120d120968cfe34
import java.util.Scanner; /** * Created by Peter on 13.04.2016. */ public class TaskA { int n, b, p; TaskA(Scanner sc) { n = sc.nextInt(); b = sc.nextInt(); p = sc.nextInt(); } private int getGamePlayed() { int nn = n; int ans = 0; while (nn > 1 ) { int k = 1; while (k*2 <= nn) { k *= 2; } ans += k/2; nn = nn - k/2; } return ans; } private void solve(){ int totalP = p * n; int gamePlayed = getGamePlayed(); int totalB = gamePlayed * (2 * b + 1); System.out.printf("%d %d", totalB, totalP); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); new TaskA(sc).solve(); sc.close(); } }
["20 15", "35 32"]
Java
NoteIn the first example will be three rounds: in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), in the second round will be only one match, so we need another 5 bottles of water, in the third round will also be only one match, so we need another 5 bottles of water. So in total we need 20 bottles of water.In the second example no participant will move on to some round directly.
Print two integers x and y β€” the number of bottles and towels need for the tournament.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.The tournament takes place in the following way (below, m is the number of the participants of the current round): let k be the maximal power of the number 2 such that k ≀ m, k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly, when only one participant remains, the tournament finishes. Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.Find the number of bottles and towels needed for the tournament.Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
[{"input": "5 2 3\r\n", "output": ["20\r\n15", "20 15"]}, {"input": "8 2 4\r\n", "output": ["35\r\n32", "35 32"]}, {"input": "10 1 500\r\n", "output": ["27 5000", "27\r\n5000"]}, {"input": "20 500 1\r\n", "output": ["19019\r\n20", "19019 20"]}, {"input": "100 123 99\r\n", "output": ["24453\r\n9900", "24453 9900"]}, {"input": "500 1 1\r\n", "output": ["1497 500", "1497\r\n500"]}, {"input": "500 500 500\r\n", "output": ["499499\r\n250000", "499499 250000"]}, {"input": "500 237 474\r\n", "output": ["237025 237000", "237025\r\n237000"]}, {"input": "1 2 3\r\n", "output": ["0\r\n3", "0 3"]}, {"input": "1 2 133\r\n", "output": ["0 133", "0\r\n133"]}, {"input": "1 2 100\r\n", "output": ["0 100", "0\r\n100"]}, {"input": "1 3 4\r\n", "output": ["0\r\n4", "0 4"]}, {"input": "1 10 15\r\n", "output": ["0 15", "0\r\n15"]}, {"input": "1 1 1\r\n", "output": ["0 1", "0\r\n1"]}, {"input": "1 2 5\r\n", "output": ["0 5", "0\r\n5"]}, {"input": "1 500 500\r\n", "output": ["0\r\n500", "0 500"]}, {"input": "1 3 8\r\n", "output": ["0 8", "0\r\n8"]}, {"input": "10 10 10\r\n", "output": ["189\r\n100", "189 100"]}, {"input": "1 3 5\r\n", "output": ["0 5", "0\r\n5"]}, {"input": "1 2 1\r\n", "output": ["0 1", "0\r\n1"]}, {"input": "1 2 4\r\n", "output": ["0\r\n4", "0 4"]}, {"input": "1 10 10\r\n", "output": ["0\r\n10", "0 10"]}, {"input": "1 345 345\r\n", "output": ["0 345", "0\r\n345"]}, {"input": "7 12 13\r\n", "output": ["150\r\n91", "150 91"]}, {"input": "1 500 1\r\n", "output": ["0 1", "0\r\n1"]}, {"input": "1 12 13\r\n", "output": ["0 13", "0\r\n13"]}, {"input": "1 500 499\r\n", "output": ["0\r\n499", "0 499"]}, {"input": "1 100 90\r\n", "output": ["0 90", "0\r\n90"]}, {"input": "2 100 90\r\n", "output": ["201 180", "201\r\n180"]}, {"input": "53 1 1\r\n", "output": ["156\r\n53", "156 53"]}, {"input": "73 73 73\r\n", "output": ["10584 5329", "10584\r\n5329"]}, {"input": "67 1 1\r\n", "output": ["198 67", "198\r\n67"]}, {"input": "63 1 1\r\n", "output": ["186\r\n63", "186 63"]}, {"input": "59 1 1\r\n", "output": ["174\r\n59", "174 59"]}, {"input": "57 1 1\r\n", "output": ["168 57", "168\r\n57"]}, {"input": "13 1 1\r\n", "output": ["36 13", "36\r\n13"]}, {"input": "349 2 5\r\n", "output": ["1740\r\n1745", "1740 1745"]}, {"input": "456 456 456\r\n", "output": ["415415\r\n207936", "415415 207936"]}]
100
100
100
[{'input': '10 1 500\r\n', 'output': ['27 5000', '27\r\n5000']}, {'input': '1 2 100\r\n', 'output': ['0 100', '0\r\n100']}, {'input': '1 3 4\r\n', 'output': ['0\r\n4', '0 4']}, {'input': '53 1 1\r\n', 'output': ['156\r\n53', '156 53']}, {'input': '67 1 1\r\n', 'output': ['198 67', '198\r\n67']}]
[{'input': '349 2 5\r\n', 'output': ['1740\r\n1745', '1740 1745']}, {'input': '1 100 90\r\n', 'output': ['0 90', '0\r\n90']}, {'input': '1 2 1\r\n', 'output': ['0 1', '0\r\n1']}, {'input': '20 500 1\r\n', 'output': ['19019\r\n20', '19019 20']}, {'input': '1 500 499\r\n', 'output': ['0\r\n499', '0 499']}]
[{'input': '10 1 500\r\n', 'output': ['27 5000', '27\r\n5000']}, {'input': '53 1 1\r\n', 'output': ['156\r\n53', '156 53']}, {'input': '1 3 5\r\n', 'output': ['0 5', '0\r\n5']}, {'input': '1 2 133\r\n', 'output': ['0 133', '0\r\n133']}, {'input': '57 1 1\r\n', 'output': ['168 57', '168\r\n57']}]
[{'input': '1 100 90\r\n', 'output': ['0 90', '0\r\n90']}, {'input': '10 10 10\r\n', 'output': ['189\r\n100', '189 100']}, {'input': '1 500 500\r\n', 'output': ['0\r\n500', '0 500']}, {'input': '1 345 345\r\n', 'output': ['0 345', '0\r\n345']}, {'input': '10 1 500\r\n', 'output': ['27 5000', '27\r\n5000']}]
[{'input': '1 3 4\r\n', 'output': ['0\r\n4', '0 4']}, {'input': '1 2 133\r\n', 'output': ['0 133', '0\r\n133']}, {'input': '1 12 13\r\n', 'output': ['0 13', '0\r\n13']}, {'input': '67 1 1\r\n', 'output': ['198 67', '198\r\n67']}, {'input': '1 1 1\r\n', 'output': ['0 1', '0\r\n1']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
291
100
100
100
["4 5\n2 3 1 4 4", "3 3\n3 1 2"]
The first line contains two integer numbers n, m (1 ≀ n, m ≀ 100). The second line contains m integer numbers l1, l2, ..., lm (1 ≀ li ≀ n) β€” indices of leaders in the beginning of each step.
4a7c959ca279d0a9bd9bbf0ce88cf72b
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.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.StringTokenizer; public class Test { static PrintWriter pw = new PrintWriter(System.out); static ArrayList<Integer> list = new ArrayList(); public static void main(String[] args)throws Exception { Reader.init(System.in); int n = Reader.nextInt(); int k = Reader.nextInt(); HashMap<Integer , Integer> set = new HashMap(); boolean[] flags = new boolean[n+1]; int[] res = new int[n+1]; int[] game = new int[k]; int count = 0; int temp = 0; for(int i = 0 ; i<k ; i++)game[i] = Reader.nextInt(); for(int i = 0 ; i<k-1 ; i++) { int a = game[i]; int b = game[i+1]; if(b>a) temp = b - a; else temp = b + (n-a); if(set.containsKey(temp) && set.get(temp) != a) { pw.print(-1); pw.close(); return; } else if(res[a] != 0 && res[a] != temp) { pw.print(-1); pw.close(); return; } else if(!set.containsKey(res[a])) { set.put(temp , a); res[a] = temp; count ++; flags[res[a]] = true; } } if(count <n) { for(int i = 1 ; i<=n ; i++) if(!flags[i]) { list.add(i); } } StringBuilder str = new StringBuilder(); Iterator<Integer> itr = list.iterator(); for(int i = 1 ; i<=n ; i++) if(res[i] == 0) { str.append(itr.next()).append(" "); } else str.append(res[i]).append(" "); pw.print(str); pw.close(); } } 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()); } }
["3 1 2 4", "-1"]
Java
NoteLet's follow leadership in the first example: Child 2 starts. Leadership goes from 2 to 2 + a2 = 3. Leadership goes from 3 to 3 + a3 = 5. As it's greater than 4, it's going in a circle to 1. Leadership goes from 1 to 1 + a1 = 4. Leadership goes from 4 to 4 + a4 = 8. Thus in circle it still remains at 4.
Print such permutation of n numbers a1, a2, ..., an that leaders in the game will be exactly l1, l2, ..., lm if all the rules are followed. If there are multiple solutions print any of them. If there is no permutation which satisfies all described conditions print -1.
n children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation a1, a2, ..., an of length n. It is an integer sequence such that each integer from 1 to n appears exactly once in it.The game consists of m steps. On each step the current leader with index i counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader becomes the new leader.You are given numbers l1, l2, ..., lm β€” indices of leaders in the beginning of each step. Child with number l1 is the first leader in the game. Write a program which will restore a possible permutation a1, a2, ..., an. If there are multiple solutions then print any of them. If there is no solution then print -1.
[{"input": "4 5\r\n2 3 1 4 4\r\n", "output": ["3 1 2 4"]}, {"input": "3 3\r\n3 1 2\r\n", "output": ["-1"]}, {"input": "1 100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["1"]}, {"input": "6 8\r\n2 5 4 2 5 4 2 5\r\n", "output": ["1 3 2 4 5 6"]}, {"input": "100 1\r\n6\r\n", "output": ["1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100"]}, {"input": "10 5\r\n7 7 9 9 3\r\n", "output": ["-1"]}, {"input": "10 20\r\n10 1 5 7 1 2 5 3 6 3 9 4 3 4 9 6 8 4 9 6\r\n", "output": ["-1"]}, {"input": "20 15\r\n11 19 1 8 17 12 3 1 8 17 12 3 1 8 17\r\n", "output": ["7 1 18 3 4 5 6 9 10 12 8 11 13 14 16 17 15 19 2 20"]}, {"input": "100 100\r\n96 73 23 74 35 44 75 13 62 50 76 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63\r\n", "output": ["1 2 3 4 5 6 7 8 10 11 12 13 49 14 15 17 18 19 20 21 22 23 51 39 24 25 27 28 16 29 30 32 33 34 9 35 36 37 40 41 42 43 44 31 79 45 46 47 48 26 52 53 54 55 56 57 58 59 60 62 63 88 66 64 65 67 68 69 70 71 72 73 50 61 38 87 74 75 76 78 80 81 82 83 84 85 86 89 90 91 92 93 94 95 96 77 97 98 99 100"]}, {"input": "100 100\r\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91\r\n", "output": ["-1"]}, {"input": "20 20\r\n1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11\r\n", "output": ["19 17 15 13 11 9 7 5 3 1 20 18 16 14 12 10 8 6 4 2"]}, {"input": "20 5\r\n1 20 2 19 3\r\n", "output": ["19 17 1 3 5 6 7 8 9 10 11 12 13 14 15 16 18 20 4 2"]}, {"input": "19 19\r\n1 19 2 18 3 17 4 16 5 15 6 14 7 13 8 12 9 11 10\r\n", "output": ["-1"]}, {"input": "100 100\r\n1 99 2 98 3 97 4 96 5 95 6 94 7 93 8 92 9 91 10 90 11 89 12 88 13 87 14 86 15 85 16 84 17 83 18 82 19 81 20 80 21 79 22 78 23 77 24 76 25 75 26 74 27 73 28 72 29 71 30 70 31 69 32 68 33 67 34 66 35 65 36 64 37 63 38 62 39 61 40 60 41 59 42 58 43 57 44 56 45 55 46 54 47 53 48 52 49 51 50 50\r\n", "output": ["98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 100 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1"]}, {"input": "51 18\r\n8 32 24 19 1 29 49 24 39 33 5 37 37 26 17 28 2 19\r\n", "output": ["-1"]}, {"input": "5 5\r\n1 2 5 2 4\r\n", "output": ["-1"]}, {"input": "6 6\r\n1 2 1 1 3 6\r\n", "output": ["-1"]}, {"input": "4 4\r\n4 3 4 2\r\n", "output": ["-1"]}, {"input": "3 3\r\n2 2 3\r\n", "output": ["-1"]}, {"input": "4 6\r\n1 1 2 4 4 4\r\n", "output": ["-1"]}, {"input": "9 4\r\n8 2 8 3\r\n", "output": ["-1"]}, {"input": "4 6\r\n2 3 1 4 4 1\r\n", "output": ["-1"]}, {"input": "2 3\r\n1 1 2\r\n", "output": ["-1"]}, {"input": "5 7\r\n4 3 4 3 3 4 5\r\n", "output": ["-1"]}, {"input": "2 9\r\n1 1 1 1 2 1 1 1 1\r\n", "output": ["-1"]}, {"input": "4 4\r\n2 4 4 4\r\n", "output": ["1 2 3 4"]}, {"input": "3 3\r\n1 1 3\r\n", "output": ["-1"]}, {"input": "2 5\r\n1 2 2 1 1\r\n", "output": ["-1"]}, {"input": "4 4\r\n1 4 1 3\r\n", "output": ["-1"]}, {"input": "3 4\r\n1 3 1 1\r\n", "output": ["-1"]}, {"input": "4 4\r\n1 4 1 1\r\n", "output": ["-1"]}, {"input": "66 67\r\n19 9 60 40 19 48 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5\r\n", "output": ["-1"]}, {"input": "3 3\r\n3 3 2\r\n", "output": ["-1"]}, {"input": "27 28\r\n8 18 27 24 20 8 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23\r\n", "output": ["-1"]}, {"input": "4 3\r\n1 1 2\r\n", "output": ["-1"]}, {"input": "4 4\r\n2 4 2 3\r\n", "output": ["-1"]}, {"input": "2 3\r\n2 2 1\r\n", "output": ["-1"]}, {"input": "2 2\r\n2 2\r\n", "output": ["1 2"]}, {"input": "3 4\r\n2 3 3 1\r\n", "output": ["-1"]}, {"input": "5 6\r\n1 4 4 2 1 4\r\n", "output": ["-1"]}, {"input": "4 3\r\n2 3 4\r\n", "output": ["-1"]}, {"input": "2 3\r\n1 2 1\r\n", "output": ["-1"]}, {"input": "10 4\r\n5 6 5 7\r\n", "output": ["-1"]}, {"input": "3 3\r\n1 1 2\r\n", "output": ["-1"]}, {"input": "4 5\r\n1 4 1 3 2\r\n", "output": ["-1"]}, {"input": "6 5\r\n1 2 4 1 3\r\n", "output": ["-1"]}]
100
100
100
[{'input': '4 4\r\n1 4 1 1\r\n', 'output': ['-1']}, {'input': '10 20\r\n10 1 5 7 1 2 5 3 6 3 9 4 3 4 9 6 8 4 9 6\r\n', 'output': ['-1']}, {'input': '66 67\r\n19 9 60 40 19 48 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5\r\n', 'output': ['-1']}, {'input': '4 4\r\n2 4 2 3\r\n', 'output': ['-1']}, {'input': '3 3\r\n2 2 3\r\n', 'output': ['-1']}]
[{'input': '20 5\r\n1 20 2 19 3\r\n', 'output': ['19 17 1 3 5 6 7 8 9 10 11 12 13 14 15 16 18 20 4 2']}, {'input': '6 5\r\n1 2 4 1 3\r\n', 'output': ['-1']}, {'input': '2 3\r\n1 1 2\r\n', 'output': ['-1']}, {'input': '2 5\r\n1 2 2 1 1\r\n', 'output': ['-1']}, {'input': '66 67\r\n19 9 60 40 19 48 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5\r\n', 'output': ['-1']}]
[{'input': '3 3\r\n3 1 2\r\n', 'output': ['-1']}, {'input': '2 3\r\n2 2 1\r\n', 'output': ['-1']}, {'input': '6 8\r\n2 5 4 2 5 4 2 5\r\n', 'output': ['1 3 2 4 5 6']}, {'input': '20 5\r\n1 20 2 19 3\r\n', 'output': ['19 17 1 3 5 6 7 8 9 10 11 12 13 14 15 16 18 20 4 2']}, {'input': '19 19\r\n1 19 2 18 3 17 4 16 5 15 6 14 7 13 8 12 9 11 10\r\n', 'output': ['-1']}]
[{'input': '2 3\r\n2 2 1\r\n', 'output': ['-1']}, {'input': '6 5\r\n1 2 4 1 3\r\n', 'output': ['-1']}, {'input': '2 3\r\n1 1 2\r\n', 'output': ['-1']}, {'input': '10 5\r\n7 7 9 9 3\r\n', 'output': ['-1']}, {'input': '4 3\r\n2 3 4\r\n', 'output': ['-1']}]
[{'input': '10 5\r\n7 7 9 9 3\r\n', 'output': ['-1']}, {'input': '4 6\r\n2 3 1 4 4 1\r\n', 'output': ['-1']}, {'input': '4 5\r\n2 3 1 4 4\r\n', 'output': ['3 1 2 4']}, {'input': '27 28\r\n8 18 27 24 20 8 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23\r\n', 'output': ['-1']}, {'input': '4 3\r\n2 3 4\r\n', 'output': ['-1']}]
100
100
100
100
100
70.45
100
100
70.45
90.91
46.15
84.62
96.15
46.15
65.38
292
100
86.362
67.69
["abacaba", "jinotega"]
In the only line of input there is a string S of lowercase English letters (1 ≀ |S| ≀ 500)Β β€” the identifiers of a program with removed whitespace characters.
c4551f66a781b174f95865fa254ca972
import java.util.HashMap; import java.util.Scanner; public class CODE_OBSTUFICATIION { public static void main(String[] args) { Scanner nik = new Scanner(System.in); String s = nik.next(); boolean b = true; HashMap<Character, Integer> hm = new HashMap<>(); for (int i = 0; i < s.length(); i++) { int temp = s.charAt(i) - 'a'; if (hm.size() < temp) { b = false; break; } else { hm.put(s.charAt(i), hm.getOrDefault(s.charAt(i) + 1, 0)); } } System.out.println(b == true ? "YES" : "NO"); } }
["YES", "NO"]
Java
NoteIn the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program: replace all occurences of number with a, the result would be "a string a character a string a", replace all occurences of string with b, the result would be "a b a character a b a", replace all occurences of character with c, the result would be "a b a c a b a", all identifiers have been replaced, thus the obfuscation is finished.
If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO".
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol a, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with b, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs.You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation.
[{"input": "abacaba\r\n", "output": ["YES"]}, {"input": "jinotega\r\n", "output": ["No", "NO"]}, {"input": "aaaaaaaaaaa\r\n", "output": ["YES"]}, {"input": "aba\r\n", "output": ["YES"]}, {"input": "bab\r\n", "output": ["No", "NO"]}, {"input": "a\r\n", "output": ["YES"]}, {"input": "abcdefghijklmnopqrstuvwxyz\r\n", "output": ["YES"]}, {"input": "fihyxmbnzq\r\n", "output": ["No", "NO"]}, {"input": "aamlaswqzotaanasdhcvjoaiwdhctezzawagkdgfffeqkyrvbcrfqgkdsvximsnvmkmjyofswmtjdoxgwamsaatngenqvsvrvwlbzuoeaolfcnmdacrmdleafbsmerwmxzyylfhemnkoayuhtpbikm\r\n", "output": ["No", "NO"]}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": ["YES"]}, {"input": "darbbbcwynbbbbaacbkvbakavabbbabzajlbajryaabbbccxraakgniagbtsswcfbkubdmcasccepybkaefcfsbzdddxgcjadybcfjtmqbspflqrdghgfwnccfveogdmifkociqscahdejctacwzbkhihajfilrgcjiofwfklifobozikcmvcfeqlidrgsgdfxffaaebzjxngsjxiclyolhjokqpdbfffooticxsezpgqkhhzmbmqgskkqvefzyijrwhpftcmbedmaflapmeljaudllojfpgfkpvgylaglrhrslxlprbhgknrctilngqccbddvpamhifsbmyowohczizjcbleehfrecjbqtxertnpfmalejmbxkhkkbyopuwlhkxuqellsybgcndvniyyxfoufalstdsdfjoxlnmigkqwmgojsppaannfstxytelluvvkdcezlqfsperwyjsdsmkvgjdbksswamhmoukcawiigkggztr\r\n", "output": ["No", "NO"]}, {"input": "bbbbbb\r\n", "output": ["No", "NO"]}, {"input": "aabbbd\r\n", "output": ["No", "NO"]}, {"input": "abdefghijklmnopqrstuvwxyz\r\n", "output": ["No", "NO"]}, {"input": "abcdeghijklmnopqrstuvwxyz\r\n", "output": ["No", "NO"]}, {"input": "abcdefghijklmnopqrsuvwxyz\r\n", "output": ["No", "NO"]}, {"input": "abcdefghijklmnopqrstuvwxy\r\n", "output": ["YES"]}, {"input": "abcdefghijklmnopqrsutvwxyz\r\n", "output": ["No", "NO"]}, {"input": "acdef\r\n", "output": ["No", "NO"]}, {"input": "z\r\n", "output": ["No", "NO"]}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaababaaababaabababccbabdbcbadccacdbdedabbeecbcabbdcaecdabbedddafeffaccgeacefbcahabfiiegecdbebabhhbdgfeghhbfahgagefbgghdbhadeicbdfgdchhefhigfcgdhcihecacfhadfgfejccibcjkfhbigbealjjkfldiecfdcafbamgfkbjlbifldghmiifkkglaflmjfmkfdjlbliijkgfdelklfnadbifgbmklfbqkhirhcadoadhmjrghlmelmjfpakqkdfcgqdkaeqpbcdoeqglqrarkipncckpfmajrqsfffldegbmahsfcqdfdqtrgrouqajgsojmmukptgerpanpcbejmergqtavwsvtveufdseuemwrhfmjqinxjodddnpcgqullrhmogflsxgsbapoghortiwcovejtinncozk\r\n", "output": ["No", "NO"]}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": ["YES"]}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbabbbabbaaabbaaaaabaabbaa\r\n", "output": ["YES"]}, {"input": "aababbabbaabbbbbaabababaabbbaaaaabbabbabbaabbbbabaabbaaababbaaacbbabbbbbbcbcababbccaaacbaccaccaababbccaacccaabaaccaaabacacbaabacbaacbaaabcbbbcbbaacaabcbcbccbacabbcbabcaccaaaaaabcbacabcbabbbbbabccbbcacbaaabbccbbaaaaaaaaaaaadbbbabdacabdaddddbaabbddbdabbdacbacbacaaaabbacadbcddddadaddabbdccaddbaaacbceebbceadbeaadecddbbbcaaecbdeaebaddbbdebbcbaabcacbdcdc\r\n", "output": ["YES"]}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbaabaabaababbbabbacacbbbacbbaaaabbccacbaabaaccbbbbbcbbbacabbccaaabbaaacabcbacbcabbbbecbecadcbacbaadeeadabeacdebccdbbcaecdbeeebbebcaaaeacdcbdeccdbbdcdebdcbdacebcecbacddeeaebcedffedfggbeedceacaecagdfedfabcfchffceachgcbicbcffeeebgcgiefcafhibhceiedgbfebbccegbehhibhhfedbaeedbghggffehggaeaidifhdhaggdjcfjhiaieaichjacedchejg\r\n", "output": ["No", "NO"]}, {"input": "b\r\n", "output": ["No", "NO"]}, {"input": "ac\r\n", "output": ["No", "NO"]}, {"input": "cde\r\n", "output": ["No", "NO"]}, {"input": "abd\r\n", "output": ["No", "NO"]}, {"input": "zx\r\n", "output": ["No", "NO"]}, {"input": "bcd\r\n", "output": ["No", "NO"]}, {"input": "aaac\r\n", "output": ["No", "NO"]}, {"input": "aacb\r\n", "output": ["No", "NO"]}, {"input": "acd\r\n", "output": ["No", "NO"]}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz\r\n", "output": ["No", "NO"]}, {"input": "abcdefghijklmnopqrstuvwxyzz\r\n", "output": ["YES"]}, {"input": "bc\r\n", "output": ["No", "NO"]}, {"input": "aaaaaaaaad\r\n", "output": ["No", "NO"]}, {"input": "abb\r\n", "output": ["YES"]}, {"input": "abcb\r\n", "output": ["YES"]}, {"input": "aac\r\n", "output": ["No", "NO"]}, {"input": "abcbcb\r\n", "output": ["YES"]}, {"input": "bb\r\n", "output": ["No", "NO"]}, {"input": "abbb\r\n", "output": ["YES"]}, {"input": "bbb\r\n", "output": ["No", "NO"]}, {"input": "x\r\n", "output": ["No", "NO"]}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazz\r\n", "output": ["No", "NO"]}, {"input": "acbccccccccccc\r\n", "output": ["No", "NO"]}, {"input": "za\r\n", "output": ["No", "NO"]}, {"input": "ade\r\n", "output": ["No", "NO"]}, {"input": "bbbbbbbbbb\r\n", "output": ["No", "NO"]}, {"input": "bac\r\n", "output": ["No", "NO"]}, {"input": "bcddcb\r\n", "output": ["No", "NO"]}, {"input": "aaacb\r\n", "output": ["No", "NO"]}, {"input": "aaaaac\r\n", "output": ["No", "NO"]}, {"input": "aaaaaaaaaaad\r\n", "output": ["No", "NO"]}, {"input": "c\r\n", "output": ["No", "NO"]}, {"input": "abcccccccc\r\n", "output": ["YES"]}, {"input": "aaaaaaac\r\n", "output": ["No", "NO"]}]
100
100
100
[{'input': 'bb\r\n', 'output': ['No', 'NO']}, {'input': 'aaaaaaaaaaa\r\n', 'output': ['YES']}, {'input': 'darbbbcwynbbbbaacbkvbakavabbbabzajlbajryaabbbccxraakgniagbtsswcfbkubdmcasccepybkaefcfsbzdddxgcjadybcfjtmqbspflqrdghgfwnccfveogdmifkociqscahdejctacwzbkhihajfilrgcjiofwfklifobozikcmvcfeqlidrgsgdfxffaaebzjxngsjxiclyolhjokqpdbfffooticxsezpgqkhhzmbmqgskkqvefzyijrwhpftcmbedmaflapmeljaudllojfpgfkpvgylaglrhrslxlprbhgknrctilngqccbddvpamhifsbmyowohczizjcbleehfrecjbqtxertnpfmalejmbxkhkkbyopuwlhkxuqellsybgcndvniyyxfoufalstdsdfjoxlnmigkqwmgojsppaannfstxytelluvvkdcezlqfsperwyjsdsmkvgjdbksswamhmoukcawiigkggztr\r\n', 'output': ['No', 'NO']}, {'input': 'cde\r\n', 'output': ['No', 'NO']}, {'input': 'abcbcb\r\n', 'output': ['YES']}]
[{'input': 'aacb\r\n', 'output': ['No', 'NO']}, {'input': 'aabbbd\r\n', 'output': ['No', 'NO']}, {'input': 'aaac\r\n', 'output': ['No', 'NO']}, {'input': 'bc\r\n', 'output': ['No', 'NO']}, {'input': 'abcdeghijklmnopqrstuvwxyz\r\n', 'output': ['No', 'NO']}]
[{'input': 'ade\r\n', 'output': ['No', 'NO']}, {'input': 'bcd\r\n', 'output': ['No', 'NO']}, {'input': 'darbbbcwynbbbbaacbkvbakavabbbabzajlbajryaabbbccxraakgniagbtsswcfbkubdmcasccepybkaefcfsbzdddxgcjadybcfjtmqbspflqrdghgfwnccfveogdmifkociqscahdejctacwzbkhihajfilrgcjiofwfklifobozikcmvcfeqlidrgsgdfxffaaebzjxngsjxiclyolhjokqpdbfffooticxsezpgqkhhzmbmqgskkqvefzyijrwhpftcmbedmaflapmeljaudllojfpgfkpvgylaglrhrslxlprbhgknrctilngqccbddvpamhifsbmyowohczizjcbleehfrecjbqtxertnpfmalejmbxkhkkbyopuwlhkxuqellsybgcndvniyyxfoufalstdsdfjoxlnmigkqwmgojsppaannfstxytelluvvkdcezlqfsperwyjsdsmkvgjdbksswamhmoukcawiigkggztr\r\n', 'output': ['No', 'NO']}, {'input': 'bc\r\n', 'output': ['No', 'NO']}, {'input': 'aaaaac\r\n', 'output': ['No', 'NO']}]
[{'input': 'za\r\n', 'output': ['No', 'NO']}, {'input': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaababaaababaabababccbabdbcbadccacdbdedabbeecbcabbdcaecdabbedddafeffaccgeacefbcahabfiiegecdbebabhhbdgfeghhbfahgagefbgghdbhadeicbdfgdchhefhigfcgdhcihecacfhadfgfejccibcjkfhbigbealjjkfldiecfdcafbamgfkbjlbifldghmiifkkglaflmjfmkfdjlbliijkgfdelklfnadbifgbmklfbqkhirhcadoadhmjrghlmelmjfpakqkdfcgqdkaeqpbcdoeqglqrarkipncckpfmajrqsfffldegbmahsfcqdfdqtrgrouqajgsojmmukptgerpanpcbejmergqtavwsvtveufdseuemwrhfmjqinxjodddnpcgqullrhmogflsxgsbapoghortiwcovejtinncozk\r\n', 'output': ['No', 'NO']}, {'input': 'fihyxmbnzq\r\n', 'output': ['No', 'NO']}, {'input': 'a\r\n', 'output': ['YES']}, {'input': 'abcccccccc\r\n', 'output': ['YES']}]
[{'input': 'abd\r\n', 'output': ['No', 'NO']}, {'input': 'zx\r\n', 'output': ['No', 'NO']}, {'input': 'aaaaaaac\r\n', 'output': ['No', 'NO']}, {'input': 'aabbbd\r\n', 'output': ['No', 'NO']}, {'input': 'fihyxmbnzq\r\n', 'output': ['No', 'NO']}]
100
100
100
100
100
100
100
100
100
100
100
66.67
66.67
100
66.67
293
100
100
80.002
["20 2\n9 19", "2 1\n16 12"]
The first line of input contains two integers a and b (1 ≀ a, b ≀ 100). The second line contains two integers c and d (1 ≀ c, d ≀ 100).
158cb12d45f4ee3368b94b2b622693e7
import java.util.Scanner; public class A787 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int accel1 = scanner.nextInt(); int initialVal1 = scanner.nextInt(); int accel2 = scanner.nextInt(); int initialVal2 = scanner.nextInt(); int time = checkHit(accel1, initialVal1, accel2, initialVal2); System.out.println(time); } private static int checkHit(int accel1, int initialVal1, int accel2, int initialVal2) { if(initialVal1 % 2 != initialVal2 % 2 && accel1 % 2 == 0 && accel2 % 2 == 0) return -1; int difference = initialVal2 - initialVal1; int i = 0; int j = 0; while(i * accel1 - j * accel2 != difference) { if(i * accel1 - j * accel2 < difference) i++; else j++; if(i > accel1 * accel2 + 100|| j >= 100 + accel1 * accel2) return -1; } return accel1 * i + initialVal1; } }
["82", "-1"]
Java
NoteIn the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82. In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
Print the first time Rick and Morty will scream at the same time, or  - 1 if they will never scream at the same time.
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, .... The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.
[{"input": "20 2\r\n9 19\r\n", "output": ["82"]}, {"input": "2 1\r\n16 12\r\n", "output": ["-1"]}, {"input": "39 52\r\n88 78\r\n", "output": ["1222"]}, {"input": "59 96\r\n34 48\r\n", "output": ["1748"]}, {"input": "87 37\r\n91 29\r\n", "output": ["211"]}, {"input": "11 81\r\n49 7\r\n", "output": ["301"]}, {"input": "39 21\r\n95 89\r\n", "output": ["3414"]}, {"input": "59 70\r\n48 54\r\n", "output": ["1014"]}, {"input": "87 22\r\n98 32\r\n", "output": ["718"]}, {"input": "15 63\r\n51 13\r\n", "output": ["-1"]}, {"input": "39 7\r\n97 91\r\n", "output": ["1255"]}, {"input": "18 18\r\n71 71\r\n", "output": ["1278"]}, {"input": "46 71\r\n16 49\r\n", "output": ["209"]}, {"input": "70 11\r\n74 27\r\n", "output": ["2321"]}, {"input": "94 55\r\n20 96\r\n", "output": ["-1"]}, {"input": "18 4\r\n77 78\r\n", "output": ["1156"]}, {"input": "46 44\r\n23 55\r\n", "output": ["-1"]}, {"input": "74 88\r\n77 37\r\n", "output": ["1346"]}, {"input": "94 37\r\n34 7\r\n", "output": ["789"]}, {"input": "22 81\r\n80 88\r\n", "output": ["-1"]}, {"input": "46 30\r\n34 62\r\n", "output": ["674"]}, {"input": "40 4\r\n81 40\r\n", "output": ["364"]}, {"input": "69 48\r\n39 9\r\n", "output": ["48"]}, {"input": "89 93\r\n84 87\r\n", "output": ["5967"]}, {"input": "17 45\r\n42 65\r\n", "output": ["317"]}, {"input": "41 85\r\n95 46\r\n", "output": ["331"]}, {"input": "69 30\r\n41 16\r\n", "output": ["1410"]}, {"input": "93 74\r\n99 93\r\n", "output": ["-1"]}, {"input": "17 19\r\n44 75\r\n", "output": ["427"]}, {"input": "45 63\r\n98 53\r\n", "output": ["3483"]}, {"input": "69 11\r\n48 34\r\n", "output": ["-1"]}, {"input": "55 94\r\n3 96\r\n", "output": ["204"]}, {"input": "100 100\r\n100 100\r\n", "output": ["100"]}, {"input": "1 1\r\n1 1\r\n", "output": ["1"]}, {"input": "1 1\r\n1 100\r\n", "output": ["100"]}, {"input": "1 100\r\n100 1\r\n", "output": ["101"]}, {"input": "98 1\r\n99 100\r\n", "output": ["9703"]}, {"input": "98 1\r\n99 2\r\n", "output": ["9605"]}, {"input": "97 2\r\n99 100\r\n", "output": ["4852"]}, {"input": "3 3\r\n3 1\r\n", "output": ["-1"]}, {"input": "3 2\r\n7 2\r\n", "output": ["2"]}, {"input": "2 3\r\n2 5\r\n", "output": ["5"]}, {"input": "2 3\r\n2 3\r\n", "output": ["3"]}, {"input": "100 3\r\n100 5\r\n", "output": ["-1"]}, {"input": "6 10\r\n12 14\r\n", "output": ["-1"]}, {"input": "4 2\r\n4 4\r\n", "output": ["-1"]}, {"input": "2 3\r\n2 2\r\n", "output": ["-1"]}, {"input": "2 3\r\n4 99\r\n", "output": ["99"]}, {"input": "1 5\r\n1 5\r\n", "output": ["5"]}, {"input": "1 100\r\n3 1\r\n", "output": ["100"]}, {"input": "2 2\r\n2 1\r\n", "output": ["-1"]}, {"input": "2 10\r\n6 20\r\n", "output": ["20"]}, {"input": "2 2\r\n2 10\r\n", "output": ["10"]}, {"input": "3 7\r\n3 6\r\n", "output": ["-1"]}, {"input": "1 100\r\n1 100\r\n", "output": ["100"]}, {"input": "7 25\r\n39 85\r\n", "output": ["319"]}, {"input": "84 82\r\n38 6\r\n", "output": ["82"]}, {"input": "7 7\r\n7 14\r\n", "output": ["14"]}]
100
100
100
[{'input': '69 30\r\n41 16\r\n', 'output': ['1410']}, {'input': '7 25\r\n39 85\r\n', 'output': ['319']}, {'input': '94 55\r\n20 96\r\n', 'output': ['-1']}, {'input': '87 22\r\n98 32\r\n', 'output': ['718']}, {'input': '41 85\r\n95 46\r\n', 'output': ['331']}]
[{'input': '2 2\r\n2 10\r\n', 'output': ['10']}, {'input': '97 2\r\n99 100\r\n', 'output': ['4852']}, {'input': '40 4\r\n81 40\r\n', 'output': ['364']}, {'input': '2 3\r\n2 5\r\n', 'output': ['5']}, {'input': '2 3\r\n4 99\r\n', 'output': ['99']}]
[{'input': '87 22\r\n98 32\r\n', 'output': ['718']}, {'input': '94 37\r\n34 7\r\n', 'output': ['789']}, {'input': '97 2\r\n99 100\r\n', 'output': ['4852']}, {'input': '98 1\r\n99 2\r\n', 'output': ['9605']}, {'input': '59 70\r\n48 54\r\n', 'output': ['1014']}]
[{'input': '98 1\r\n99 2\r\n', 'output': ['9605']}, {'input': '100 100\r\n100 100\r\n', 'output': ['100']}, {'input': '3 2\r\n7 2\r\n', 'output': ['2']}, {'input': '18 18\r\n71 71\r\n', 'output': ['1278']}, {'input': '2 10\r\n6 20\r\n', 'output': ['20']}]
[{'input': '2 3\r\n2 3\r\n', 'output': ['3']}, {'input': '18 18\r\n71 71\r\n', 'output': ['1278']}, {'input': '1 5\r\n1 5\r\n', 'output': ['5']}, {'input': '3 7\r\n3 6\r\n', 'output': ['-1']}, {'input': '17 19\r\n44 75\r\n', 'output': ['427']}]
100
100
100
100
100
95
90
90
90
95
78.57
50
71.43
71.43
85.71
294
100
92
71.428
["4 2", "3 1"]
The only line contains two integers $$$n$$$ and $$$m~(1 \le n \le 10^5, 0 \le m \le \frac{n (n - 1)}{2})$$$. It is guaranteed that there exists a graph without any self-loops or multiple edges with such number of vertices and edges.
daf0dd781bf403f7c1bb668925caa64d
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); long vertexes = in.nextLong(); long edges = in.nextLong(); long max = 0; if (edges == 0) { System.out.println(vertexes + " " + vertexes); return; } for (long i = 1; i < vertexes; i++) { long currentEdges = (i * (i - 1)) / 2; if (currentEdges >= edges) { max = vertexes - i; break; } } for (long i = 0; i < edges; i++) { vertexes -= 2; if (vertexes < 0) { break; } } vertexes = vertexes > 0 ? vertexes : 0; System.out.println(vertexes + " " + max); } }
["0 1", "1 1"]
Java
NoteIn the first example it is possible to construct a graph with $$$0$$$ isolated vertices: for example, it should contain edges $$$(1, 2)$$$ and $$$(3, 4)$$$. To get one isolated vertex, we may construct a graph with edges $$$(1, 2)$$$ and $$$(1, 3)$$$. In the second example the graph will always contain exactly one isolated vertex.
In the only line print two numbers $$$min$$$ and $$$max$$$ β€” the minimum and maximum number of isolated vertices, respectively.
Vasya has got an undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. This graph doesn't contain any self-loops or multiple edges. Self-loop is an edge connecting a vertex to itself. Multiple edges are a pair of edges such that they connect the same pair of vertices. Since the graph is undirected, the pair of edges $$$(1, 2)$$$ and $$$(2, 1)$$$ is considered to be multiple edges. Isolated vertex of the graph is a vertex such that there is no edge connecting this vertex to any other vertex.Vasya wants to know the minimum and maximum possible number of isolated vertices in an undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges.
[{"input": "4 2\r\n", "output": ["0 1"]}, {"input": "3 1\r\n", "output": ["1 1"]}, {"input": "20 55\r\n", "output": ["0 9"]}, {"input": "20 54\r\n", "output": ["0 9"]}, {"input": "20 56\r\n", "output": ["0 8"]}, {"input": "100000 3950493829\r\n", "output": ["0 11111"]}, {"input": "100000 49997\r\n", "output": ["6 99683"]}, {"input": "100 0\r\n", "output": ["100 100"]}, {"input": "1 0\r\n", "output": ["1 1"]}, {"input": "15 4\r\n", "output": ["7 11"]}, {"input": "100000 4999950000\r\n", "output": ["0 0"]}, {"input": "18889 138011083\r\n", "output": ["0 2274"]}, {"input": "100 100\r\n", "output": ["0 85"]}, {"input": "5 5\r\n", "output": ["0 1"]}, {"input": "4 6\r\n", "output": ["0 0"]}, {"input": "2 1\r\n", "output": ["0 0"]}, {"input": "5 10\r\n", "output": ["0 0"]}, {"input": "10 2\r\n", "output": ["6 7"]}, {"input": "3 2\r\n", "output": ["0 0"]}, {"input": "6 15\r\n", "output": ["0 0"]}, {"input": "2 0\r\n", "output": ["2 2"]}, {"input": "6740 22710430\r\n", "output": ["0 0"]}, {"input": "10 45\r\n", "output": ["0 0"]}]
100
100
100
[{'input': '100000 3950493829\r\n', 'output': ['0 11111']}, {'input': '2 1\r\n', 'output': ['0 0']}, {'input': '5 10\r\n', 'output': ['0 0']}, {'input': '6 15\r\n', 'output': ['0 0']}, {'input': '5 5\r\n', 'output': ['0 1']}]
[{'input': '4 2\r\n', 'output': ['0 1']}, {'input': '100 100\r\n', 'output': ['0 85']}, {'input': '4 6\r\n', 'output': ['0 0']}, {'input': '3 1\r\n', 'output': ['1 1']}, {'input': '100000 4999950000\r\n', 'output': ['0 0']}]
[{'input': '5 10\r\n', 'output': ['0 0']}, {'input': '2 0\r\n', 'output': ['2 2']}, {'input': '6740 22710430\r\n', 'output': ['0 0']}, {'input': '10 45\r\n', 'output': ['0 0']}, {'input': '6 15\r\n', 'output': ['0 0']}]
[{'input': '1 0\r\n', 'output': ['1 1']}, {'input': '20 56\r\n', 'output': ['0 8']}, {'input': '5 5\r\n', 'output': ['0 1']}, {'input': '5 10\r\n', 'output': ['0 0']}, {'input': '15 4\r\n', 'output': ['7 11']}]
[{'input': '6 15\r\n', 'output': ['0 0']}, {'input': '1 0\r\n', 'output': ['1 1']}, {'input': '100000 4999950000\r\n', 'output': ['0 0']}, {'input': '5 5\r\n', 'output': ['0 1']}, {'input': '100 0\r\n', 'output': ['100 100']}]
100
100
100
100
100
89.47
89.47
89.47
100
100
83.33
91.67
75
100
83.33
295
100
93.682
86.666
["3 2\n50 85 250\n10 15 25", "3 6\n50 85 250\n10 15 25", "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76"]
The first line contains two integers n and c (1 ≀ n ≀ 50, 1 ≀ c ≀ 1000)Β β€” the number of problems and the constant representing the speed of loosing points. The second line contains n integers p1, p2, ..., pn (1 ≀ pi ≀ 1000, pi &lt; pi + 1)Β β€” initial scores. The third line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 1000, ti &lt; ti + 1) where ti denotes the number of minutes one needs to solve the i-th problem.
8c704de75ab85f9e2c04a926143c8b4a
import java.util.Scanner; public class A17 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int c = sc.nextInt(); int[] score = new int[n]; int[] minute = new int[n]; for (int i = 0; i < n; i++) { score[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { minute[i] = sc.nextInt(); } int Limak = 0; int l; int currmin = 0; for (int i = 0; i < n; i++) { currmin += minute[i]; l = score[i] - (c * currmin); if (l > 0) { Limak += l; } } int Radewoosh = 0; int r; int curr = 0; for (int i = n - 1; i >= 0; i--) { curr += minute[i]; r = score[i] - (c * curr); if (r > 0) { Radewoosh += r; } } if (Radewoosh == Limak) { System.out.println("Tie"); } else System.out.println((Radewoosh > Limak) ? "Radewoosh" : "Limak"); } }
["Limak", "Radewoosh", "Tie"]
Java
NoteIn the first sample, there are 3 problems. Limak solves them as follows: Limak spends 10 minutes on the 1-st problem and he gets 50 - cΒ·10 = 50 - 2Β·10 = 30 points. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85 - 2Β·25 = 35 points. He spends 25 minutes on the 3-rd problem so he submits it 10 + 15 + 25 = 50 minutes after the start. For this problem he gets 250 - 2Β·50 = 150 points. So, Limak got 30 + 35 + 150 = 215 points.Radewoosh solves problem in the reversed order: Radewoosh solves 3-rd problem after 25 minutes so he gets 250 - 2Β·25 = 200 points. He spends 15 minutes on the 2-nd problem so he submits it 25 + 15 = 40 minutes after the start. He gets 85 - 2Β·40 = 5 points for this problem. He spends 10 minutes on the 1-st problem so he submits it 25 + 15 + 10 = 50 minutes after the start. He gets max(0, 50 - 2Β·50) = max(0,  - 50) = 0 points. Radewoosh got 200 + 5 + 0 = 205 points in total. Limak has 215 points so Limak wins.In the second sample, Limak will get 0 points for each problem and Radewoosh will first solve the hardest problem and he will get 250 - 6Β·25 = 100 points for that. Radewoosh will get 0 points for other two problems but he is the winner anyway.In the third sample, Limak will get 2 points for the 1-st problem and 2 points for the 2-nd problem. Radewoosh will get 4 points for the 8-th problem. They won't get points for other problems and thus there is a tie because 2 + 2 = 4.
Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points.
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.There will be n problems. The i-th problem has initial score pi and it takes exactly ti minutes to solve it. Problems are sorted by difficultyΒ β€” it's guaranteed that pi &lt; pi + 1 and ti &lt; ti + 1.A constant c is given too, representing the speed of loosing points. Then, submitting the i-th problem at time x (x minutes after the start of the contest) gives max(0,  pi - cΒ·x) points.Limak is going to solve problems in order 1, 2, ..., n (sorted increasingly by pi). Radewoosh is going to solve them in order n, n - 1, ..., 1 (sorted decreasingly by pi). Your task is to predict the outcomeΒ β€” print the name of the winner (person who gets more points at the end) or a word "Tie" in case of a tie.You may assume that the duration of the competition is greater or equal than the sum of all ti. That means both Limak and Radewoosh will accept all n problems.
[{"input": "3 2\r\n50 85 250\r\n10 15 25\r\n", "output": ["Limak"]}, {"input": "3 6\r\n50 85 250\r\n10 15 25\r\n", "output": ["Radewoosh"]}, {"input": "8 1\r\n10 20 30 40 50 60 70 80\r\n8 10 58 63 71 72 75 76\r\n", "output": ["Tie"]}, {"input": "4 1\r\n3 5 6 9\r\n1 2 4 8\r\n", "output": ["Limak"]}, {"input": "4 1\r\n1 3 6 10\r\n1 5 7 8\r\n", "output": ["Radewoosh"]}, {"input": "4 1\r\n2 4 5 10\r\n2 3 9 10\r\n", "output": ["Tie"]}, {"input": "18 4\r\n68 97 121 132 146 277 312 395 407 431 458 461 595 634 751 855 871 994\r\n1 2 3 4 9 10 13 21 22 29 31 34 37 38 39 41 48 49\r\n", "output": ["Radewoosh"]}, {"input": "50 1\r\n5 14 18 73 137 187 195 197 212 226 235 251 262 278 287 304 310 322 342 379 393 420 442 444 448 472 483 485 508 515 517 523 559 585 618 627 636 646 666 682 703 707 780 853 937 951 959 989 991 992\r\n30 84 113 173 199 220 235 261 266 277 300 306 310 312 347 356 394 396 397 409 414 424 446 462 468 487 507 517 537 566 594 643 656 660 662 668 706 708 773 774 779 805 820 827 868 896 929 942 961 995\r\n", "output": ["Tie"]}, {"input": "4 1\r\n4 6 9 10\r\n2 3 4 5\r\n", "output": ["Radewoosh"]}, {"input": "4 1\r\n4 6 9 10\r\n3 4 5 7\r\n", "output": ["Radewoosh"]}, {"input": "4 1\r\n1 6 7 10\r\n2 7 8 10\r\n", "output": ["Tie"]}, {"input": "4 1\r\n4 5 7 9\r\n1 4 5 8\r\n", "output": ["Limak"]}, {"input": "50 1\r\n6 17 44 82 94 127 134 156 187 211 212 252 256 292 294 303 352 355 379 380 398 409 424 434 480 524 584 594 631 714 745 756 777 778 789 793 799 821 841 849 859 878 879 895 925 932 944 952 958 990\r\n15 16 40 42 45 71 99 100 117 120 174 181 186 204 221 268 289 332 376 394 403 409 411 444 471 487 499 539 541 551 567 589 619 623 639 669 689 722 735 776 794 822 830 840 847 907 917 927 936 988\r\n", "output": ["Radewoosh"]}, {"input": "50 10\r\n25 49 52 73 104 117 127 136 149 164 171 184 226 251 257 258 286 324 337 341 386 390 428 453 464 470 492 517 543 565 609 634 636 660 678 693 710 714 729 736 739 749 781 836 866 875 956 960 977 979\r\n2 4 7 10 11 22 24 26 27 28 31 35 37 38 42 44 45 46 52 53 55 56 57 59 60 61 64 66 67 68 69 71 75 76 77 78 79 81 83 85 86 87 89 90 92 93 94 98 99 100\r\n", "output": ["Limak"]}, {"input": "50 10\r\n11 15 25 71 77 83 95 108 143 150 182 183 198 203 213 223 279 280 346 348 350 355 375 376 412 413 415 432 470 545 553 562 589 595 607 633 635 637 688 719 747 767 771 799 842 883 905 924 942 944\r\n1 3 5 6 7 10 11 12 13 14 15 16 19 20 21 23 25 32 35 36 37 38 40 41 42 43 47 50 51 54 55 56 57 58 59 60 62 63 64 65 66 68 69 70 71 72 73 75 78 80\r\n", "output": ["Radewoosh"]}, {"input": "32 6\r\n25 77 141 148 157 159 192 196 198 244 245 255 332 392 414 457 466 524 575 603 629 700 738 782 838 841 845 847 870 945 984 985\r\n1 2 4 5 8 9 10 12 13 14 15 16 17 18 20 21 22 23 24 26 28 31 38 39 40 41 42 43 45 47 48 49\r\n", "output": ["Radewoosh"]}, {"input": "5 1\r\n256 275 469 671 842\r\n7 9 14 17 26\r\n", "output": ["Limak"]}, {"input": "2 1000\r\n1 2\r\n1 2\r\n", "output": ["Tie"]}, {"input": "3 1\r\n1 50 809\r\n2 8 800\r\n", "output": ["Limak"]}, {"input": "1 13\r\n866\r\n10\r\n", "output": ["Tie"]}, {"input": "15 1\r\n9 11 66 128 199 323 376 386 393 555 585 718 935 960 971\r\n3 11 14 19 20 21 24 26 32 38 40 42 44 47 50\r\n", "output": ["Limak"]}, {"input": "1 10\r\n546\r\n45\r\n", "output": ["Tie"]}, {"input": "50 20\r\n21 43 51 99 117 119 158 167 175 190 196 244 250 316 335 375 391 403 423 428 451 457 460 480 487 522 539 559 566 584 598 602 604 616 626 666 675 730 771 787 828 841 861 867 886 889 898 970 986 991\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50\r\n", "output": ["Limak"]}, {"input": "50 21\r\n13 20 22 38 62 84 118 135 141 152 170 175 194 218 227 229 232 253 260 263 278 313 329 357 396 402 422 452 454 533 575 576 580 594 624 644 653 671 676 759 789 811 816 823 831 833 856 924 933 987\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50\r\n", "output": ["Tie"]}, {"input": "1 36\r\n312\r\n42\r\n", "output": ["Tie"]}, {"input": "1 1000\r\n1\r\n1000\r\n", "output": ["Tie"]}, {"input": "1 1\r\n1000\r\n1\r\n", "output": ["Tie"]}, {"input": "50 35\r\n9 17 28 107 136 152 169 174 186 188 201 262 291 312 324 330 341 358 385 386 393 397 425 431 479 498 502 523 530 540 542 554 578 588 622 623 684 696 709 722 784 819 836 845 850 932 945 969 983 984\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50\r\n", "output": ["Tie"]}, {"input": "50 20\r\n12 113 116 120 138 156 167 183 185 194 211 228 234 261 278 287 310 317 346 361 364 397 424 470 496 522 527 536 611 648 668 704 707 712 717 752 761 766 815 828 832 864 872 885 889 901 904 929 982 993\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50\r\n", "output": ["Limak"]}]
100
100
100
[{'input': '1 13\r\n866\r\n10\r\n', 'output': ['Tie']}, {'input': '1 10\r\n546\r\n45\r\n', 'output': ['Tie']}, {'input': '4 1\r\n4 6 9 10\r\n3 4 5 7\r\n', 'output': ['Radewoosh']}, {'input': '3 2\r\n50 85 250\r\n10 15 25\r\n', 'output': ['Limak']}, {'input': '50 20\r\n21 43 51 99 117 119 158 167 175 190 196 244 250 316 335 375 391 403 423 428 451 457 460 480 487 522 539 559 566 584 598 602 604 616 626 666 675 730 771 787 828 841 861 867 886 889 898 970 986 991\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50\r\n', 'output': ['Limak']}]
[{'input': '4 1\r\n3 5 6 9\r\n1 2 4 8\r\n', 'output': ['Limak']}, {'input': '4 1\r\n4 6 9 10\r\n2 3 4 5\r\n', 'output': ['Radewoosh']}, {'input': '50 35\r\n9 17 28 107 136 152 169 174 186 188 201 262 291 312 324 330 341 358 385 386 393 397 425 431 479 498 502 523 530 540 542 554 578 588 622 623 684 696 709 722 784 819 836 845 850 932 945 969 983 984\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50\r\n', 'output': ['Tie']}, {'input': '50 10\r\n11 15 25 71 77 83 95 108 143 150 182 183 198 203 213 223 279 280 346 348 350 355 375 376 412 413 415 432 470 545 553 562 589 595 607 633 635 637 688 719 747 767 771 799 842 883 905 924 942 944\r\n1 3 5 6 7 10 11 12 13 14 15 16 19 20 21 23 25 32 35 36 37 38 40 41 42 43 47 50 51 54 55 56 57 58 59 60 62 63 64 65 66 68 69 70 71 72 73 75 78 80\r\n', 'output': ['Radewoosh']}, {'input': '3 6\r\n50 85 250\r\n10 15 25\r\n', 'output': ['Radewoosh']}]
[{'input': '32 6\r\n25 77 141 148 157 159 192 196 198 244 245 255 332 392 414 457 466 524 575 603 629 700 738 782 838 841 845 847 870 945 984 985\r\n1 2 4 5 8 9 10 12 13 14 15 16 17 18 20 21 22 23 24 26 28 31 38 39 40 41 42 43 45 47 48 49\r\n', 'output': ['Radewoosh']}, {'input': '50 20\r\n21 43 51 99 117 119 158 167 175 190 196 244 250 316 335 375 391 403 423 428 451 457 460 480 487 522 539 559 566 584 598 602 604 616 626 666 675 730 771 787 828 841 861 867 886 889 898 970 986 991\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50\r\n', 'output': ['Limak']}, {'input': '15 1\r\n9 11 66 128 199 323 376 386 393 555 585 718 935 960 971\r\n3 11 14 19 20 21 24 26 32 38 40 42 44 47 50\r\n', 'output': ['Limak']}, {'input': '8 1\r\n10 20 30 40 50 60 70 80\r\n8 10 58 63 71 72 75 76\r\n', 'output': ['Tie']}, {'input': '4 1\r\n4 6 9 10\r\n2 3 4 5\r\n', 'output': ['Radewoosh']}]
[{'input': '4 1\r\n3 5 6 9\r\n1 2 4 8\r\n', 'output': ['Limak']}, {'input': '4 1\r\n1 6 7 10\r\n2 7 8 10\r\n', 'output': ['Tie']}, {'input': '3 1\r\n1 50 809\r\n2 8 800\r\n', 'output': ['Limak']}, {'input': '50 1\r\n5 14 18 73 137 187 195 197 212 226 235 251 262 278 287 304 310 322 342 379 393 420 442 444 448 472 483 485 508 515 517 523 559 585 618 627 636 646 666 682 703 707 780 853 937 951 959 989 991 992\r\n30 84 113 173 199 220 235 261 266 277 300 306 310 312 347 356 394 396 397 409 414 424 446 462 468 487 507 517 537 566 594 643 656 660 662 668 706 708 773 774 779 805 820 827 868 896 929 942 961 995\r\n', 'output': ['Tie']}, {'input': '1 10\r\n546\r\n45\r\n', 'output': ['Tie']}]
[{'input': '50 20\r\n21 43 51 99 117 119 158 167 175 190 196 244 250 316 335 375 391 403 423 428 451 457 460 480 487 522 539 559 566 584 598 602 604 616 626 666 675 730 771 787 828 841 861 867 886 889 898 970 986 991\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50\r\n', 'output': ['Limak']}, {'input': '50 1\r\n5 14 18 73 137 187 195 197 212 226 235 251 262 278 287 304 310 322 342 379 393 420 442 444 448 472 483 485 508 515 517 523 559 585 618 627 636 646 666 682 703 707 780 853 937 951 959 989 991 992\r\n30 84 113 173 199 220 235 261 266 277 300 306 310 312 347 356 394 396 397 409 414 424 446 462 468 487 507 517 537 566 594 643 656 660 662 668 706 708 773 774 779 805 820 827 868 896 929 942 961 995\r\n', 'output': ['Tie']}, {'input': '50 20\r\n12 113 116 120 138 156 167 183 185 194 211 228 234 261 278 287 310 317 346 361 364 397 424 470 496 522 527 536 611 648 668 704 707 712 717 752 761 766 815 828 832 864 872 885 889 901 904 929 982 993\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50\r\n', 'output': ['Limak']}, {'input': '3 2\r\n50 85 250\r\n10 15 25\r\n', 'output': ['Limak']}, {'input': '4 1\r\n1 3 6 10\r\n1 5 7 8\r\n', 'output': ['Radewoosh']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
93.75
100
296
100
100
98.75
["6\n1 2 4 3 3 2", "1\n100"]
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β€” the number of coins. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$) β€” values of coins.
f30329023e84b4c50b1b118dc98ae73c
import java.util.*; public class Watermelon { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[] = new int[n]; int c[] = new int[101]; for(int i=0; i<n; i++) { a[i] = sc.nextInt(); c[a[i]]++; } int max = 0; for(int i=0; i<101; i++) { if(c[i]>max) max = c[i]; } System.out.println(max); } }
["2", "1"]
Java
null
Print only one integer β€” the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
Polycarp has $$$n$$$ coins, the value of the $$$i$$$-th coin is $$$a_i$$$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.For example, if Polycarp has got six coins represented as an array $$$a = [1, 2, 4, 3, 3, 2]$$$, he can distribute the coins into two pockets as follows: $$$[1, 2, 3], [2, 3, 4]$$$.Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.
[{"input": "6\r\n1 2 4 3 3 2\r\n", "output": ["2"]}, {"input": "1\r\n100\r\n", "output": ["1"]}, {"input": "100\r\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\r\n", "output": ["100"]}, {"input": "100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["100"]}, {"input": "100\r\n59 47 39 47 47 71 47 28 58 47 35 79 58 47 38 47 47 47 47 27 47 43 29 95 47 49 46 71 47 74 79 47 47 32 45 67 47 47 30 37 47 47 16 67 22 76 47 86 84 10 5 47 47 47 47 47 1 51 47 54 47 8 47 47 9 47 47 47 47 28 47 47 26 47 47 47 47 47 47 92 47 47 77 47 47 24 45 47 10 47 47 89 47 27 47 89 47 67 24 71\r\n", "output": ["51"]}, {"input": "100\r\n45 99 10 27 16 85 39 38 17 32 15 23 67 48 50 97 42 70 62 30 44 81 64 73 34 22 46 5 83 52 58 60 33 74 47 88 18 61 78 53 25 95 94 31 3 75 1 57 20 54 59 9 68 7 77 43 21 87 86 24 4 80 11 49 2 72 36 84 71 8 65 55 79 100 41 14 35 89 66 69 93 37 56 82 90 91 51 19 26 92 6 96 13 98 12 28 76 40 63 29\r\n", "output": ["1"]}, {"input": "100\r\n45 29 5 2 6 50 22 36 14 15 9 48 46 20 8 37 7 47 12 50 21 38 18 27 33 19 40 10 5 49 38 42 34 37 27 30 35 24 10 3 40 49 41 3 4 44 13 25 28 31 46 36 23 1 1 23 7 22 35 26 21 16 48 42 32 8 11 16 34 11 39 32 47 28 43 41 39 4 14 19 26 45 13 18 15 25 2 44 17 29 17 33 43 6 12 30 9 20 31 24\r\n", "output": ["2"]}, {"input": "50\r\n7 7 3 3 7 4 5 6 4 3 7 5 6 4 5 4 4 5 6 7 7 7 4 5 5 5 3 7 6 3 4 6 3 6 4 4 5 4 6 6 3 5 6 3 5 3 3 7 7 6\r\n", "output": ["10"]}, {"input": "100\r\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\r\n", "output": ["99"]}, {"input": "7\r\n1 2 3 3 3 1 2\r\n", "output": ["3"]}, {"input": "5\r\n1 2 3 4 5\r\n", "output": ["1"]}, {"input": "7\r\n1 2 3 4 5 6 7\r\n", "output": ["1"]}, {"input": "8\r\n1 2 3 4 5 6 7 8\r\n", "output": ["1"]}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": ["1"]}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": ["1"]}, {"input": "3\r\n2 1 1\r\n", "output": ["2"]}, {"input": "11\r\n1 2 3 4 5 6 7 8 9 1 1\r\n", "output": ["3"]}, {"input": "12\r\n1 2 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["11"]}, {"input": "13\r\n1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["13"]}, {"input": "14\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["14"]}, {"input": "15\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["15"]}, {"input": "16\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["16"]}, {"input": "3\r\n1 1 1\r\n", "output": ["3"]}, {"input": "3\r\n1 2 3\r\n", "output": ["1"]}, {"input": "10\r\n1 1 1 1 2 2 1 1 9 10\r\n", "output": ["6"]}, {"input": "2\r\n1 1\r\n", "output": ["2"]}, {"input": "56\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["56"]}, {"input": "99\r\n35 96 73 72 70 83 22 93 98 75 45 32 81 82 45 54 25 7 53 72 29 2 94 19 21 98 34 28 39 99 55 85 44 23 6 47 98 2 33 34 19 57 49 35 67 4 60 4 4 23 55 6 57 66 16 68 34 45 84 79 48 63 4 9 46 88 98 13 19 27 83 12 4 63 57 22 44 77 44 62 28 52 44 64 9 24 55 22 48 4 2 9 80 76 45 1 56 22 92\r\n", "output": ["6"]}, {"input": "10\r\n1 2 2 3 3 3 4 4 4 4\r\n", "output": ["4"]}, {"input": "99\r\n97 44 33 56 42 10 61 85 64 26 40 39 82 34 75 9 51 51 39 73 58 38 74 31 13 99 58 1 28 89 76 19 52 7 40 56 12 27 72 72 67 75 62 46 22 55 35 16 18 39 60 63 92 42 85 69 34 61 73 50 57 95 30 4 45 63 76 58 32 35 48 81 10 78 95 79 55 97 21 21 22 94 30 17 78 57 89 93 100 44 16 89 68 55 19 46 42 73 21\r\n", "output": ["3"]}, {"input": "5\r\n5 5 5 5 1\r\n", "output": ["4"]}, {"input": "6\r\n2 3 2 5 2 6\r\n", "output": ["3"]}, {"input": "3\r\n58 59 58\r\n", "output": ["2"]}, {"input": "9\r\n1 2 3 4 5 6 7 8 8\r\n", "output": ["2"]}, {"input": "97\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": ["97"]}, {"input": "3\r\n95 95 4\r\n", "output": ["2"]}, {"input": "3\r\n2 2 5\r\n", "output": ["2"]}]
100
100
100
[{'input': '11\r\n1 2 3 4 5 6 7 8 9 1 1\r\n', 'output': ['3']}, {'input': '100\r\n45 29 5 2 6 50 22 36 14 15 9 48 46 20 8 37 7 47 12 50 21 38 18 27 33 19 40 10 5 49 38 42 34 37 27 30 35 24 10 3 40 49 41 3 4 44 13 25 28 31 46 36 23 1 1 23 7 22 35 26 21 16 48 42 32 8 11 16 34 11 39 32 47 28 43 41 39 4 14 19 26 45 13 18 15 25 2 44 17 29 17 33 43 6 12 30 9 20 31 24\r\n', 'output': ['2']}, {'input': '5\r\n5 5 5 5 1\r\n', 'output': ['4']}, {'input': '7\r\n1 2 3 3 3 1 2\r\n', 'output': ['3']}, {'input': '7\r\n1 2 3 4 5 6 7\r\n', 'output': ['1']}]
[{'input': '56\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n', 'output': ['56']}, {'input': '16\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n', 'output': ['16']}, {'input': '14\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n', 'output': ['14']}, {'input': '100\r\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\r\n', 'output': ['100']}, {'input': '3\r\n1 2 3\r\n', 'output': ['1']}]
[{'input': '6\r\n1 2 4 3 3 2\r\n', 'output': ['2']}, {'input': '1\r\n100\r\n', 'output': ['1']}, {'input': '99\r\n35 96 73 72 70 83 22 93 98 75 45 32 81 82 45 54 25 7 53 72 29 2 94 19 21 98 34 28 39 99 55 85 44 23 6 47 98 2 33 34 19 57 49 35 67 4 60 4 4 23 55 6 57 66 16 68 34 45 84 79 48 63 4 9 46 88 98 13 19 27 83 12 4 63 57 22 44 77 44 62 28 52 44 64 9 24 55 22 48 4 2 9 80 76 45 1 56 22 92\r\n', 'output': ['6']}, {'input': '6\r\n2 3 2 5 2 6\r\n', 'output': ['3']}, {'input': '11\r\n1 2 3 4 5 6 7 8 9 1 1\r\n', 'output': ['3']}]
[{'input': '10\r\n1 2 3 4 5 6 7 8 9 10\r\n', 'output': ['1']}, {'input': '7\r\n1 2 3 4 5 6 7\r\n', 'output': ['1']}, {'input': '99\r\n35 96 73 72 70 83 22 93 98 75 45 32 81 82 45 54 25 7 53 72 29 2 94 19 21 98 34 28 39 99 55 85 44 23 6 47 98 2 33 34 19 57 49 35 67 4 60 4 4 23 55 6 57 66 16 68 34 45 84 79 48 63 4 9 46 88 98 13 19 27 83 12 4 63 57 22 44 77 44 62 28 52 44 64 9 24 55 22 48 4 2 9 80 76 45 1 56 22 92\r\n', 'output': ['6']}, {'input': '3\r\n2 2 5\r\n', 'output': ['2']}, {'input': '6\r\n2 3 2 5 2 6\r\n', 'output': ['3']}]
[{'input': '14\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n', 'output': ['14']}, {'input': '6\r\n1 2 4 3 3 2\r\n', 'output': ['2']}, {'input': '1\r\n100\r\n', 'output': ['1']}, {'input': '7\r\n1 2 3 3 3 1 2\r\n', 'output': ['3']}, {'input': '7\r\n1 2 3 4 5 6 7\r\n', 'output': ['1']}]
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
297
100
100
100
["3 4", "2 1"]
The only line contains two integers $$$N$$$ and $$$M$$$ ($$$1 \leq N, M \leq 10^9$$$) β€” the number of rows and columns in the grid.
a91aab4c0618d036c81022232814ef44
import java.util.*; import java.math.*; public class Dominoes { public static void main(String[] args) { Scanner o = new Scanner(System.in); int n = o.nextInt(), m = o.nextInt(); BigInteger b1 = BigInteger.valueOf(n), b2 = BigInteger.valueOf(m); if( n == 1 && m == 1) System.out.println(0); else if( m == 1 ) System.out.println(n - 1); else System.out.println(BigInteger.valueOf(m - 1).multiply(b1)); } }
["9", "1"]
Java
NoteThe picture below is the grid that Pak Chanek has in the first example. The picture below is an example of a tight domino in the grid.
An integer representing the number of distinct tight dominoes in the grid.
Pak Chanek has a grid that has $$$N$$$ rows and $$$M$$$ columns. Each row is numbered from $$$1$$$ to $$$N$$$ from top to bottom. Each column is numbered from $$$1$$$ to $$$M$$$ from left to right.Each tile in the grid contains a number. The numbers are arranged as follows: Row $$$1$$$ contains integers from $$$1$$$ to $$$M$$$ from left to right. Row $$$2$$$ contains integers from $$$M+1$$$ to $$$2 \times M$$$ from left to right. Row $$$3$$$ contains integers from $$$2 \times M+1$$$ to $$$3 \times M$$$ from left to right. And so on until row $$$N$$$. A domino is defined as two different tiles in the grid that touch by their sides. A domino is said to be tight if and only if the two numbers in the domino have a difference of exactly $$$1$$$. Count the number of distinct tight dominoes in the grid.Two dominoes are said to be distinct if and only if there exists at least one tile that is in one domino, but not in the other.
[{"input": "3 4\n", "output": ["\n9", "9", "9\n\n", "9\n\n", "\n\n\n9\n", "9\n", "\n9\n", "\n\n\n\n\n\n\n\n9\n", "9\n"]}, {"input": "2 1\n", "output": ["\n1", "1\n", "1", "1\n\n", "\n1\n", "1\n\n", "\n\n1\n", "1\n", "\n\n\n\n\n1\n"]}, {"input": "1 1\n", "output": ["\n0\n", "\n0", "0\n\n", "0\n\n", "0\n", "0\n", "\n\n0\n", "0"]}, {"input": "1 2\n", "output": ["\n1", "1\n", "1", "1\n\n", "\n1\n", "1\n\n", "\n\n1\n", "1\n"]}, {"input": "2 2\n", "output": ["2\n", "2", "\n\n\n\n\n2\n", "2\n\n", "\n\n2\n", "\n2", "2\n\n", "\n2\n", "2\n"]}, {"input": "1 1000000000\n", "output": ["999999999\n", "\n999999999\n", "\n999999999", "999999999\n", "999999999\n\n", "999999999", "999999999\n\n"]}, {"input": "1 999999997\n", "output": ["999999996\n\n", "\n999999996", "999999996\n\n", "999999996\n", "999999996\n", "\n999999996\n", "999999996"]}, {"input": "1 589284012\n", "output": ["589284011\n", "\n589284011", "589284011", "589284011\n\n", "589284011\n\n", "\n589284011\n", "589284011\n"]}, {"input": "1000000000 1\n", "output": ["999999999\n", "\n999999999\n", "\n999999999", "999999999\n", "999999999\n\n", "999999999", "999999999\n\n"]}, {"input": "999999999 1\n", "output": ["\n999999998", "\n999999998\n", "999999998", "999999998\n\n", "999999998\n", "999999998\n\n", "999999998\n"]}, {"input": "636562060 1\n", "output": ["\n636562059", "636562059\n\n", "636562059\n", "636562059", "\n636562059\n", "636562059\n", "636562059\n\n"]}, {"input": "2 1000000000\n", "output": ["1999999998\n\n", "\n1999999998\n", "1999999998\n", "1999999998", "1999999998\n", "\n1999999998", "1999999998\n\n"]}, {"input": "1000000000 2\n", "output": ["1000000000", "1000000000\n\n", "1000000000\n", "1000000000\n", "\n1000000000", "\n1000000000\n", "1000000000\n\n"]}, {"input": "30001 30001\n", "output": ["900030000\n", "\n900030000\n", "900030000", "\n900030000", "900030000\n\n", "900030000\n\n", "900030000\n"]}, {"input": "1000000000 1000000000\n", "output": ["999999999000000000\n", "999999999000000000\n\n", "999999999000000000\n\n", "999999999000000000\n", "999999999000000000"]}, {"input": "767928735 1000000000\n", "output": ["767928734232071265\n\n", "767928734232071265\n", "767928734232071265\n\n", "767928734232071265\n", "767928734232071265"]}, {"input": "1000000000 906523442\n", "output": ["906523441000000000\n\n", "906523441000000000", "906523441000000000\n", "906523441000000000\n\n", "906523441000000000\n"]}, {"input": "647242241 921242095\n", "output": ["596266797424092654\n", "596266797424092654\n\n", "596266797424092654\n", "596266797424092654", "596266797424092654\n\n"]}]
100
100
100
[{'input': '636562060 1\n', 'output': ['\n636562059', '636562059\n\n', '636562059\n', '636562059', '\n636562059\n', '636562059\n', '636562059\n\n']}, {'input': '2 1\n', 'output': ['\n1', '1\n', '1', '1\n\n', '\n1\n', '1\n\n', '\n\n1\n', '1\n', '\n\n\n\n\n1\n']}, {'input': '1000000000 1000000000\n', 'output': ['999999999000000000\n', '999999999000000000\n\n', '999999999000000000\n\n', '999999999000000000\n', '999999999000000000']}, {'input': '2 1000000000\n', 'output': ['1999999998\n\n', '\n1999999998\n', '1999999998\n', '1999999998', '1999999998\n', '\n1999999998', '1999999998\n\n']}, {'input': '30001 30001\n', 'output': ['900030000\n', '\n900030000\n', '900030000', '\n900030000', '900030000\n\n', '900030000\n\n', '900030000\n']}]
[{'input': '1 2\n', 'output': ['\n1', '1\n', '1', '1\n\n', '\n1\n', '1\n\n', '\n\n1\n', '1\n']}, {'input': '1000000000 1\n', 'output': ['999999999\n', '\n999999999\n', '\n999999999', '999999999\n', '999999999\n\n', '999999999', '999999999\n\n']}, {'input': '3 4\n', 'output': ['\n9', '9', '9\n\n', '9\n\n', '\n\n\n9\n', '9\n', '\n9\n', '\n\n\n\n\n\n\n\n9\n', '9\n']}, {'input': '1 589284012\n', 'output': ['589284011\n', '\n589284011', '589284011', '589284011\n\n', '589284011\n\n', '\n589284011\n', '589284011\n']}, {'input': '1000000000 906523442\n', 'output': ['906523441000000000\n\n', '906523441000000000', '906523441000000000\n', '906523441000000000\n\n', '906523441000000000\n']}]
[{'input': '1 589284012\n', 'output': ['589284011\n', '\n589284011', '589284011', '589284011\n\n', '589284011\n\n', '\n589284011\n', '589284011\n']}, {'input': '1000000000 1000000000\n', 'output': ['999999999000000000\n', '999999999000000000\n\n', '999999999000000000\n\n', '999999999000000000\n', '999999999000000000']}, {'input': '1 999999997\n', 'output': ['999999996\n\n', '\n999999996', '999999996\n\n', '999999996\n', '999999996\n', '\n999999996\n', '999999996']}, {'input': '1000000000 2\n', 'output': ['1000000000', '1000000000\n\n', '1000000000\n', '1000000000\n', '\n1000000000', '\n1000000000\n', '1000000000\n\n']}, {'input': '767928735 1000000000\n', 'output': ['767928734232071265\n\n', '767928734232071265\n', '767928734232071265\n\n', '767928734232071265\n', '767928734232071265']}]
[{'input': '2 1000000000\n', 'output': ['1999999998\n\n', '\n1999999998\n', '1999999998\n', '1999999998', '1999999998\n', '\n1999999998', '1999999998\n\n']}, {'input': '636562060 1\n', 'output': ['\n636562059', '636562059\n\n', '636562059\n', '636562059', '\n636562059\n', '636562059\n', '636562059\n\n']}, {'input': '2 2\n', 'output': ['2\n', '2', '\n\n\n\n\n2\n', '2\n\n', '\n\n2\n', '\n2', '2\n\n', '\n2\n', '2\n']}, {'input': '1 1000000000\n', 'output': ['999999999\n', '\n999999999\n', '\n999999999', '999999999\n', '999999999\n\n', '999999999', '999999999\n\n']}, {'input': '1 1\n', 'output': ['\n0\n', '\n0', '0\n\n', '0\n\n', '0\n', '0\n', '\n\n0\n', '0']}]
[{'input': '1000000000 1\n', 'output': ['999999999\n', '\n999999999\n', '\n999999999', '999999999\n', '999999999\n\n', '999999999', '999999999\n\n']}, {'input': '1 1000000000\n', 'output': ['999999999\n', '\n999999999\n', '\n999999999', '999999999\n', '999999999\n\n', '999999999', '999999999\n\n']}, {'input': '30001 30001\n', 'output': ['900030000\n', '\n900030000\n', '900030000', '\n900030000', '900030000\n\n', '900030000\n\n', '900030000\n']}, {'input': '636562060 1\n', 'output': ['\n636562059', '636562059\n\n', '636562059\n', '636562059', '\n636562059\n', '636562059\n', '636562059\n\n']}, {'input': '3 4\n', 'output': ['\n9', '9', '9\n\n', '9\n\n', '\n\n\n9\n', '9\n', '\n9\n', '\n\n\n\n\n\n\n\n9\n', '9\n']}]
100
100
100
100
100
88.89
88.89
77.78
100
88.89
50
83.33
66.67
100
83.33
298
100
88.89
76.666
["3 3 1", "4 4 1", "6 7 2"]
The first and only line contains three integers: n, m, k (1 ≀ n, m, k ≀ 1000).
309d2d46086d526d160292717dfef308
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Main { public static void main (String[] args) throws java.lang.Exception { long mod = 1000000007; Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int k = in.nextInt(); if (k * 2 > n - 1 || k * 2 > m - 1) System.out.println("0"); else { long c[][] = new long [1001][1001]; c[0][0] = 1; for (int i = 1; i <= Math.max(n - 1, m - 1); ++i) { c[i][0] = 1; for (int j = 1; j <= i; ++j) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; } System.out.println((c[n - 1][2 * k] * c[m - 1][2 * k]) % mod); } } }
["1", "9", "75"]
Java
NoteTwo ways to play the game are considered different if the final pictures are different. In other words, if one way contains a rectangle that is not contained in the other way.In the first sample Anna, who performs her first and only move, has only one possible action plan β€” insert a 1 × 1 square inside the given 3 × 3 square.In the second sample Anna has as much as 9 variants: 4 ways to paint a 1 × 1 square, 2 ways to insert a 1 × 2 rectangle vertically, 2 more ways to insert it horizontally and one more way is to insert a 2 × 2 square.
Print the single number β€” the number of the ways to play the game. As this number can be very big, print the value modulo 1000000007 (109 + 7).
In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted n × m rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. During each move one should paint inside the last-painted rectangle a new lesser rectangle (along the grid lines). The new rectangle should have no common points with the previous one. Note that when we paint a rectangle, we always paint only the border, the rectangles aren't filled.Nobody wins the game β€” Anna and Maria simply play until they have done k moves in total. Count the number of different ways to play this game.
[{"input": "3 3 1\r\n", "output": ["1"]}, {"input": "4 4 1\r\n", "output": ["9"]}, {"input": "6 7 2\r\n", "output": ["75"]}, {"input": "5 5 3\r\n", "output": ["0"]}, {"input": "2 2 1\r\n", "output": ["0"]}, {"input": "999 999 499\r\n", "output": ["1"]}, {"input": "456 876 1000\r\n", "output": ["0"]}, {"input": "3 5 1\r\n", "output": ["6"]}, {"input": "5 7 2\r\n", "output": ["15"]}, {"input": "10 13 3\r\n", "output": ["77616"]}, {"input": "1000 1000 499\r\n", "output": ["998001"]}, {"input": "1000 1000 500\r\n", "output": ["0"]}, {"input": "3 1000 1\r\n", "output": ["498501"]}, {"input": "1000 3 1\r\n", "output": ["498501"]}, {"input": "998 1000 499\r\n", "output": ["0"]}, {"input": "1000 1000 250\r\n", "output": ["263321201"]}, {"input": "999 996 247\r\n", "output": ["729817056"]}, {"input": "86 564 16\r\n", "output": ["966200617"]}, {"input": "711 390 95\r\n", "output": ["187455436"]}, {"input": "963 415 36\r\n", "output": ["336772492"]}, {"input": "356 628 17\r\n", "output": ["665796305"]}, {"input": "214 538 33\r\n", "output": ["661877504"]}, {"input": "840 474 207\r\n", "output": ["895622621"]}, {"input": "589 898 280\r\n", "output": ["752764170"]}, {"input": "227 405 404\r\n", "output": ["0"]}, {"input": "351 286 60\r\n", "output": ["414370922"]}, {"input": "531 131 43\r\n", "output": ["102593830"]}, {"input": "980 811 236\r\n", "output": ["542553202"]}, {"input": "638 119 38\r\n", "output": ["73514263"]}, {"input": "897 301 47\r\n", "output": ["886904759"]}, {"input": "569 191 164\r\n", "output": ["0"]}, {"input": "409 92 105\r\n", "output": ["0"]}, {"input": "307 190 52\r\n", "output": ["186536168"]}, {"input": "354 923 125\r\n", "output": ["708700715"]}, {"input": "705 155 490\r\n", "output": ["0"]}, {"input": "188 413 35\r\n", "output": ["103598368"]}, {"input": "954 950 732\r\n", "output": ["0"]}, {"input": "580 1000 203\r\n", "output": ["693824000"]}, {"input": "104 935 326\r\n", "output": ["0"]}, {"input": "611 229 104\r\n", "output": ["737450171"]}, {"input": "277 939 15\r\n", "output": ["934000455"]}, {"input": "338 949 121\r\n", "output": ["67858020"]}, {"input": "734 917 148\r\n", "output": ["80695422"]}, {"input": "505 380 86\r\n", "output": ["926905224"]}, {"input": "340 124 41\r\n", "output": ["801948369"]}, {"input": "565 606 234\r\n", "output": ["509636173"]}, {"input": "956 926 201\r\n", "output": ["186215807"]}, {"input": "1000 1000 20\r\n", "output": ["155086097"]}, {"input": "1000 1000 1000\r\n", "output": ["0"]}, {"input": "1000 1000 100\r\n", "output": ["58573582"]}]
100
100
100
[{'input': '956 926 201\r\n', 'output': ['186215807']}, {'input': '5 7 2\r\n', 'output': ['15']}, {'input': '456 876 1000\r\n', 'output': ['0']}, {'input': '188 413 35\r\n', 'output': ['103598368']}, {'input': '589 898 280\r\n', 'output': ['752764170']}]
[{'input': '277 939 15\r\n', 'output': ['934000455']}, {'input': '954 950 732\r\n', 'output': ['0']}, {'input': '5 5 3\r\n', 'output': ['0']}, {'input': '611 229 104\r\n', 'output': ['737450171']}, {'input': '3 1000 1\r\n', 'output': ['498501']}]
[{'input': '611 229 104\r\n', 'output': ['737450171']}, {'input': '354 923 125\r\n', 'output': ['708700715']}, {'input': '580 1000 203\r\n', 'output': ['693824000']}, {'input': '734 917 148\r\n', 'output': ['80695422']}, {'input': '1000 1000 500\r\n', 'output': ['0']}]
[{'input': '705 155 490\r\n', 'output': ['0']}, {'input': '3 5 1\r\n', 'output': ['6']}, {'input': '356 628 17\r\n', 'output': ['665796305']}, {'input': '409 92 105\r\n', 'output': ['0']}, {'input': '86 564 16\r\n', 'output': ['966200617']}]
[{'input': '307 190 52\r\n', 'output': ['186536168']}, {'input': '3 3 1\r\n', 'output': ['1']}, {'input': '6 7 2\r\n', 'output': ['75']}, {'input': '840 474 207\r\n', 'output': ['895622621']}, {'input': '10 13 3\r\n', 'output': ['77616']}]
100
100
100
100
100
100
100
100
100
93.33
87.5
87.5
87.5
100
75
299
100
98.666
87.5
["3\n7 20 88", "9\n16 20 30 40 50 60 70 80 90", "9\n15 20 30 40 50 60 70 80 90"]
The first line of the input contains one integer n (1 ≀ n ≀ 90)Β β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 &lt; t2 &lt; ... tn ≀ 90), given in the increasing order.
5031b15e220f0ff6cc1dd3731ecdbf27
import static java.lang.System.*; import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(in); int n = sc.nextInt(); int sum = 0; int m = 0; while (n --> 0 && (m - (m = sc.nextInt())) * -1 <= 15) { sum = m; } if (n >= 0) { while (n --> 0) { sc.nextInt(); } } sum += 15; if (sum > 90) sum = 90; out.println(sum); } }
["35", "15", "90"]
Java
NoteIn the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.In the second sample, the first 15 minutes are boring.In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
Print the number of minutes Limak will watch the game.
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game.
[{"input": "3\r\n7 20 88\r\n", "output": ["35"]}, {"input": "9\r\n16 20 30 40 50 60 70 80 90\r\n", "output": ["15"]}, {"input": "9\r\n15 20 30 40 50 60 70 80 90\r\n", "output": ["90"]}, {"input": "30\r\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88\r\n", "output": ["90"]}, {"input": "60\r\n1 2 4 5 6 7 11 14 16 18 20 21 22 23 24 25 26 33 34 35 36 37 38 39 41 42 43 44 46 47 48 49 52 55 56 57 58 59 60 61 63 64 65 67 68 70 71 72 73 74 75 77 78 80 82 83 84 85 86 88\r\n", "output": ["90"]}, {"input": "90\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90\r\n", "output": ["90"]}, {"input": "1\r\n1\r\n", "output": ["16"]}, {"input": "5\r\n15 30 45 60 75\r\n", "output": ["90"]}, {"input": "6\r\n14 29 43 59 70 74\r\n", "output": ["58"]}, {"input": "1\r\n15\r\n", "output": ["30"]}, {"input": "1\r\n16\r\n", "output": ["15"]}, {"input": "14\r\n14 22 27 31 35 44 46 61 62 69 74 79 88 89\r\n", "output": ["90"]}, {"input": "76\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90\r\n", "output": ["90"]}, {"input": "1\r\n90\r\n", "output": ["15"]}, {"input": "6\r\n13 17 32 47 60 66\r\n", "output": ["81"]}, {"input": "84\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84\r\n", "output": ["90"]}, {"input": "9\r\n6 20 27 28 40 53 59 70 85\r\n", "output": ["90"]}, {"input": "12\r\n14 22 27 31 35 44 62 69 74 79 88 89\r\n", "output": ["59"]}, {"input": "5\r\n15 30 45 60 74\r\n", "output": ["89"]}, {"input": "72\r\n3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89\r\n", "output": ["54"]}, {"input": "8\r\n1 16 30 31 32 33 34 50\r\n", "output": ["49"]}, {"input": "12\r\n1 3 6 10 15 21 28 36 45 55 66 78\r\n", "output": ["90"]}, {"input": "25\r\n1 2 3 4 5 6 7 8 9 10 11 23 36 50 65 81 82 83 84 85 86 87 88 89 90\r\n", "output": ["80"]}, {"input": "8\r\n5 17 20 35 42 53 67 76\r\n", "output": ["90"]}, {"input": "9\r\n15 28 39 48 55 60 63 64 74\r\n", "output": ["89"]}, {"input": "10\r\n15 28 39 48 55 60 63 64 74 82\r\n", "output": ["90"]}, {"input": "2\r\n1 18\r\n", "output": ["16"]}, {"input": "9\r\n10 20 30 40 50 60 70 80 84\r\n", "output": ["90"]}, {"input": "2\r\n16 50\r\n", "output": ["15"]}, {"input": "6\r\n15 30 45 60 75 84\r\n", "output": ["90"]}, {"input": "8\r\n15 20 30 40 50 60 73 83\r\n", "output": ["90"]}, {"input": "8\r\n10 20 30 40 50 60 70 80\r\n", "output": ["90"]}, {"input": "3\r\n1 20 90\r\n", "output": ["16"]}, {"input": "6\r\n15 30 45 60 74 89\r\n", "output": ["90"]}]
100
100
100
[{'input': '8\r\n15 20 30 40 50 60 73 83\r\n', 'output': ['90']}, {'input': '25\r\n1 2 3 4 5 6 7 8 9 10 11 23 36 50 65 81 82 83 84 85 86 87 88 89 90\r\n', 'output': ['80']}, {'input': '9\r\n15 20 30 40 50 60 70 80 90\r\n', 'output': ['90']}, {'input': '1\r\n1\r\n', 'output': ['16']}, {'input': '12\r\n14 22 27 31 35 44 62 69 74 79 88 89\r\n', 'output': ['59']}]
[{'input': '2\r\n1 18\r\n', 'output': ['16']}, {'input': '8\r\n1 16 30 31 32 33 34 50\r\n', 'output': ['49']}, {'input': '9\r\n16 20 30 40 50 60 70 80 90\r\n', 'output': ['15']}, {'input': '9\r\n15 28 39 48 55 60 63 64 74\r\n', 'output': ['89']}, {'input': '1\r\n16\r\n', 'output': ['15']}]
[{'input': '84\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84\r\n', 'output': ['90']}, {'input': '14\r\n14 22 27 31 35 44 46 61 62 69 74 79 88 89\r\n', 'output': ['90']}, {'input': '1\r\n1\r\n', 'output': ['16']}, {'input': '1\r\n90\r\n', 'output': ['15']}, {'input': '6\r\n13 17 32 47 60 66\r\n', 'output': ['81']}]
[{'input': '3\r\n1 20 90\r\n', 'output': ['16']}, {'input': '72\r\n3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89\r\n', 'output': ['54']}, {'input': '8\r\n5 17 20 35 42 53 67 76\r\n', 'output': ['90']}, {'input': '6\r\n13 17 32 47 60 66\r\n', 'output': ['81']}, {'input': '9\r\n6 20 27 28 40 53 59 70 85\r\n', 'output': ['90']}]
[{'input': '8\r\n10 20 30 40 50 60 70 80\r\n', 'output': ['90']}, {'input': '3\r\n1 20 90\r\n', 'output': ['16']}, {'input': '84\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84\r\n', 'output': ['90']}, {'input': '6\r\n13 17 32 47 60 66\r\n', 'output': ['81']}, {'input': '72\r\n3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89\r\n', 'output': ['54']}]
100
100
100
100
100
100
100
92.31
100
100
100
90
90
100
100
300
100
98.462
96